Supporting json output (except for errors)
This commit is contained in:
+5
-4
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user