Skip to content

Commit

Permalink
golint
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Nov 15, 2019
1 parent 81d945a commit 9d835f2
Show file tree
Hide file tree
Showing 52 changed files with 455 additions and 223 deletions.
4 changes: 2 additions & 2 deletions adapter/beego/beego.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (bee *Beego) Content(contextInterface interface{}, c types.GetPanel) {
return
}

user, ok := auth.GetCurUserById(int64(userID.(float64)))
user, ok := auth.GetCurUserByID(int64(userID.(float64)))

if !ok {
ctx.Redirect(http.StatusFound, globalConfig.Url("/login"))
Expand Down Expand Up @@ -140,7 +140,7 @@ func (bee *Beego) Content(contextInterface interface{}, c types.GetPanel) {

buf := new(bytes.Buffer)
err = tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(user,
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.UrlRemovePrefix(ctx.Request.URL.String()))),
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.URLRemovePrefix(ctx.Request.URL.String()))),
panel, globalConfig, template.GetComponentAssetListsHTML()))
if err != nil {
logger.Error("Beego Content", err)
Expand Down
4 changes: 2 additions & 2 deletions adapter/buffalo/buffalo.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (bu *Buffalo) Content(contextInterface interface{}, c types.GetPanel) {
return
}

user, ok := auth.GetCurUserById(int64(userID.(float64)))
user, ok := auth.GetCurUserByID(int64(userID.(float64)))

if !ok {
_ = ctx.Redirect(http.StatusFound, globalConfig.Url("/login"))
Expand Down Expand Up @@ -185,7 +185,7 @@ func (bu *Buffalo) Content(contextInterface interface{}, c types.GetPanel) {

buf := new(bytes.Buffer)
err = tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(user,
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.UrlRemovePrefix(ctx.Request().URL.String()))),
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.URLRemovePrefix(ctx.Request().URL.String()))),
panel, globalConfig, template.GetComponentAssetListsHTML()))
if err != nil {
logger.Error("Buffalo Content", err)
Expand Down
4 changes: 2 additions & 2 deletions adapter/chi/chi.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (bu *Chi) Content(contextInterface interface{}, c types.GetPanel) {
return
}

user, ok := auth.GetCurUserById(int64(userID.(float64)))
user, ok := auth.GetCurUserByID(int64(userID.(float64)))

if !ok {
http.Redirect(ctx.Response, ctx.Request, config.Url("/login"), http.StatusFound)
Expand Down Expand Up @@ -191,7 +191,7 @@ func (bu *Chi) Content(contextInterface interface{}, c types.GetPanel) {

buf := new(bytes.Buffer)
err = tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(user,
*(menu.GetGlobalMenu(user).SetActiveClass(config.UrlRemovePrefix(ctx.Request.URL.String()))),
*(menu.GetGlobalMenu(user).SetActiveClass(config.URLRemovePrefix(ctx.Request.URL.String()))),
panel, config, template.GetComponentAssetListsHTML()))
if err != nil {
logger.Error("Chi Content", err)
Expand Down
4 changes: 2 additions & 2 deletions adapter/echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (e *Echo) Content(contextInterface interface{}, c types.GetPanel) {
return
}

user, ok := auth.GetCurUserById(int64(userID.(float64)))
user, ok := auth.GetCurUserByID(int64(userID.(float64)))

if !ok {
_ = ctx.Redirect(http.StatusFound, globalConfig.Url("/login"))
Expand Down Expand Up @@ -138,7 +138,7 @@ func (e *Echo) Content(contextInterface interface{}, c types.GetPanel) {

buf := new(bytes.Buffer)
err = tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(user,
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.UrlRemovePrefix(ctx.Request().URL.String()))),
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.URLRemovePrefix(ctx.Request().URL.String()))),
panel, globalConfig, template.GetComponentAssetListsHTML()))
if err != nil {
logger.Error("Echo Content", err)
Expand Down
4 changes: 2 additions & 2 deletions adapter/fasthttp/fasthttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (fast *Fasthttp) Content(contextInterface interface{}, c types.GetPanel) {
return
}

user, ok := auth.GetCurUserById(int64(userID.(float64)))
user, ok := auth.GetCurUserByID(int64(userID.(float64)))

if !ok {
ctx.Redirect(globalConfig.Url("/login"), http.StatusFound)
Expand Down Expand Up @@ -206,7 +206,7 @@ func (fast *Fasthttp) Content(contextInterface interface{}, c types.GetPanel) {

buf := new(bytes.Buffer)
err = tmpl.ExecuteTemplate(buf, tmplName,
types.NewPage(user, *(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.UrlRemovePrefix(ctx.Request.URI().String()))),
types.NewPage(user, *(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.URLRemovePrefix(ctx.Request.URI().String()))),
panel, globalConfig, template.GetComponentAssetListsHTML()))
if err != nil {
logger.Error("Fasthttp Content", err)
Expand Down
4 changes: 2 additions & 2 deletions adapter/gin/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (gins *Gin) Content(contextInterface interface{}, c types.GetPanel) {
return
}

user, ok := auth.GetCurUserById(int64(userID.(float64)))
user, ok := auth.GetCurUserByID(int64(userID.(float64)))

if !ok {
ctx.Redirect(http.StatusFound, globalConfig.Url("/login"))
Expand Down Expand Up @@ -142,7 +142,7 @@ func (gins *Gin) Content(contextInterface interface{}, c types.GetPanel) {

buf := new(bytes.Buffer)
err = tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(user,
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.UrlRemovePrefix(ctx.Request.URL.String()))),
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.URLRemovePrefix(ctx.Request.URL.String()))),
panel, globalConfig, template.GetComponentAssetListsHTML()))
if err != nil {
logger.Error("Gin Content", err)
Expand Down
4 changes: 2 additions & 2 deletions adapter/gorilla/gorilla.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (g *Gorilla) Content(contextInterface interface{}, c types.GetPanel) {
return
}

user, ok := auth.GetCurUserById(int64(userID.(float64)))
user, ok := auth.GetCurUserByID(int64(userID.(float64)))

if !ok {
http.Redirect(ctx.Response, ctx.Request, globalConfig.Url("/login"), http.StatusFound)
Expand Down Expand Up @@ -165,7 +165,7 @@ func (g *Gorilla) Content(contextInterface interface{}, c types.GetPanel) {

buf := new(bytes.Buffer)
err = tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(user,
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.UrlRemovePrefix(ctx.Request.URL.String()))),
*(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.URLRemovePrefix(ctx.Request.URL.String()))),
panel, globalConfig, template.GetComponentAssetListsHTML()))
if err != nil {
logger.Error("Gorilla Content", err)
Expand Down
4 changes: 2 additions & 2 deletions adapter/iris/iris.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (is *Iris) Content(contextInterface interface{}, c types.GetPanel) {
return
}

user, ok := auth.GetCurUserById(int64(userID.(float64)))
user, ok := auth.GetCurUserByID(int64(userID.(float64)))

if !ok {
ctx.Redirect(globalConfig.Url("/login"), http.StatusFound)
Expand Down Expand Up @@ -149,7 +149,7 @@ func (is *Iris) Content(contextInterface interface{}, c types.GetPanel) {

buf := new(bytes.Buffer)
err = tmpl.ExecuteTemplate(buf, tmplName,
types.NewPage(user, *(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.UrlRemovePrefix(ctx.Request().URL.String()))),
types.NewPage(user, *(menu.GetGlobalMenu(user).SetActiveClass(globalConfig.URLRemovePrefix(ctx.Request().URL.String()))),
panel, globalConfig, template.GetComponentAssetListsHTML()))
if err != nil {
logger.Error("Iris Content", err)
Expand Down
2 changes: 1 addition & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Context struct {
handlers Handlers
}

// Path is used in the matching of request and response. URL stores the
// Path is used in the matching of request and response. Url stores the
// raw register url. RegUrl contains the wildcard which on behalf of
// the route params.
type Path struct {
Expand Down
4 changes: 2 additions & 2 deletions examples/datamodel/mysql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func GetAllTypesTable() table.Table {
info.AddField("Type_40", "type_40", db.Multipoint)
info.AddField("Type_42", "type_42", db.Geometrycollection)
info.AddField("Type_50", "type_50", db.Double)
info.AddField("Type_51", "type_51", db.Json)
info.AddField("Type_51", "type_51", db.JSON)

info.SetTable("all_types").SetTitle("All_types").SetDescription("All_types")

Expand Down Expand Up @@ -107,7 +107,7 @@ func GetAllTypesTable() table.Table {
formList.AddField("Type_40", "type_40", db.Multipoint, form.Text)
formList.AddField("Type_42", "type_42", db.Geometrycollection, form.Text)
formList.AddField("Type_50", "type_50", db.Double, form.Text)
formList.AddField("Type_51", "type_51", db.Json, form.Text)
formList.AddField("Type_51", "type_51", db.JSON, form.Text)

formList.SetTable("all_types").SetTitle("All_types").SetDescription("All_types")

Expand Down
7 changes: 5 additions & 2 deletions modules/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Check(password string, username string) (user models.UserModel, ok bool) {

func comparePassword(comPwd, pwdHash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(pwdHash), []byte(comPwd))
return err != nil
return err == nil
}

// EncodePassword encode the password.
Expand All @@ -52,7 +52,7 @@ func EncodePassword(pwd []byte) string {

// SetCookie set the cookie.
func SetCookie(ctx *context.Context, user models.UserModel) bool {
InitSession(ctx).Set("user_id", user.Id)
InitSession(ctx).Add("user_id", user.Id)
return true
}

Expand All @@ -73,6 +73,7 @@ var (
CsrfTokenLock sync.Mutex
)

// AddToken add the token to the CSRFToken.
func (csrf *CSRFToken) AddToken() string {
CsrfTokenLock.Lock()
defer CsrfTokenLock.Unlock()
Expand All @@ -81,6 +82,8 @@ func (csrf *CSRFToken) AddToken() string {
return tokenStr
}

// CheckToken check the given token with tokens in the CSRFToken, if exist
// return true.
func (csrf *CSRFToken) CheckToken(toCheckToken string) bool {
for i := 0; i < len(*csrf); i++ {
if (*csrf)[i] == toCheckToken {
Expand Down
9 changes: 6 additions & 3 deletions modules/auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ func SetPrefix(prefix string) *Invoker {
return i
}

// SetAuthFailCallback set the authFailCallback of Invoker.
func (invoker *Invoker) SetAuthFailCallback(callback MiddlewareCallback) *Invoker {
invoker.authFailCallback = callback
return invoker
}

// SetPermissionDenyCallback set the permissionDenyCallback of Invoker.
func (invoker *Invoker) SetPermissionDenyCallback(callback MiddlewareCallback) *Invoker {
invoker.permissionDenyCallback = callback
return invoker
Expand All @@ -74,6 +76,7 @@ func (invoker *Invoker) SetPermissionDenyCallback(callback MiddlewareCallback) *
// MiddlewareCallback is type of callback function.
type MiddlewareCallback func(ctx *context.Context)

// Middleware get the auth middleware from Invoker.
func (invoker *Invoker) Middleware() context.Handler {
return func(ctx *context.Context) {
user, authOk, permissionOk := Filter(ctx)
Expand Down Expand Up @@ -112,7 +115,7 @@ func Filter(ctx *context.Context) (models.UserModel, bool, bool) {
return user, false, false
}

user, ok = GetCurUserById(int64(id))
user, ok = GetCurUserByID(int64(id))

if !ok {
return user, false, false
Expand All @@ -121,8 +124,8 @@ func Filter(ctx *context.Context) (models.UserModel, bool, bool) {
return user, true, CheckPermissions(user, ctx.Path(), ctx.Method())
}

// GetCurUserById return the user model of given user id.
func GetCurUserById(id int64) (user models.UserModel, ok bool) {
// GetCurUserByID return the user model of given user id.
func GetCurUserByID(id int64) (user models.UserModel, ok bool) {

user = models.User().Find(id)

Expand Down
14 changes: 7 additions & 7 deletions modules/auth/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (ses *Session) Get(key string) interface{} {
return ses.Values[key]
}

// Get set the session value of key.
func (ses *Session) Set(key string, value interface{}) {
// Add add the session value of key.
func (ses *Session) Add(key string, value interface{}) {
ses.Values[key] = value
ses.Driver.Update(ses.Sid, ses.Values)
cookie := http.Cookie{
Expand Down Expand Up @@ -121,11 +121,11 @@ func (driver *DBDriver) Load(sid string) map[string]interface{} {

if sesModel == nil {
return map[string]interface{}{}
} else {
var values map[string]interface{}
_ = json.Unmarshal([]byte(sesModel["values"].(string)), &values)
return values
}

var values map[string]interface{}
_ = json.Unmarshal([]byte(sesModel["values"].(string)), &values)
return values
}

func deleteOverdueSession() {
Expand All @@ -151,7 +151,7 @@ func deleteOverdueSession() {
cmd = `delete from goadmin_session where strftime('%s', created_at) < strftime('%s', 'now') - ` + duration
}

logger.LogSql(cmd, nil)
logger.LogSQL(cmd, nil)

_, _ = db.Query(cmd)
}
Expand Down
Loading

0 comments on commit 9d835f2

Please sign in to comment.