github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/helper/config.go (about) 1 package helper 2 3 import ( 4 "strconv" 5 "github.com/insionng/yougam/libraries/goconfig" 6 ) 7 8 func init() { 9 TouchFile(ConfigPath) 10 conf, e := goconfig.LoadConfigFile(ConfigPath) 11 if e == nil { 12 13 if site, e := conf.GetSection("site"); e == nil { 14 Domain = site["Domain"] 15 AesConstKey = site["Aes5Keys"] 16 SiteName = site["SiteName"] 17 SiteTitle = site["SiteTitle"] 18 Keywords = site["Keywords"] 19 Description = site["Description"] 20 } else { 21 22 if v, _ := conf.GetValue("site", "Domain"); v == "" { 23 conf.SetValue("site", "Domain", Domain) 24 } 25 if v, _ := conf.GetValue("site", "SiteName"); v == "" { 26 conf.SetValue("site", "SiteName", SiteName) 27 } 28 if v, _ := conf.GetValue("site", "Aes5Keys"); v == "" { 29 conf.SetValue("site", "Aes5Keys", AesConstKey) 30 } 31 if v, _ := conf.GetValue("site", "SiteTitle"); v == "" { 32 conf.SetValue("site", "SiteTitle", SiteTitle) 33 } 34 if v, _ := conf.GetValue("site", "Keywords"); v == "" { 35 conf.SetValue("site", "Keywords", Keywords) 36 } 37 if v, _ := conf.GetValue("site", "Description"); v == "" { 38 conf.SetValue("site", "Description", Description) 39 } 40 } 41 42 if datebase, e := conf.GetSection("datebase"); e == nil { 43 DataType = datebase["DataType"] 44 DBConnect = datebase["Connect"] 45 } else { 46 47 if v, _ := conf.GetValue("datebase", "DataType"); v == "" { 48 conf.SetValue("datebase", "DataType", DataType) 49 } 50 if v, _ := conf.GetValue("datebase", "Connect"); v == "" { 51 conf.SetValue("datebase", "Connect", DBConnect) 52 } 53 } 54 55 if cloud, e := conf.GetSection("cloud"); e == nil { 56 BUCKET4QINIU = cloud["BUCKET4QINIU"] 57 DOMAIN4QINIU = cloud["DOMAIN4QINIU"] 58 AKEY4QINIU = cloud["AKEY4QINIU"] 59 SKEY4QINIU = cloud["DOMAIN4QINIU"] 60 } else { 61 if v, _ := conf.GetValue("cloud", "BUCKET4QINIU"); v == "" { 62 conf.SetValue("cloud", "BUCKET4QINIU", "") 63 } 64 if v, _ := conf.GetValue("cloud", "DOMAIN4QINIU"); v == "" { 65 conf.SetValue("cloud", "DOMAIN4QINIU", "") 66 } 67 if v, _ := conf.GetValue("cloud", "AKEY4QINIU"); v == "" { 68 conf.SetValue("cloud", "AKEY4QINIU", "") 69 } 70 if v, _ := conf.GetValue("cloud", "SKEY4QINIU"); v == "" { 71 conf.SetValue("cloud", "SKEY4QINIU", "") 72 } 73 } 74 75 if mail, e := conf.GetSection("mail"); e == nil { 76 SmtpHost = mail["SmtpHost"] 77 SmtpPort = mail["SmtpPort"] 78 MailUser = mail["MailUser"] 79 MailPassword = mail["MailPassword"] 80 MailAdline = mail["MailAdline"] 81 } else { 82 if v, _ := conf.GetValue("mail", "SmtpHost"); v == "" { 83 conf.SetValue("mail", "SmtpHost", SmtpHost) 84 } 85 if v, _ := conf.GetValue("mail", "SmtpPort"); v == "" { 86 conf.SetValue("mail", "SmtpPort", SmtpPort) 87 } 88 if v, _ := conf.GetValue("mail", "MailUser"); v == "" { 89 conf.SetValue("mail", "MailUser", MailUser) 90 } 91 if v, _ := conf.GetValue("mail", "MailPassword"); v == "" { 92 conf.SetValue("mail", "MailPassword", MailPassword) 93 } 94 if v, _ := conf.GetValue("mail", "MailAdline"); v == "" { 95 conf.SetValue("mail", "MailAdline", MailAdline) 96 } 97 98 goconfig.SaveConfigFile(conf, ConfigPath) 99 100 } 101 if mail, e := conf.GetSection("signup"); e != nil { 102 IsCaptcha = true 103 } else { 104 if isCaptcha, err := strconv.ParseBool(mail["captcha"]); err == nil { 105 IsCaptcha = isCaptcha 106 } 107 } 108 } 109 } 110 111 func Theme() (theme string) { 112 113 TouchFile(ConfigPath) 114 115 if conf, e := goconfig.LoadConfigFile(ConfigPath); e == nil { 116 if style, e := conf.GetValue("themes", "style"); (style == "") || (e != nil) { 117 conf.SetValue("themes", "style", "yougam") 118 goconfig.SaveConfigFile(conf, ConfigPath) 119 theme = "yougam" 120 } else { 121 theme = style 122 } 123 } 124 125 return theme 126 127 } 128 129 func IsSendMail() (isSendMail bool) { 130 131 TouchFile(ConfigPath) 132 133 if conf, e := goconfig.LoadConfigFile(ConfigPath); e == nil { 134 if i, e := conf.GetValue("signup", "sendmail"); (i == "") || (e != nil) { 135 conf.SetValue("signup", "sendmail", "false") 136 goconfig.SaveConfigFile(conf, ConfigPath) 137 isSendMail = false 138 } else { 139 if i == "true" { 140 isSendMail = true 141 } else { 142 isSendMail = false 143 } 144 } 145 } 146 147 return isSendMail 148 149 }