fix: improve code specification (#231)

This commit is contained in:
sh1luo
2021-08-07 22:02:56 +08:00
committed by Yang Luo
parent a271ef0719
commit 8c66ef6860
36 changed files with 209 additions and 164 deletions

View File

@ -24,6 +24,7 @@ import (
var defaultHttpClient *http.Client
var proxyHttpClient *http.Client
// InitHttpClient ...
func InitHttpClient() {
// not use proxy
defaultHttpClient = http.DefaultClient
@ -54,6 +55,7 @@ func InitHttpClient() {
//println("Response status: %s", resp.Status)
}
// ResponseError ...
func (c *ApiController) ResponseError(error string, data ...interface{}) {
resp := Response{Status: "error", Msg: error}
switch len(data) {
@ -67,11 +69,13 @@ func (c *ApiController) ResponseError(error string, data ...interface{}) {
c.ServeJSON()
}
// ResponseErrorWithData ...
func (c *ApiController) ResponseErrorWithData(error string, data interface{}) {
c.Data["json"] = Response{Status: "error", Msg: error, Data: data}
c.ServeJSON()
}
// RequireSignedIn ...
func (c *ApiController) RequireSignedIn() (string, bool) {
userId := c.GetSessionUsername()
if userId == "" {