mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-15 05:47:13 +02:00
Introduced helper methods for parsing/biding request parameters
This commit is contained in:
parent
91c660c746
commit
28bef732cf
8 changed files with 28 additions and 20 deletions
|
|
@ -5,6 +5,8 @@ import (
|
|||
"fmt"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type BaseAPIController struct{ beego.Controller }
|
||||
|
|
@ -13,7 +15,7 @@ func (c *BaseAPIController) NewEmpty() responses.Subsonic {
|
|||
return responses.Subsonic{Status: "ok", Version: beego.AppConfig.String("apiVersion")}
|
||||
}
|
||||
|
||||
func (c *BaseAPIController) GetParameter(param string, msg string) string {
|
||||
func (c *BaseAPIController) RequiredParamString(param string, msg string) string {
|
||||
p := c.Input().Get(param)
|
||||
if p == "" {
|
||||
c.SendError(responses.ERROR_MISSING_PARAMETER, msg)
|
||||
|
|
@ -21,6 +23,18 @@ func (c *BaseAPIController) GetParameter(param string, msg string) string {
|
|||
return p
|
||||
}
|
||||
|
||||
func (c *BaseAPIController) ParamTime(param string) time.Time {
|
||||
var value int64
|
||||
c.Ctx.Input.Bind(&value, param)
|
||||
return utils.ToTime(value)
|
||||
}
|
||||
|
||||
func (c *BaseAPIController) ParamInt(param string) int {
|
||||
var value int
|
||||
c.Ctx.Input.Bind(&value, param)
|
||||
return value
|
||||
}
|
||||
|
||||
func (c *BaseAPIController) SendError(errorCode int, message ...interface{}) {
|
||||
response := responses.Subsonic{Version: beego.AppConfig.String("apiVersion"), Status: "fail"}
|
||||
var msg string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue