This repository was archived by the owner on Nov 5, 2024. It is now read-only.
File tree 4 files changed +10
-16
lines changed
4 files changed +10
-16
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ var serverCmd = &cobra.Command{
35
35
}
36
36
logrus .Infoln ("config init success" )
37
37
38
- tplFile := viper .GetString ("customTmpl " )
38
+ tplFile := viper .GetString ("example.tpl " )
39
39
if tplFile != "" {
40
40
tmpl , err := template .ParseFiles (tplFile )
41
41
if err != nil {
Original file line number Diff line number Diff line change 1
1
package config
2
2
3
3
import (
4
- "strings "
5
-
4
+ "bytes "
5
+ _ "embed"
6
6
"github.com/fsnotify/fsnotify"
7
7
"github.com/sirupsen/logrus"
8
8
"github.com/spf13/viper"
9
9
)
10
10
11
+ //go:embed config.yaml
12
+ var configBytes []byte
13
+
11
14
type Config struct {
12
15
Name string
13
16
}
@@ -20,20 +23,12 @@ func (c *Config) WatchConfig() {
20
23
}
21
24
22
25
func (c * Config ) Init () error {
23
- if c .Name != "" {
24
- viper .SetConfigName (c .Name )
25
- } else {
26
- viper .AddConfigPath ("./config" )
27
- viper .SetConfigName ("config" )
28
- }
29
26
viper .SetConfigType ("yaml" )
30
- viper .AutomaticEnv ()
31
- viper .SetEnvPrefix ("monitor" )
32
- replacer := strings .NewReplacer ("." , "_" )
33
- viper .SetEnvKeyReplacer (replacer )
34
- if err := viper .ReadInConfig (); err != nil {
27
+ err := viper .ReadConfig (bytes .NewBufferString (string (configBytes )))
28
+ if err != nil {
35
29
return err
36
30
}
31
+ viper .AutomaticEnv ()
37
32
38
33
return nil
39
34
}
Original file line number Diff line number Diff line change 1
- name : DbToGoStruct # API Server的名字
1
+ name : DbToGoStruct # API Server的名字
2
2
gormlog : true
3
3
server :
4
4
host : 127.0.0.1
5
5
port : 8000
6
6
7
- customTmpl : example.tpl
8
7
9
8
genFilePath : ./
You can’t perform that action at this time.
0 commit comments