gPanel/pkg/api/api_handler.go
2017-11-03 17:18:26 -05:00

28 lines
810 B
Go

// Package api handles all API calls
package api
import (
"net/http"
"strings"
"github.com/Ennovar/gPanel/pkg/api/user"
)
// 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 "user_auth":
return true, user.UserAuthentication(res, req)
case "user_register":
return true, user.UserRegistration(res, req)
case "user_logout":
return true, user.UserLogout(res, req)
default:
return false, false
}
}