-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
74 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
package session | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
|
||
"4u-go/config/config" | ||
"4u-go/config/redis" | ||
"github.com/gin-contrib/sessions" | ||
sessionRedis "github.com/gin-contrib/sessions/redis" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// Init 初始化会话管理,设置会话存储驱动 | ||
// Init 使用 Redis 初始化会话管理 | ||
func Init(r *gin.Engine) error { | ||
config := getConfig() | ||
switch config.Driver { | ||
case Redis: | ||
return setRedis(r, config.Name) | ||
case Memory: | ||
setMemory(r, config.Name) | ||
default: | ||
return errors.New("session config error") | ||
} | ||
info := redis.InfoConfig | ||
name := config.Config.GetString("session.name") | ||
secret := config.Config.GetString("session.secret") | ||
|
||
store, err := sessionRedis.NewStoreWithDB(10, "tcp", | ||
info.Host+":"+info.Port, info.Password, | ||
strconv.Itoa(info.DB), | ||
[]byte(secret), | ||
) | ||
if err != nil { | ||
return fmt.Errorf("session init failed: %w", err) | ||
} | ||
r.Use(sessions.Sessions(name, store)) | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.