Changeset 147 in code for trunk/config/config.go


Ignore:
Timestamp:
Mar 18, 2024, 1:23:54 AM (15 months ago)
Author:
Izuru Yakumo
Message:

コードのリファクタリングが完了しました

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/config/config.go

    r142 r147  
    22
    33import (
    4         "os"
     4        "gopkg.in/ini.v1"
    55)
    66
    7 type Config struct {
     7var Config struct {
    88        Debug          bool
    99        ListenAddress  string
     
    1717}
    1818
    19 var DefaultConfig *Config
     19func 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()
    2033
    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
    4635}
Note: See TracChangeset for help on using the changeset viewer.