replace dep with go modules (#16017)
- guide shamelessly stolen from prometheus/prometheus - updates local interface of oauth exchange - updates local impl of hclogger - bump jaeger client version closes #16088
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
ledis/tmp.db
|
||||
nodb/tmp.db
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
# session [](https://travis-ci.org/go-macaron/session)
|
||||
|
||||
Middleware session provides session management for [Macaron](https://github.com/go-macaron/macaron). It can use many session providers, including memory, file, Redis, Memcache, PostgreSQL, MySQL, Couchbase, Ledis and Nodb.
|
||||
|
||||
### Installation
|
||||
|
||||
The minimum requirement of Go is 1.6 (*1.7 if using Redis, 1.8 if using MySQL*).
|
||||
|
||||
go get github.com/go-macaron/session
|
||||
|
||||
## Getting Help
|
||||
|
||||
- [API Reference](https://gowalker.org/github.com/go-macaron/session)
|
||||
- [Documentation](https://go-macaron.com/docs/middlewares/session)
|
||||
|
||||
## Credits
|
||||
|
||||
This package is a modified version of [beego/session](https://github.com/astaxie/beego/tree/master/session).
|
||||
|
||||
## License
|
||||
|
||||
This project is under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for the full license text.
|
||||
+5
@@ -81,6 +81,11 @@ func (s *FileStore) Release() error {
|
||||
s.p.lock.Lock()
|
||||
defer s.p.lock.Unlock()
|
||||
|
||||
// Skip encoding if the data is empty
|
||||
if len(s.data) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := EncodeGob(s.data)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// Copyright 2018 The Macaron Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"): you may
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package session
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"gopkg.in/macaron.v1"
|
||||
)
|
||||
|
||||
type Flash struct {
|
||||
ctx *macaron.Context
|
||||
url.Values
|
||||
ErrorMsg, WarningMsg, InfoMsg, SuccessMsg string
|
||||
}
|
||||
|
||||
func (f *Flash) set(name, msg string, current ...bool) {
|
||||
isShow := false
|
||||
if (len(current) == 0 && macaron.FlashNow) ||
|
||||
(len(current) > 0 && current[0]) {
|
||||
isShow = true
|
||||
}
|
||||
|
||||
if isShow {
|
||||
f.ctx.Data["Flash"] = f
|
||||
} else {
|
||||
f.Set(name, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Flash) Error(msg string, current ...bool) {
|
||||
f.ErrorMsg = msg
|
||||
f.set("error", msg, current...)
|
||||
}
|
||||
|
||||
func (f *Flash) Warning(msg string, current ...bool) {
|
||||
f.WarningMsg = msg
|
||||
f.set("warning", msg, current...)
|
||||
}
|
||||
|
||||
func (f *Flash) Info(msg string, current ...bool) {
|
||||
f.InfoMsg = msg
|
||||
f.set("info", msg, current...)
|
||||
}
|
||||
|
||||
func (f *Flash) Success(msg string, current ...bool) {
|
||||
f.SuccessMsg = msg
|
||||
f.set("success", msg, current...)
|
||||
}
|
||||
+5
@@ -85,6 +85,11 @@ func (s *MemcacheStore) ID() string {
|
||||
|
||||
// Release releases resource and save data to provider.
|
||||
func (s *MemcacheStore) Release() error {
|
||||
// Skip encoding if the data is empty
|
||||
if len(s.data) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := session.EncodeGob(s.data)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
ignore
|
||||
+5
@@ -78,6 +78,11 @@ func (s *PostgresStore) ID() string {
|
||||
// save postgres session values to database.
|
||||
// must call this method to save values to database.
|
||||
func (s *PostgresStore) Release() error {
|
||||
// Skip encoding if the data is empty
|
||||
if len(s.data) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := session.EncodeGob(s.data)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
ignore
|
||||
+6
-1
@@ -81,6 +81,11 @@ func (s *RedisStore) ID() string {
|
||||
|
||||
// Release releases resource and save data to provider.
|
||||
func (s *RedisStore) Release() error {
|
||||
// Skip encoding if the data is empty
|
||||
if len(s.data) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
data, err := session.EncodeGob(s.data)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -153,7 +158,7 @@ func (p *RedisProvider) Init(maxlifetime int64, configs string) (err error) {
|
||||
func (p *RedisProvider) Read(sid string) (session.RawStore, error) {
|
||||
psid := p.prefix + sid
|
||||
if !p.Exist(sid) {
|
||||
if err := p.c.Set(psid, "").Err(); err != nil {
|
||||
if err := p.c.SetEx(psid, p.duration, "").Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
ignore
|
||||
+14
-52
@@ -27,7 +27,7 @@ import (
|
||||
"gopkg.in/macaron.v1"
|
||||
)
|
||||
|
||||
const _VERSION = "0.5.0"
|
||||
const _VERSION = "0.6.0"
|
||||
|
||||
func Version() string {
|
||||
return _VERSION
|
||||
@@ -95,6 +95,8 @@ type Options struct {
|
||||
IDLength int
|
||||
// Configuration section name. Default is "session".
|
||||
Section string
|
||||
// Ignore release for websocket. Default is false.
|
||||
IgnoreReleaseForWebSocket bool
|
||||
}
|
||||
|
||||
func prepareOptions(options []Options) Options {
|
||||
@@ -137,6 +139,9 @@ func prepareOptions(options []Options) Options {
|
||||
if opt.IDLength == 0 {
|
||||
opt.IDLength = sec.Key("ID_LENGTH").MustInt(16)
|
||||
}
|
||||
if !opt.IgnoreReleaseForWebSocket {
|
||||
opt.IgnoreReleaseForWebSocket = sec.Key("IGNORE_RELEASE_FOR_WEBSOCKET").MustBool()
|
||||
}
|
||||
|
||||
return opt
|
||||
}
|
||||
@@ -186,6 +191,10 @@ func Sessioner(options ...Options) macaron.Handler {
|
||||
|
||||
ctx.Next()
|
||||
|
||||
if manager.opt.IgnoreReleaseForWebSocket && ctx.Req.Header.Get("Upgrade") == "websocket" {
|
||||
return
|
||||
}
|
||||
|
||||
if err = sess.Release(); err != nil {
|
||||
panic("session(release): " + err.Error())
|
||||
}
|
||||
@@ -346,7 +355,7 @@ func (m *Manager) RegenerateId(ctx *macaron.Context) (sess RawStore, err error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ck := &http.Cookie{
|
||||
cookie := &http.Cookie{
|
||||
Name: m.opt.CookieName,
|
||||
Value: sid,
|
||||
Path: m.opt.CookiePath,
|
||||
@@ -355,10 +364,10 @@ func (m *Manager) RegenerateId(ctx *macaron.Context) (sess RawStore, err error)
|
||||
Domain: m.opt.Domain,
|
||||
}
|
||||
if m.opt.CookieLifeTime >= 0 {
|
||||
ck.MaxAge = m.opt.CookieLifeTime
|
||||
cookie.MaxAge = m.opt.CookieLifeTime
|
||||
}
|
||||
http.SetCookie(ctx.Resp, ck)
|
||||
ctx.Req.AddCookie(ck)
|
||||
http.SetCookie(ctx.Resp, cookie)
|
||||
ctx.Req.AddCookie(cookie)
|
||||
return sess, nil
|
||||
}
|
||||
|
||||
@@ -382,50 +391,3 @@ func (m *Manager) startGC() {
|
||||
func (m *Manager) SetSecure(secure bool) {
|
||||
m.opt.Secure = secure
|
||||
}
|
||||
|
||||
// ___________.____ _____ _________ ___ ___
|
||||
// \_ _____/| | / _ \ / _____// | \
|
||||
// | __) | | / /_\ \ \_____ \/ ~ \
|
||||
// | \ | |___/ | \/ \ Y /
|
||||
// \___ / |_______ \____|__ /_______ /\___|_ /
|
||||
// \/ \/ \/ \/ \/
|
||||
|
||||
type Flash struct {
|
||||
ctx *macaron.Context
|
||||
url.Values
|
||||
ErrorMsg, WarningMsg, InfoMsg, SuccessMsg string
|
||||
}
|
||||
|
||||
func (f *Flash) set(name, msg string, current ...bool) {
|
||||
isShow := false
|
||||
if (len(current) == 0 && macaron.FlashNow) ||
|
||||
(len(current) > 0 && current[0]) {
|
||||
isShow = true
|
||||
}
|
||||
|
||||
if isShow {
|
||||
f.ctx.Data["Flash"] = f
|
||||
} else {
|
||||
f.Set(name, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Flash) Error(msg string, current ...bool) {
|
||||
f.ErrorMsg = msg
|
||||
f.set("error", msg, current...)
|
||||
}
|
||||
|
||||
func (f *Flash) Warning(msg string, current ...bool) {
|
||||
f.WarningMsg = msg
|
||||
f.set("warning", msg, current...)
|
||||
}
|
||||
|
||||
func (f *Flash) Info(msg string, current ...bool) {
|
||||
f.InfoMsg = msg
|
||||
f.set("info", msg, current...)
|
||||
}
|
||||
|
||||
func (f *Flash) Success(msg string, current ...bool) {
|
||||
f.SuccessMsg = msg
|
||||
f.set("success", msg, current...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user