Skip to content

Commit

Permalink
Update go-chi session
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jan 8, 2021
1 parent 6f25aac commit 04c8a10
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 47 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
code.gitea.io/gitea-vet v0.2.1
code.gitea.io/sdk/gitea v0.13.1
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee
gitea.com/lunny/levelqueue v0.3.0
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFj
code.gitea.io/sdk/gitea v0.13.1 h1:Y7bpH2iO6Q0KhhMJfjP/LZ0AmiYITeRQlCD8b0oYqhk=
code.gitea.io/sdk/gitea v0.13.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27 h1:cdb1OTNXGLwQ55gg+9tIPWufdsnrHWcIq8Qs+j/E8JU=
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee h1:9U6HuKUBt/cGK6T/64dEuz0r7Yp97WAAEJvXHDlY3ws=
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
gitea.com/lunny/levelqueue v0.3.0 h1:MHn1GuSZkxvVEDMyAPqlc7A3cOW+q8RcGhRgH/xtm6I=
gitea.com/lunny/levelqueue v0.3.0/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
gitea.com/lunny/log v0.0.0-20190322053110-01b5df579c4e h1:r1en/D7xJmcY24VkHkjkcJFa+7ZWubVWPBrvsHkmHxk=
Expand Down
42 changes: 1 addition & 41 deletions routers/routes/chi.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,46 +180,6 @@ var (
sessionManager *session.Manager
)

func prepareOptions(options []session.Options) session.Options {
var opt session.Options
if len(options) > 0 {
opt = options[0]
}

if len(opt.Provider) == 0 {
opt.Provider = "memory"
}
if len(opt.ProviderConfig) == 0 {
opt.ProviderConfig = "data/sessions"
}
if len(opt.CookieName) == 0 {
opt.CookieName = "MacaronSession"
}
if len(opt.CookiePath) == 0 {
opt.CookiePath = "/"
}
if opt.Gclifetime == 0 {
opt.Gclifetime = 3600
}
if opt.Maxlifetime == 0 {
opt.Maxlifetime = opt.Gclifetime
}
if !opt.Secure {
opt.Secure = false
}
if opt.IDLength == 0 {
opt.IDLength = 16
}
if len(opt.FlashEncryptionKey) == 0 {
opt.FlashEncryptionKey = ""
}
if len(opt.FlashEncryptionKey) == 0 {
opt.FlashEncryptionKey, _ = session.NewSecret()
}

return opt
}

// NewChi creates a chi Router
func NewChi() chi.Router {
c := chi.NewRouter()
Expand All @@ -240,7 +200,7 @@ func NewChi() chi.Router {
Secure: setting.SessionConfig.Secure,
Domain: setting.SessionConfig.Domain,
}
opt = prepareOptions([]session.Options{opt})
opt = session.PrepareOptions([]session.Options{opt})

var err error
sessionManager, err = session.NewManager(opt.Provider, opt)
Expand Down
1 change: 1 addition & 0 deletions routers/routes/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func Recovery() func(next http.Handler) http.Handler {

lc := middlewares.Locale(w, req)

// TODO: this should be replaced by real session after macaron removed totally
sessionStore, err := sessionManager.Start(w, req)
if err != nil {
// Just invoke the above recover catch
Expand Down
5 changes: 3 additions & 2 deletions vendor/gitea.com/go-chi/session/session.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ code.gitea.io/gitea-vet/checks
# code.gitea.io/sdk/gitea v0.13.1
## explicit
code.gitea.io/sdk/gitea
# gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27
# gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee
## explicit
gitea.com/go-chi/session
gitea.com/go-chi/session/couchbase
Expand Down

0 comments on commit 04c8a10

Please sign in to comment.