Skip to content

Commit e88db94

Browse files
committed
优化代码
1 parent d3cdeb4 commit e88db94

File tree

16 files changed

+87
-71
lines changed

16 files changed

+87
-71
lines changed

config.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"fmt"
66
tconfig "github.com/RichardKnop/machinery/v1/config"
7+
"github.com/WingGao/go-utils/redis"
78
"github.com/go-errors/errors"
89
"github.com/micro/go-micro/registry"
910
"github.com/ungerik/go-dry"
@@ -69,7 +70,7 @@ type MConfig struct {
6970
WpDir string
7071
}
7172
WxConfig WxConfig `yaml:"wechat"`
72-
Redis RedisConf
73+
Redis redis.RedisConf
7374
Task tconfig.Config
7475

7576
Cms struct {
@@ -230,15 +231,7 @@ type WxCorpConf struct {
230231
OauthRedirect string `yaml:"oauth_redirect"`
231232
}
232233

233-
type RedisConf struct {
234-
Addr string //host:port 127.0.0.1:6379
235-
Shards []string //host:port 127.0.0.1:6379
236-
Password string
237-
Database int
238-
UniqueIdKey string
239-
Prefix string
240-
CacheCloudUrl string
241-
}
234+
242235
type GraphQLConf struct {
243236
Path string
244237
}
@@ -320,7 +313,3 @@ func formatEnv(v string) string {
320313
}
321314
return v
322315
}
323-
324-
func IsDebug() bool {
325-
return DefaultConfig.Debug
326-
}

consts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package utils
33
import "os"
44

55
const (
6-
XSESSION_KEY = "xsession"
6+
77
)
88

99
var (

errors.go renamed to core/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package utils
1+
package core
22

33
import (
44
"bytes"

errors_test.go renamed to core/errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package utils
1+
package core
22

33
import (
44
"testing"

json.go renamed to core/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package utils
1+
package core
22

33
import "github.com/json-iterator/go"
44

init.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
package utils
22

3+
import (
4+
ucore "github.com/WingGao/go-utils/core"
5+
"github.com/WingGao/go-utils/session"
6+
"github.com/WingGao/go-utils/whandler"
7+
)
8+
39
func init() {
4-
for _, v := range UtilsErrList {
5-
AddHandlerIgnoreErrors(v.Error())
10+
for _, v := range ucore.UtilsErrList {
11+
whandler.AddHandlerIgnoreErrors(v.Error())
612
}
713
}
14+
15+
var (
16+
// error
17+
NewErrorList = ucore.NewErrorList
18+
NewWError = ucore.NewWError
19+
PanicIfErr = ucore.PanicIfErr
20+
FirstError = ucore.FirstError
21+
//handler
22+
AfterHandler = whandler.AfterHandler
23+
CancelAfterHandler = whandler.CancelAfterHandler
24+
//session
25+
XSESSION_KEY = session.XSESSION_KEY
26+
)

redis/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package redis
2+
3+
type RedisConf struct {
4+
Addr string //host:port 127.0.0.1:6379
5+
Shards []string //host:port 127.0.0.1:6379
6+
Password string
7+
Database int
8+
UniqueIdKey string
9+
Prefix string
10+
CacheCloudUrl string
11+
}

redis/redis.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"encoding/gob"
66
"fmt"
7-
"github.com/WingGao/go-utils"
87
"github.com/emirpasic/gods/lists/arraylist"
98
gredis "github.com/go-redis/redis"
109
"time"
@@ -17,7 +16,7 @@ const (
1716
type RedisClient interface {
1817
gredis.UniversalClient
1918
FullKey(key string) string
20-
GetConfig() utils.RedisConf
19+
GetConfig() RedisConf
2120
ExpireSecond(key string, second int) (bool, error)
2221
SetGlob(key string, ptr interface{}, opt *Option) (error)
2322
GetGlob(key string, out interface{}) (error)
@@ -249,14 +248,14 @@ var MainClient RedisClient
249248
// panic("implement me")
250249
//}
251250

252-
func LoadClient(conf utils.RedisConf) (err error) {
251+
func LoadClient(conf RedisConf) (err error) {
253252
if MainClient == nil {
254253
MainClient, err = NewRedisClient(conf)
255254
}
256255
return
257256
}
258257

259-
func NewRedisClient(conf utils.RedisConf) (c RedisClient, err error) {
258+
func NewRedisClient(conf RedisConf) (c RedisClient, err error) {
260259
uoption := &gredis.UniversalOptions{}
261260
if conf.CacheCloudUrl != "" {
262261
fmt.Println("redis use cachecloud")

redis/redis_universal.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package redis
33
import (
44
"context"
55
"fmt"
6-
"github.com/WingGao/go-utils"
76
"github.com/WingGao/go-utils/wlog"
87
gredis "github.com/go-redis/redis"
98
"strings"
@@ -30,14 +29,14 @@ var (
3029

3130
type RedisUniversalClient struct {
3231
gredis.UniversalClient
33-
Config utils.RedisConf
32+
Config RedisConf
3433
}
3534

3635
func (c *RedisUniversalClient) ExpireSecond(key string, second int) (bool, error) {
3736
return c.Expire(key, time.Duration(second)*time.Second).Result()
3837
}
3938

40-
func (c *RedisUniversalClient) GetConfig() utils.RedisConf {
39+
func (c *RedisUniversalClient) GetConfig() RedisConf {
4140
return c.Config
4241
}
4342

session/session.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package session
22

33
import (
4-
. "github.com/WingGao/go-utils"
54
"github.com/WingGao/go-utils/session/redis"
65
"github.com/kataras/iris"
76
"github.com/kataras/iris/context"
@@ -20,7 +19,9 @@ import (
2019
//pxdb "px/db"
2120
"time"
2221
)
23-
22+
const (
23+
XSESSION_KEY = "xsession"
24+
)
2425
type XSession struct {
2526
ctx context.Context
2627
Iris *sessions.Session `json:"-"`
@@ -52,8 +53,7 @@ var (
5253
_sessionKeyPrefix = "core:sid:"
5354
)
5455

55-
func BuildIrisSession(conf MConfig) {
56-
rconf := conf.Redis
56+
func BuildIrisSession(rconf uredis.RedisConf,cookieExpire int64) {
5757
_rdb = redis.New(uredis.MainClient, service.Config{
5858
Network: service.DefaultRedisNetwork,
5959
Addr: rconf.Addr,
@@ -68,7 +68,7 @@ func BuildIrisSession(conf MConfig) {
6868
_rdb.Close()
6969
})
7070

71-
exp := time.Duration(conf.CookieExpires)
71+
exp := time.Duration(cookieExpire)
7272
if exp > 0 {
7373
exp = exp * time.Second
7474
}

0 commit comments

Comments
 (0)