MCPcopy
hub / github.com/tuna/tunasync / LoadConfig

Function LoadConfig

manager/config.go:33–75  ·  view source on GitHub ↗

LoadConfig loads config from specified file

(cfgFile string, c *cli.Context)

Source from the content-addressed store, hash-verified

31
32// LoadConfig loads config from specified file
33func LoadConfig(cfgFile string, c *cli.Context) (*Config, error) {
34
35 cfg := new(Config)
36 cfg.Server.Addr = "127.0.0.1"
37 cfg.Server.Port = 14242
38 cfg.Debug = false
39 cfg.Files.StatusFile = "/var/lib/tunasync/tunasync.json"
40 cfg.Files.DBFile = "/var/lib/tunasync/tunasync.db"
41 cfg.Files.DBType = "bolt"
42
43 if cfgFile != "" {
44 if _, err := toml.DecodeFile(cfgFile, cfg); err != nil {
45 logger.Error(err.Error())
46 return nil, err
47 }
48 }
49
50 if c == nil {
51 return cfg, nil
52 }
53
54 if c.String("addr") != "" {
55 cfg.Server.Addr = c.String("addr")
56 }
57 if c.Int("port") > 0 {
58 cfg.Server.Port = c.Int("port")
59 }
60 if c.String("cert") != "" && c.String("key") != "" {
61 cfg.Server.SSLCert = c.String("cert")
62 cfg.Server.SSLKey = c.String("key")
63 }
64 if c.String("status-file") != "" {
65 cfg.Files.StatusFile = c.String("status-file")
66 }
67 if c.String("db-file") != "" {
68 cfg.Files.DBFile = c.String("db-file")
69 }
70 if c.String("db-type") != "" {
71 cfg.Files.DBType = c.String("db-type")
72 }
73
74 return cfg, nil
75}

Callers 3

startManagerFunction · 0.92
mainFunction · 0.92
TestConfigFunction · 0.70

Calls 2

ErrorMethod · 0.80
StringMethod · 0.45

Tested by 1

TestConfigFunction · 0.56