Changeset 147 in code for trunk/config
- Timestamp:
- Mar 18, 2024, 1:23:54 AM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/config.go
r142 r147 2 2 3 3 import ( 4 " os"4 "gopkg.in/ini.v1" 5 5 ) 6 6 7 typeConfig struct {7 var Config struct { 8 8 Debug bool 9 9 ListenAddress string … … 17 17 } 18 18 19 var DefaultConfig *Config 19 func readConfig(file string) error { 20 cfg, err := ini.Load(file) 21 if err != nil { 22 return err 23 } 24 Config.Debug, _ = cfg.Section("yukari").Key("debug").Bool() 25 Config.ListenAddress = cfg.Section("yukari").Key("listen").String() 26 Config.Key = cfg.Section("yukari").Key("key").String() 27 Config.IPV6, _ = cfg.Section("yukari").Key("ipv6").Bool() 28 Config.RequestTimeout, _ = cfg.Section("yukari").Key("timeout").Uint() 29 Config.FollowRedirect, _ = cfg.Section("yukari").Key("followredirect").Bool() 30 Config.MaxConnsPerHost, _ = cfg.Section("yukari").Key("max_conns_per_host").Uint() 31 Config.UrlParameter = cfg.Section("yukari").Key("urlparam").String() 32 Config.HashParameter = cfg.Section("yukari").Key("hashparam").String() 20 33 21 func init() { 22 default_listen_addr := os.Getenv("YUKARI_ADDRESS") 23 if default_listen_addr == "" { 24 default_listen_addr = "127.0.0.1:3000" 25 } 26 default_url_parameter := os.Getenv("YUKARI_URL_PARAM") 27 if default_url_parameter == "" { 28 default_url_parameter = "yukariurl" 29 } 30 default_hash_parameter := os.Getenv("YUKARI_HASH_PARAM") 31 if default_hash_parameter == "" { 32 default_hash_parameter = "yukarihash" 33 } 34 default_key := os.Getenv("YUKARI_KEY") 35 DefaultConfig = &Config{ 36 Debug: os.Getenv("DEBUG") != "false", 37 ListenAddress: default_listen_addr, 38 Key: default_key, 39 IPV6: true, 40 RequestTimeout: 5, 41 FollowRedirect: false, 42 MaxConnsPerHost: 4, 43 UrlParameter: default_url_parameter, 44 HashParameter: default_hash_parameter, 45 } 34 return nil 46 35 }
Note:
See TracChangeset
for help on using the changeset viewer.