Skip to content

Golang security project, implementation imitating sa-token, supports login authentication, session query, kick people offline, account banned

License

Notifications You must be signed in to change notification settings

veerdone/gsecurity

Repository files navigation

gsecurity


go version >= 1.18

English | 中文

Golang implementation imitating sa-token

  • Login authentication
  • Kick people offline
  • Account banned
  • Session query
  • Authority certification
go get github.com/veerdone/gsecurity

Document

Login

// Login return a token, then set token to cookie or response header or response body
token := gsecurity.Login(10010)

// or use LoginAndSet,login then set token to the cookie
// the second method parameter needs to be implemented Adaptor
http.HandleFunc("/set/session", func(w http.ResponseWriter, req *http.Request) {
    gsecurity.LoginAndSet(10010, standardadaptor.New(req, w))
})

Account Banned

// disable with userId and disable expire time
gsecurity.Disable(10010, 3600)

// disable with userId, disable level, disable expire time
gsecurity.DisableWithLevel(10010, 1, 3600)

// disable with userId, disable level, disable expire time and service
gsecurity.DisableWithLevelAndService(10010, 1, 3600, "comment")

// has been disabled with userId
disabled := gsecurity.IsDisable(10010)
// or
gsecurity.IsDisableWithLevel(10010, 1)
gsecurity.IsDisableWithLevelAndService(10010, 1, "comment")

// has been disabled with userId, return error
disbleErr := gsecurity.CheckDisable(10010)
// or
gsecurity.CheckDisableWithLevel(10010, 1)
gsecurity.CheckDisableWithLevelAndService(10010, 1, "comment")

Session query

http.HandleFunc("/set/session", func (w http.ResponseWriter, req *http.Request) {
// if not login will return nil
    session := gsecurity.Sessions(standardadaptor.New(req, w))
    if session != nil {
        session.Set("key", "value")
        session.Get("key")
    }
})

Example

About

Golang security project, implementation imitating sa-token, supports login authentication, session query, kick people offline, account banned

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages