Browse Source

clean useless code

haiswork 5 years ago
parent
commit
a074b9487b

+ 1
- 1
.gitignore View File

@@ -1,5 +1,5 @@
1 1
 # debug
2
-/skeleton
2
+/monitor_status
3 3
 /debug
4 4
 /.env
5 5
 # editor workspace

+ 1
- 1
cmd/http/handler/index.go View File

@@ -2,7 +2,7 @@ package handler
2 2
 
3 3
 import (
4 4
 	"git.links123.net/links123.com/pkg/request"
5
-	"git.links123.net/links123.com/skeleton/service/api"
5
+	"git.links123.net/links123.com/monitor_status/service/api"
6 6
 	"github.com/Unknwon/i18n"
7 7
 	"github.com/gin-gonic/gin"
8 8
 )

+ 1
- 9
cmd/http/http.go View File

@@ -6,9 +6,7 @@ import (
6 6
 	"strings"
7 7
 	"syscall"
8 8
 
9
-	"git.links123.net/links123.com/skeleton/cmd/http/router"
10
-	"git.links123.net/links123.com/skeleton/service/store/cache"
11
-	"git.links123.net/links123.com/skeleton/service/store/mysql"
9
+	"git.links123.net/links123.com/monitor_status/cmd/http/router"
12 10
 	"github.com/braintree/manners"
13 11
 	"github.com/sirupsen/logrus"
14 12
 	"github.com/spf13/cobra"
@@ -37,10 +35,6 @@ func RunCommand() *cobra.Command {
37 35
 
38 36
 // Start use for cobra or testing
39 37
 func Start(host, port string) {
40
-	// init db
41
-	mysql.Init()
42
-	// init cache
43
-	cache.Init()
44 38
 	// build router
45 39
 	r := router.BuildRouter()
46 40
 	// start server
@@ -55,6 +49,4 @@ func Stop() {
55 49
 	if manners.Close() {
56 50
 		logrus.Info("http server stopped")
57 51
 	}
58
-	cache.Close()
59
-	mysql.Close()
60 52
 }

+ 0
- 18
cmd/http/middleware/auth.go View File

@@ -1,18 +0,0 @@
1
-package middleware
2
-
3
-import (
4
-	"git.links123.net/links123.com/pkg/middleware/auth"
5
-	"git.links123.net/links123.com/skeleton/config"
6
-	"git.links123.net/links123.com/skeleton/service/store/cache"
7
-	"github.com/gin-gonic/gin"
8
-)
9
-
10
-// Auth 必须认证
11
-func Auth() gin.HandlerFunc {
12
-	return auth.Auth(config.C.App.Secret, cache.AuthSessionStore())
13
-}
14
-
15
-// OptionalAuth 可选认证 如果传了token就会解析其用户
16
-func OptionalAuth() gin.HandlerFunc {
17
-	return auth.OptionalAuth(config.C.App.Secret)
18
-}

+ 3
- 3
cmd/http/router/router.go View File

@@ -2,9 +2,9 @@ package router
2 2
 
3 3
 import (
4 4
 	"git.links123.net/links123.com/pkg/middleware/cors"
5
-	"git.links123.net/links123.com/skeleton/cmd/http/handler"
6
-	"git.links123.net/links123.com/skeleton/config"
7
-	_ "git.links123.net/links123.com/skeleton/docs" // for swagger
5
+	"git.links123.net/links123.com/monitor_status/cmd/http/handler"
6
+	"git.links123.net/links123.com/monitor_status/config"
7
+	_ "git.links123.net/links123.com/monitor_status/docs" // for swagger
8 8
 	"github.com/gin-gonic/gin"
9 9
 	"github.com/swaggo/gin-swagger"
10 10
 	"github.com/swaggo/gin-swagger/swaggerFiles"

+ 1
- 14
cmd/http/router/v1.go View File

@@ -1,8 +1,7 @@
1 1
 package router
2 2
 
3 3
 import (
4
-	"git.links123.net/links123.com/skeleton/cmd/http/handler"
5
-	"git.links123.net/links123.com/skeleton/cmd/http/middleware"
4
+	"git.links123.net/links123.com/monitor_status/cmd/http/handler"
6 5
 )
7 6
 
8 7
 func registerV1Router() {
@@ -11,16 +10,4 @@ func registerV1Router() {
11 10
 	{
12 11
 		v1NoAuth.GET("/hello", handler.Healthy)
13 12
 	}
14
-
15
-	// All user can access, you can get user id in handle
16
-	v1OptionAuth := r.Group("/v1").Use(middleware.OptionalAuth())
17
-	{
18
-		v1OptionAuth.POST("/hello/option/auth", handler.Healthy)
19
-	}
20
-
21
-	// Only the login user can access
22
-	v1Auth := r.Group("/v1").Use(middleware.Auth())
23
-	{
24
-		v1Auth.POST("/hello/auth", handler.Healthy)
25
-	}
26 13
 }

+ 0
- 10
cmd/tcp/handler/index.go View File

@@ -1,10 +0,0 @@
1
-package handler
2
-
3
-import (
4
-	"github.com/wpajqz/linker"
5
-)
6
-
7
-// Healthy 健康检查
8
-func Healthy(ctx linker.Context) {
9
-	ctx.Success(map[string]string{"keepalive": "true"})
10
-}

+ 0
- 43
cmd/tcp/middleware/auth.go View File

@@ -1,43 +0,0 @@
1
-package middleware
2
-
3
-import (
4
-	"fmt"
5
-	"net/http"
6
-
7
-	"git.links123.net/links123.com/skeleton/config"
8
-	"github.com/dgrijalva/jwt-go"
9
-	"github.com/wpajqz/linker"
10
-)
11
-
12
-// headers
13
-const (
14
-	CtxRequestHeaderUserId        = "user_id"
15
-	CtxRequestHeaderAuthorization = "Authorization"
16
-)
17
-
18
-// Auth empty struct for middleware interface
19
-type Auth struct{}
20
-
21
-// Handle middleware process
22
-func (a *Auth) Handle(ctx linker.Context) linker.Context {
23
-	tk := ctx.GetRequestProperty(CtxRequestHeaderAuthorization)
24
-	if len(tk) < 8 {
25
-		ctx.Error(http.StatusUnauthorized, "Auth failed")
26
-	}
27
-
28
-	token, err := jwt.Parse(tk[7:], func(token *jwt.Token) (interface{}, error) {
29
-		if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
30
-			return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
31
-		}
32
-
33
-		return []byte(config.C.App.Secret), nil
34
-	})
35
-
36
-	if err != nil || !token.Valid {
37
-		ctx.Error(http.StatusUnauthorized, "Auth failed")
38
-	}
39
-
40
-	ctx.Set(CtxRequestHeaderUserId, int(token.Claims.(jwt.MapClaims)[CtxRequestHeaderUserId].(float64)))
41
-
42
-	return ctx
43
-}

+ 0
- 18
cmd/tcp/router/router.go View File

@@ -1,18 +0,0 @@
1
-package router
2
-
3
-import (
4
-	"git.links123.net/links123.com/skeleton/cmd/tcp/middleware"
5
-	"github.com/wpajqz/linker"
6
-)
7
-
8
-// golbal tcp router
9
-var r *linker.Router
10
-
11
-// BuildRouter build linker roter
12
-func BuildRouter() *linker.Router {
13
-	r = linker.NewRouter()
14
-	r.Use(&middleware.Auth{})
15
-	registerV1Router()
16
-
17
-	return r
18
-}

+ 0
- 17
cmd/tcp/router/v1.go View File

@@ -1,17 +0,0 @@
1
-package router
2
-
3
-import (
4
-	"git.links123.net/links123.com/skeleton/cmd/tcp/handler"
5
-	"github.com/wpajqz/linker"
6
-)
7
-
8
-func registerV1Router() {
9
-	r.NSRouter("/v1",
10
-		r.NSRoute(
11
-			"/",
12
-			linker.HandlerFunc(func(ctx linker.Context) {
13
-				handler.Healthy(ctx)
14
-			}),
15
-		),
16
-	)
17
-}

+ 0
- 74
cmd/tcp/tcp.go View File

@@ -1,74 +0,0 @@
1
-package tcp
2
-
3
-import (
4
-	"os"
5
-	"os/signal"
6
-	"strings"
7
-	"syscall"
8
-	"time"
9
-
10
-	"git.links123.net/links123.com/skeleton/cmd/tcp/router"
11
-	"git.links123.net/links123.com/skeleton/service/store/cache"
12
-	"git.links123.net/links123.com/skeleton/service/store/mysql"
13
-	"github.com/sirupsen/logrus"
14
-	"github.com/spf13/cobra"
15
-	"github.com/wpajqz/linker"
16
-	"github.com/wpajqz/linker/plugins"
17
-)
18
-
19
-// RunCommand cobra subcommand tcp
20
-func RunCommand() *cobra.Command {
21
-	var host, port string
22
-	cmd := &cobra.Command{
23
-		Use:   "tcp",
24
-		Short: "Run the tcp service",
25
-		Run: func(cmd *cobra.Command, args []string) {
26
-			go Start(host, port)
27
-			// 阻塞退出 捕获信号
28
-			signalChan := make(chan os.Signal)
29
-			signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
30
-			logrus.Infof("caught signal %+v, begin garbage collection", <-signalChan)
31
-			Stop()
32
-		},
33
-	}
34
-
35
-	cmd.PersistentFlags().StringVarP(&host, "host", "o", "0.0.0.0", "server hostname")
36
-	cmd.PersistentFlags().StringVarP(&port, "port", "p", "8081", "server port")
37
-
38
-	return cmd
39
-}
40
-
41
-// Start use for cobra or testing
42
-func Start(host, port string) {
43
-	// init db
44
-	mysql.Init()
45
-	// init cache
46
-	cache.Init()
47
-	// init server
48
-	server := linker.NewServer(linker.Config{
49
-		Timeout: 30 * time.Second,
50
-		PluginForPacketSender: []linker.PacketPlugin{
51
-			&plugins.Encryption{},
52
-			&plugins.Debug{Sender: true},
53
-		},
54
-		PluginForPacketReceiver: []linker.PacketPlugin{
55
-			&plugins.Decryption{},
56
-			&plugins.Debug{Sender: false},
57
-		},
58
-	})
59
-	// build router
60
-	r := router.BuildRouter()
61
-	server.BindRouter(r)
62
-	// start server
63
-	err := server.RunTCP("tcp", strings.Join([]string{host, port}, ":"))
64
-	if err != nil {
65
-		panic(err)
66
-	}
67
-}
68
-
69
-// Stop stop the http service graceful
70
-func Stop() {
71
-	// tcp server graceful shutdown missing
72
-	cache.Close()
73
-	mysql.Close()
74
-}

+ 0
- 107
cmd/tcp/tcp_test.go View File

@@ -1,107 +0,0 @@
1
-package tcp
2
-
3
-import (
4
-	"fmt"
5
-	"os"
6
-	"testing"
7
-	"time"
8
-
9
-	"git.links123.net/links123.com/skeleton/config"
10
-	jwt "github.com/dgrijalva/jwt-go"
11
-	"github.com/stretchr/testify/assert"
12
-	"github.com/wpajqz/go-sdk/export"
13
-)
14
-
15
-var client *export.Client
16
-
17
-type (
18
-	ReadyStateCallback    struct{}
19
-	RequestStatusCallback struct {
20
-		Start   func()
21
-		End     func()
22
-		Success func(header, body []byte)
23
-		Error   func(code int, message string)
24
-	}
25
-)
26
-
27
-func (readyStateCallback *ReadyStateCallback) OnOpen() {
28
-	fmt.Println("Open connection")
29
-}
30
-
31
-func (readyStateCallback *ReadyStateCallback) OnClose() {
32
-	fmt.Println("Close connection")
33
-}
34
-
35
-func (readyStateCallback *ReadyStateCallback) OnError(err string) {
36
-	fmt.Println("Error:", err)
37
-}
38
-
39
-func (r RequestStatusCallback) OnStart() {
40
-	if r.Start != nil {
41
-		r.Start()
42
-	}
43
-}
44
-
45
-func (r RequestStatusCallback) OnSuccess(header, body []byte) {
46
-	if r.Success != nil {
47
-		r.Success(header, body)
48
-	}
49
-}
50
-
51
-func (r RequestStatusCallback) OnError(code int, message string) {
52
-	if r.Error != nil {
53
-		r.Error(code, message)
54
-	}
55
-}
56
-
57
-func (r RequestStatusCallback) OnEnd() {
58
-	if r.End != nil {
59
-		r.End()
60
-	}
61
-}
62
-
63
-func genToken(userID int64) string {
64
-	// Create a new token object, specifying signing method and the claims
65
-	// you would like it to contain.
66
-	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
67
-		"user_id": userID,
68
-		"expired": time.Now().Add(time.Hour).Unix(),
69
-	})
70
-
71
-	// Sign and get the complete encoded token as a string using the secret
72
-	tokenString, err := token.SignedString([]byte(config.C.App.Secret))
73
-	if err != nil {
74
-		panic(err)
75
-	}
76
-	return tokenString
77
-}
78
-
79
-func TestHealthy(t *testing.T) {
80
-	err := client.SyncSend("/v1/", nil, &RequestStatusCallback{
81
-		Success: func(header, body []byte) {
82
-			fmt.Print(header)
83
-			assert.Equal(t, "{\"keepalive\":\"true\"}", string(body))
84
-		},
85
-		Error: func(code int, message string) {
86
-			t.Error(code, message)
87
-		},
88
-	})
89
-	if err != nil {
90
-		t.Error(err)
91
-	}
92
-}
93
-
94
-func TestMain(m *testing.M) {
95
-	// start tcp server
96
-	go Start("127.0.0.1", "8081")
97
-	client = export.NewClient("127.0.0.1", 8081, &ReadyStateCallback{})
98
-	for {
99
-		time.Sleep(time.Second)
100
-		if client.GetReadyState() == export.OPEN {
101
-			break
102
-		}
103
-	}
104
-	client.SetRequestProperty("Authorization", "Bearer "+genToken(217))
105
-	// call flag.Parse() here if TestMain uses flags
106
-	os.Exit(m.Run())
107
-}

+ 15
- 26
config/config.go View File

@@ -23,19 +23,15 @@ type appConfig struct {
23 23
 		Debug  bool   `mapstructure:"debug"`
24 24
 		Secret string `mapstructure:"secret"`
25 25
 	} `mapstructure:"app"`
26
-	DB struct {
27
-		Host               string `mapstructure:"host"`
28
-		User               string `mapstructure:"user"`
29
-		Password           string `mapstructure:"password"`
30
-		Name               string `mapstructure:"name"`
31
-		MaxIdleConnections int    `mapstructure:"max_idle_connections"`
32
-		MaxOpenConnections int    `mapstructure:"max_open_connections"`
33
-	} `mapstructure:"db"`
34
-	Redis struct {
35
-		Address  string `mapstructure:"address"`
36
-		Password string `mapstructure:"password"`
37
-		PoolSize int    `mapstructure:"pool_size"`
38
-	} `mapstructure:"redis"`
26
+	Notice struct {
27
+		SMTP struct {
28
+			Host     string `mapstructure:"host"`
29
+			Port     string `mapstructure:"port"`
30
+			User     string `mapstructure:"user"`
31
+			Password string `mapstructure:"password"`
32
+		} `mapstructure:"smtp"`
33
+		URLs []string `mapstructure:"urls"`
34
+	} `mapstructure:"notice"`
39 35
 }
40 36
 
41 37
 func init() {
@@ -49,21 +45,14 @@ func init() {
49 45
 	viper.SetDefault("app.debug", true)
50 46
 	viper.SetDefault("app.secret", "123456")
51 47
 
52
-	// db
53
-	viper.SetDefault("db.host", "localhost:3306")
54
-	viper.SetDefault("db.user", "user")
55
-	viper.SetDefault("db.password", "password")
56
-	viper.SetDefault("db.name", "name")
57
-	viper.SetDefault("db.max_idle_connections", 20)
58
-	viper.SetDefault("db.max_open_connections", 50)
59
-
60
-	// redis
61
-	viper.SetDefault("redis.address", "localhost")
62
-	viper.SetDefault("redis.password", "")
63
-	viper.SetDefault("redis.pool_size", 10)
48
+	// smtp
49
+	viper.SetDefault("notice.smtp.host", "host")
50
+	viper.SetDefault("notice.smtp.port", "port")
51
+	viper.SetDefault("notice.smtp.user", "user")
52
+	viper.SetDefault("notice.smtp.password", "password")
64 53
 
65 54
 	// bind env
66
-	viper.SetEnvPrefix("skeleton")
55
+	viper.SetEnvPrefix("monitor")
67 56
 	viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
68 57
 	viper.AutomaticEnv()
69 58
 

+ 2
- 2
docs/docs.go View File

@@ -11,8 +11,8 @@ import (
11 11
 var doc = `{
12 12
     "swagger": "2.0",
13 13
     "info": {
14
-        "description": "project skeleton for all project from links123.com",
15
-        "title": "project skeleton for all project from links123.com",
14
+        "description": "project monitor_status for all project from links123.com",
15
+        "title": "project monitor_status for all project from links123.com",
16 16
         "contact": {},
17 17
         "license": {},
18 18
         "version": "1.0"

+ 2
- 2
docs/swagger/swagger.json View File

@@ -1,8 +1,8 @@
1 1
 {
2 2
     "swagger": "2.0",
3 3
     "info": {
4
-        "description": "project skeleton for all project from links123.com",
5
-        "title": "project skeleton for all project from links123.com",
4
+        "description": "project monitor_status for all project from links123.com",
5
+        "title": "project monitor_status for all project from links123.com",
6 6
         "contact": {},
7 7
         "license": {},
8 8
         "version": "1.0"

+ 2
- 2
docs/swagger/swagger.yaml View File

@@ -1,9 +1,9 @@
1 1
 host: 127.0.0.1:8080/v1
2 2
 info:
3 3
   contact: {}
4
-  description: project skeleton for all project from links123.com
4
+  description: project monitor_status for all project from links123.com
5 5
   license: {}
6
-  title: project skeleton for all project from links123.com
6
+  title: project monitor_status for all project from links123.com
7 7
   version: "1.0"
8 8
 paths: {}
9 9
 swagger: "2.0"

+ 1
- 1
go.mod View File

@@ -1,4 +1,4 @@
1
-module git.links123.net/links123.com/skeleton
1
+module git.links123.net/links123.com/monitor_status
2 2
 
3 3
 require (
4 4
 	git.links123.net/links123.com/pkg/middleware/auth v0.0.0-20180919101150-037eea5b1493

+ 0
- 1
languages/en-US.ini View File

@@ -1 +0,0 @@
1
-hi = hello, %s

+ 0
- 1
languages/zh-CN.ini View File

@@ -1 +0,0 @@
1
-hi = 你好,%s

+ 4
- 6
main.go View File

@@ -2,25 +2,23 @@ package main
2 2
 
3 3
 import (
4 4
 	"git.links123.net/links123.com/monitor_status/cmd/http"
5
-	"git.links123.net/links123.com/monitor_status/cmd/tcp"
6 5
 	"git.links123.net/links123.com/monitor_status/cmd/version"
7 6
 	"github.com/spf13/cobra"
8 7
 )
9 8
 
10 9
 var apiVersion, gitCommit, built string
11 10
 
12
-// @title project skeleton for all project from links123.com
11
+// @title project monitor_status for all project from links123.com
13 12
 // @version 1.0
14
-// @description project skeleton for all project from links123.com
13
+// @description project monitor_status for all project from links123.com
15 14
 // @host 127.0.0.1:8080/v1
16 15
 func main() {
17 16
 	rootCmd := &cobra.Command{
18
-		Use:   "skeleton",
19
-		Short: "skeleton api for the project of links123.com's campus",
17
+		Use:   "monitor_status",
18
+		Short: "monitor_status api for the project of links123.com's campus",
20 19
 	}
21 20
 
22 21
 	rootCmd.AddCommand(http.RunCommand())
23
-	rootCmd.AddCommand(tcp.RunCommand())
24 22
 	rootCmd.AddCommand(version.RunCommand(apiVersion, gitCommit, built))
25 23
 
26 24
 	if err := rootCmd.Execute(); err != nil {

+ 0
- 10
service/store/cache/auth.go View File

@@ -1,10 +0,0 @@
1
-package cache
2
-
3
-import (
4
-	"git.links123.net/links123.com/pkg/middleware/auth"
5
-)
6
-
7
-// AuthSessionStore 认证存储
8
-func AuthSessionStore() auth.Session {
9
-	return session
10
-}

+ 0
- 12
service/store/cache/auth_test.go View File

@@ -1,12 +0,0 @@
1
-package cache
2
-
3
-import (
4
-	"testing"
5
-)
6
-
7
-func TestAuthSessionStore(t *testing.T) {
8
-	store := AuthSessionStore()
9
-	if store == nil {
10
-		t.Error("init auth session store error")
11
-	}
12
-}

+ 0
- 59
service/store/cache/cache.go View File

@@ -1,60 +1 @@
1 1
 package cache
2
-
3
-import (
4
-	"sync"
5
-	"time"
6
-
7
-	"git.links123.net/links123.com/pkg/middleware/auth"
8
-	"git.links123.net/links123.com/skeleton/config"
9
-	"github.com/go-redis/redis"
10
-	"github.com/sirupsen/logrus"
11
-)
12
-
13
-var (
14
-	client  *redis.Client
15
-	session auth.Session
16
-	once    = &sync.Once{}
17
-)
18
-
19
-// Init 初始化缓存
20
-func Init() {
21
-	once.Do(func() {
22
-		redisConfig := config.C.Redis
23
-
24
-		client = redis.NewClient(&redis.Options{
25
-			Addr:     redisConfig.Address,
26
-			Password: redisConfig.Password,
27
-			PoolSize: redisConfig.PoolSize,
28
-		})
29
-
30
-		for {
31
-			if err := client.Ping().Err(); err != nil {
32
-				logrus.Warn("waiting for redis server start...")
33
-				time.Sleep(3 * time.Second)
34
-				continue
35
-			}
36
-
37
-			logrus.Info("connect to redis successful")
38
-
39
-			break
40
-		}
41
-
42
-		if config.C.App.Debug {
43
-			session = auth.NewDebugSessionStore()
44
-		} else {
45
-			session = auth.NewRedisSessionStore(redisConfig.Address, redisConfig.Password)
46
-		}
47
-	})
48
-}
49
-
50
-// Close 退出时关闭链接
51
-func Close() {
52
-	if client != nil {
53
-		err := client.Close()
54
-		if err != nil {
55
-			logrus.Errorf("close redis connection error: %s", err.Error())
56
-			return
57
-		}
58
-		logrus.Info("redis connection closed")
59
-	}
60
-}

+ 0
- 11
service/store/cache/cache_test.go View File

@@ -1,11 +0,0 @@
1
-package cache
2
-
3
-import (
4
-	"os"
5
-	"testing"
6
-)
7
-
8
-func TestMain(m *testing.M) {
9
-	Init()
10
-	os.Exit(m.Run())
11
-}

+ 0
- 69
service/store/mysql/mysql.go View File

@@ -1,69 +0,0 @@
1
-package mysql
2
-
3
-import (
4
-	"time"
5
-
6
-	"git.links123.net/links123.com/skeleton/config"
7
-	"git.links123.net/links123.com/skeleton/service/api"
8
-	"github.com/sirupsen/logrus"
9
-	"upper.io/db.v3/lib/sqlbuilder"
10
-	"upper.io/db.v3/mysql"
11
-)
12
-
13
-var (
14
-	session sqlbuilder.Database
15
-)
16
-
17
-// Init 初始化数据库
18
-func Init() {
19
-	dbConfig := config.C.DB
20
-	settings := mysql.ConnectionURL{
21
-		Host:     dbConfig.Host,
22
-		Database: dbConfig.Name,
23
-		User:     dbConfig.User,
24
-		Password: dbConfig.Password,
25
-	}
26
-
27
-	var err error
28
-	if session, err = mysql.Open(settings); err != nil {
29
-		logrus.WithField("dsn", settings.String()).Info("connect db failed")
30
-		panic(err)
31
-	}
32
-
33
-	logrus.WithField("dsn", settings.String()).Info("connect db success")
34
-
35
-	session.SetMaxIdleConns(dbConfig.MaxIdleConnections)
36
-	session.SetMaxOpenConns(dbConfig.MaxOpenConnections)
37
-
38
-	for {
39
-		if err := session.Ping(); err != nil {
40
-			logrus.Warn("waiting for mysql server start...")
41
-			time.Sleep(3 * time.Second)
42
-			continue
43
-		}
44
-
45
-		logrus.Info("connect to mysql successful")
46
-
47
-		break
48
-	}
49
-
50
-	if config.C.App.Debug {
51
-		session.SetLogging(true)
52
-	}
53
-}
54
-
55
-// Close 在程序退出时关闭连接
56
-func Close() {
57
-	if session != nil {
58
-		err := session.Close()
59
-		if err != nil {
60
-			logrus.Errorf("error close mysql connection: %s", err.Error())
61
-			return
62
-		}
63
-	}
64
-	logrus.Info("mysql connection close")
65
-}
66
-
67
-func paging(selector sqlbuilder.Selector, cp api.CommonParams) sqlbuilder.Paginator {
68
-	return selector.Paginate(uint(cp.Limit)).Page(uint(cp.Page))
69
-}