Browse Source

add app dir

Paul 6 years ago
parent
commit
36c2eb3e5c
4 changed files with 182 additions and 2 deletions
  1. 116
    2
      Gopkg.lock
  2. 40
    0
      app/config.go
  3. 14
    0
      app/language.go
  4. 12
    0
      app/logger.go

+ 116
- 2
Gopkg.lock View File

@@ -1,6 +1,18 @@
1 1
 # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2 2
 
3 3
 
4
+[[projects]]
5
+  branch = "master"
6
+  name = "github.com/Unknwon/i18n"
7
+  packages = ["."]
8
+  revision = "b64d336589669d317928070e70ba0ae558f16633"
9
+
10
+[[projects]]
11
+  name = "github.com/fsnotify/fsnotify"
12
+  packages = ["."]
13
+  revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
14
+  version = "v1.4.7"
15
+
4 16
 [[projects]]
5 17
   branch = "master"
6 18
   name = "github.com/gin-contrib/sse"
@@ -23,30 +35,132 @@
23 35
   revision = "925541529c1fa6821df4e44ce2723319eb2be768"
24 36
   version = "v1.0.0"
25 37
 
38
+[[projects]]
39
+  branch = "master"
40
+  name = "github.com/hashicorp/hcl"
41
+  packages = [
42
+    ".",
43
+    "hcl/ast",
44
+    "hcl/parser",
45
+    "hcl/printer",
46
+    "hcl/scanner",
47
+    "hcl/strconv",
48
+    "hcl/token",
49
+    "json/parser",
50
+    "json/scanner",
51
+    "json/token"
52
+  ]
53
+  revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168"
54
+
55
+[[projects]]
56
+  name = "github.com/magiconair/properties"
57
+  packages = ["."]
58
+  revision = "c3beff4c2358b44d0493c7dda585e7db7ff28ae6"
59
+  version = "v1.7.6"
60
+
26 61
 [[projects]]
27 62
   name = "github.com/mattn/go-isatty"
28 63
   packages = ["."]
29 64
   revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
30 65
   version = "v0.0.3"
31 66
 
67
+[[projects]]
68
+  branch = "master"
69
+  name = "github.com/mitchellh/mapstructure"
70
+  packages = ["."]
71
+  revision = "00c29f56e2386353d58c599509e8dc3801b0d716"
72
+
73
+[[projects]]
74
+  name = "github.com/pelletier/go-toml"
75
+  packages = ["."]
76
+  revision = "acdc4509485b587f5e675510c4f2c63e90ff68a8"
77
+  version = "v1.1.0"
78
+
79
+[[projects]]
80
+  name = "github.com/sirupsen/logrus"
81
+  packages = ["."]
82
+  revision = "c155da19408a8799da419ed3eeb0cb5db0ad5dbc"
83
+  version = "v1.0.5"
84
+
85
+[[projects]]
86
+  name = "github.com/spf13/afero"
87
+  packages = [
88
+    ".",
89
+    "mem"
90
+  ]
91
+  revision = "63644898a8da0bc22138abf860edaf5277b6102e"
92
+  version = "v1.1.0"
93
+
94
+[[projects]]
95
+  name = "github.com/spf13/cast"
96
+  packages = ["."]
97
+  revision = "8965335b8c7107321228e3e3702cab9832751bac"
98
+  version = "v1.2.0"
99
+
100
+[[projects]]
101
+  branch = "master"
102
+  name = "github.com/spf13/jwalterweatherman"
103
+  packages = ["."]
104
+  revision = "7c0cea34c8ece3fbeb2b27ab9b59511d360fb394"
105
+
106
+[[projects]]
107
+  name = "github.com/spf13/pflag"
108
+  packages = ["."]
109
+  revision = "583c0c0531f06d5278b7d917446061adc344b5cd"
110
+  version = "v1.0.1"
111
+
112
+[[projects]]
113
+  name = "github.com/spf13/viper"
114
+  packages = ["."]
115
+  revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736"
116
+  version = "v1.0.2"
117
+
32 118
 [[projects]]
33 119
   name = "github.com/ugorji/go"
34 120
   packages = ["codec"]
35 121
   revision = "b4c50a2b199d93b13dc15e78929cfb23bfdf21ab"
36 122
   version = "v1.1.1"
37 123
 
