gPanel/pkg/api/api_handler.go

24 lines
699 B
Go

// Package api handles all API calls
package api
import (
"net/http"
"strings"
)
// HandleAPI function takes a path and determines if it is an API call, if it is it will
// call the specified API. It returns two booleans, the first being if it is an API call and
// the second is the response of the API call's function.
func HandleAPI(path string, res http.ResponseWriter, req *http.Request) (bool, bool) {
splitUrl := strings.Split(path, "/")
suspectApi := strings.ToLower(splitUrl[len(splitUrl)-1])
switch suspectApi {
case "authentication":
return true, UserAuthentication(res, req)
case "registration":
return true, UserRegistration(res, req)
default:
return false, false
}
}