未验证 提交 bfd23407 编写于 作者: G GuerraMorgan 提交者: GitHub

Add: Unix Socket support (#466)

* Update conf.go

* Update driver.go

* Update session.go

* Update defaults.go

* Update main.go

* Update conf.go

* Update defaults.go
上级 dd50ef1c
......@@ -40,6 +40,16 @@ func main() {
}()
}
// 如果启用了Unix
if conf.UnixConfig.Listen != "" {
go func() {
util.Log().Info("开始监听 %s", conf.UnixConfig.Listen)
if err := api.RunUnix(conf.UnixConfig.Listen); err != nil {
util.Log().Error("无法监听[%s],%s", conf.UnixConfig.Listen, err)
}
}()
}
util.Log().Info("开始监听 %s", conf.SystemConfig.Listen)
if err := api.Run(conf.SystemConfig.Listen); err != nil {
util.Log().Error("无法监听[%s],%s", conf.SystemConfig.Listen, err)
......
......@@ -18,7 +18,7 @@ func Session(secret string) gin.HandlerFunc {
// Redis设置不为空,且非测试模式时使用Redis
if conf.RedisConfig.Server != "" && gin.Mode() != gin.TestMode {
var err error
Store, err = redis.NewStoreWithDB(10, "tcp", conf.RedisConfig.Server, conf.RedisConfig.Password, conf.RedisConfig.DB, []byte(secret))
Store, err = redis.NewStoreWithDB(10, conf.RedisConfig.Network, conf.RedisConfig.Server, conf.RedisConfig.Password, conf.RedisConfig.DB, []byte(secret))
if err != nil {
util.Log().Panic("无法连接到 Redis:%s", err)
}
......
......@@ -15,7 +15,7 @@ func Init() {
if conf.RedisConfig.Server != "" && gin.Mode() != gin.TestMode {
Store = NewRedisStore(
10,
"tcp",
conf.RedisConfig.Network,
conf.RedisConfig.Server,
conf.RedisConfig.Password,
conf.RedisConfig.DB,
......
......@@ -33,6 +33,10 @@ type ssl struct {
Listen string `validate:"required"`
}
type unix struct {
Listen string
}
// slave 作为slave存储端配置
type slave struct {
Secret string `validate:"omitempty,gte=64"`
......@@ -57,6 +61,7 @@ type captcha struct {
// redis 配置
type redis struct {
Network string
Server string
Password string
DB string
......@@ -120,6 +125,7 @@ func Init(path string) {
"Database": DatabaseConfig,
"System": SystemConfig,
"SSL": SSLConfig,
"Unix": UnixConfig,
"Captcha": CaptchaConfig,
"Redis": RedisConfig,
"Thumbnail": ThumbConfig,
......
......@@ -4,6 +4,7 @@ import "github.com/mojocn/base64Captcha"
// RedisConfig Redis服务器配置
var RedisConfig = &redis{
Network: "tcp",
Server: "",
Password: "",
DB: "0",
......@@ -65,3 +66,7 @@ var SSLConfig = &ssl{
CertPath: "",
KeyPath: "",
}
var UnixConfig = &unix{
Listen: "",
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册