124
+[[projects]]
125
+  branch = "master"
126
+  name = "golang.org/x/crypto"
127
+  packages = ["ssh/terminal"]
128
+  revision = "b49d69b5da943f7ef3c9cf91c8777c1f78a0cc3c"
129
+
38 130
 [[projects]]
39 131
   branch = "master"
40 132
   name = "golang.org/x/sys"
41
-  packages = ["unix"]
133
+  packages = [
134
+    "unix",
135
+    "windows"
136
+  ]
42 137
   revision = "79b0c6888797020a994db17c8510466c72fe75d9"
43 138
 
139
+[[projects]]
140
+  name = "golang.org/x/text"
141
+  packages = [
142
+    "internal/gen",
143
+    "internal/triegen",
144
+    "internal/ucd",
145
+    "transform",
146
+    "unicode/cldr",
147
+    "unicode/norm"
148
+  ]
149
+  revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
150
+  version = "v0.3.0"
151
+
44 152
 [[projects]]
45 153
   name = "gopkg.in/go-playground/validator.v8"
46 154
   packages = ["."]
47 155
   revision = "5f1438d3fca68893a817e4a66806cea46a9e4ebf"
48 156
   version = "v8.18.2"
49 157
 
158
+[[projects]]
159
+  name = "gopkg.in/ini.v1"
160
+  packages = ["."]
161
+  revision = "6529cf7c58879c08d927016dde4477f18a0634cb"
162
+  version = "v1.36.0"
163
+
50 164
 [[projects]]
51 165
   name = "gopkg.in/yaml.v2"
52 166
   packages = ["."]
@@ -56,6 +170,6 @@
56 170
 [solve-meta]
57 171
   analyzer-name = "dep"
58 172
   analyzer-version = 1
59
-  inputs-digest = "1a2b10f3ec80fa4b6ad88156b737403ca45820640ec668e0b797538b6274d305"
173
+  inputs-digest = "8fe597b39b7ddfd166b23ba2d6c37c68c00acbcfe4aaab97b44ccfdda2394c0e"
60 174
   solver-name = "gps-cdcl"
61 175
   solver-version = 1

+ 40
- 0
app/config.go View File

@@ -0,0 +1,40 @@
1
+package app
2
+
3
+import (
4
+	"path/filepath"
5
+	"strings"
6
+
7
+	"github.com/spf13/viper"
8
+)
9
+
10
+var (
11
+	Config appConfig
12
+)
13
+
14
+type appConfig struct {
15
+	DB struct {
16
+		Host               string `mapstructure:"host"`
17
+		Port               string `mapstructure:"port"`
18
+		User               string `mapstructure:"user"`
19
+		Password           string `mapstructure:"password"`
20
+		Name               string `mapstructure:"name"`
21
+		MaxIdleConnections int    `mapstructure:"max_idle_connections"`
22
+		MaxOpenConnections int    `mapstructure:"max_idle_connections"`
23
+	} `mapstructure:"db"`
24
+	Secret struct {
25
+		AuthKey string `mapstructure:"auth_key"`
26
+	} `mapstructure:"secret"`
27
+}
28
+
29
+func InitConfig(cfg string) {
30
+	viper.SetConfigFile(cfg)
31
+	viper.SetConfigType(strings.Trim(filepath.Ext(cfg), "."))
32
+
33
+	if err := viper.ReadInConfig(); err != nil {
34
+		panic(err)
35
+	}
36
+
37
+	if err := viper.Unmarshal(&Config); err != nil {
38
+		panic(err)
39
+	}
40
+}

+ 14
- 0
app/language.go View File

@@ -0,0 +1,14 @@
1
+package app
2
+
3
+import "github.com/Unknwon/i18n"
4
+
5
+func InitLang() {
6
+	languages := []string{"en-US", "zh-CN"}
7
+	for _, language := range languages {
8
+		if err := i18n.SetMessage(language, "languages/"+language+".ini"); err != nil {
9
+			panic(err)
10
+		}
11
+	}
12
+
13
+	i18n.SetDefaultLang("en-US")
14
+}

+ 12
- 0
app/logger.go View File

@@ -0,0 +1,12 @@
1
+package app
2
+
3
+import (
4
+	"github.com/gin-gonic/gin"
5
+	"github.com/sirupsen/logrus"
6
+)
7
+
8
+func InitLogger() {
9
+	if gin.Mode() == gin.DebugMode {
10
+		logrus.SetLevel(logrus.DebugLevel)
11
+	}
12
+}