Supporting json output (except for errors)

This commit is contained in:
Deluan
2016-03-02 13:04:55 -05:00
parent 7c82af75f5
commit 9d41f5a39f
11 changed files with 114 additions and 99 deletions
+5 -4
View File
@@ -8,6 +8,7 @@ import (
type ControllerInterface interface {
GetString(key string, def ...string) string
CustomAbort(status int, body string)
SendError(errorCode int, message ...interface{})
}
func Validate(controller ControllerInterface) {
@@ -23,7 +24,7 @@ func checkParameters(c ControllerInterface) {
for _, p := range requiredParameters {
if c.GetString(p) == "" {
cancel(c, responses.ERROR_MISSING_PARAMETER)
abortRequest(c, responses.ERROR_MISSING_PARAMETER)
}
}
}
@@ -32,10 +33,10 @@ func authenticate(c ControllerInterface) {
user := c.GetString("u")
pass := c.GetString("p") // TODO Handle hex-encoded password
if user != beego.AppConfig.String("user") || pass != beego.AppConfig.String("password") {
cancel(c, responses.ERROR_AUTHENTICATION_FAIL)
abortRequest(c, responses.ERROR_AUTHENTICATION_FAIL)
}
}
func cancel(c ControllerInterface, code int) {
c.CustomAbort(200, string(responses.NewError(code)))
func abortRequest(c ControllerInterface, code int) {
c.SendError(code)
}