Skip to content

Commit

Permalink
update array check
Browse files Browse the repository at this point in the history
  • Loading branch information
snowlyg committed Jan 16, 2023
1 parent 392934c commit 90fcdd1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/mattn/go-colorable v0.1.12
github.com/robfig/cron/v3 v3.0.1
github.com/snowlyg/helper v0.0.7
github.com/snowlyg/helper v0.1.33
github.com/spf13/viper v1.12.0
github.com/unrolled/secure v1.0.9
go.mongodb.org/mongo-driver v1.10.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/snowlyg/helper v0.0.7 h1:aHpE0BrWUGn4Hu5mSuvmVHDY+I00Q5/pXIHEnKxTruc=
github.com/snowlyg/helper v0.0.7/go.mod h1:/uAwFSceu4L27DdY0AvRhM5HMO0vhVoIXdFH3CyezZY=
github.com/snowlyg/helper v0.1.33 h1:iKVcFvT8TAmsrGqFIMGgonmiX2JCbFq5iBkR16gJK44=
github.com/snowlyg/helper v0.1.33/go.mod h1:/uAwFSceu4L27DdY0AvRhM5HMO0vhVoIXdFH3CyezZY=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
5 changes: 4 additions & 1 deletion server/web/web_gin/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/gin-gonic/gin"
"github.com/mattn/go-colorable"
"github.com/snowlyg/helper/arr"
"github.com/snowlyg/helper/dir"
"github.com/snowlyg/helper/str"
"github.com/snowlyg/iris-admin/server/web"
Expand Down Expand Up @@ -102,7 +103,9 @@ func (ws *WebServer) GetEngine() *gin.Engine {
// AddWebStatic
func (ws *WebServer) AddWebStatic(staticAbsPath, webPrefix string, paths ...string) {
webPrefixs := strings.Split(web.CONFIG.System.WebPrefix, ",")
if str.InStrArray(webPrefix, webPrefixs) {
wp := arr.NewCheckArrayType(2)
wp.AddMutil(webPrefixs[0], webPrefixs[1])
if wp.Check(webPrefix) {
return
}

Expand Down
16 changes: 8 additions & 8 deletions server/web/web_gin/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (ws *WebServer) GetRouterGroup(relativePath string) *gin.RouterGroup {
return ws.app.Group(relativePath)
}

// InitRouter
// InitRouter
func (ws *WebServer) InitRouter() error {
ws.app.Use(limit.MaxAllowed(50))
ws.app.Use(gin.Recovery())
Expand All @@ -26,7 +26,7 @@ func (ws *WebServer) InitRouter() error {
}
router := ws.app.Group("/")
{
router.Use(middleware.Cors())
router.Use(middleware.Cors())
// last middleware
router.Use(gin.Recovery())

Expand All @@ -37,9 +37,9 @@ func (ws *WebServer) InitRouter() error {
return nil
}

// GetSources
// - PermRoutes
// - NoPermRoutes
// GetSources
// - PermRoutes
// - NoPermRoutes
func (ws *WebServer) GetSources() ([]map[string]string, []map[string]string) {

methodExcepts := strings.Split(web.CONFIG.Except.Method, ";")
Expand All @@ -62,13 +62,13 @@ func (ws *WebServer) GetSources() ([]map[string]string, []map[string]string) {
"group": bases[0],
"method": r.Method,
}

if !arr.InArray([]string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete}, r.Method) {
httpStatusType := arr.NewCheckArrayType(4)
httpStatusType.AddMutil(http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete)
if !httpStatusType.Check(r.Method) {
noPermRoutes = append(noPermRoutes, route)
continue
}


if len(methodExcepts) > 0 && len(uriExcepts) > 0 && len(methodExcepts) == len(uriExcepts) {
for i := 0; i < len(methodExcepts); i++ {
if strings.EqualFold(r.Method, strings.ToLower(methodExcepts[i])) && strings.EqualFold(path, strings.ToLower(uriExcepts[i])) {
Expand Down
5 changes: 4 additions & 1 deletion server/web/web_iris/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/go-playground/validator/v10"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/recover"
"github.com/snowlyg/helper/arr"
"github.com/snowlyg/helper/str"
"github.com/snowlyg/iris-admin/server/web"
"github.com/snowlyg/iris-admin/server/web/web_iris/middleware"
Expand Down Expand Up @@ -80,7 +81,9 @@ func (ws *WebServer) AddModule(parties ...Party) {
// AddWebStatic
func (ws *WebServer) AddWebStatic(staticAbsPath, webPrefix string, paths ...string) {
webPrefixs := strings.Split(web.CONFIG.System.WebPrefix, ",")
if str.InStrArray(webPrefix, webPrefixs) {
wp := arr.NewCheckArrayType(2)
wp.AddMutil(webPrefixs[0], webPrefixs[1])
if wp.Check(webPrefix) {
return
}

Expand Down
5 changes: 3 additions & 2 deletions server/web/web_iris/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ func (ws *WebServer) GetSources() ([]map[string]string, []map[string]string) {
"name": r.Name,
"act": r.Method,
}

if !arr.InArray([]string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete}, r.Method) {
httpStatusType := arr.NewCheckArrayType(4)
httpStatusType.AddMutil(http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete)
if !httpStatusType.Check(r.Method) {
noPermRoutes = append(noPermRoutes, route)
continue
}
Expand Down

0 comments on commit 90fcdd1

Please sign in to comment.