From c1f6611b5d6da17ad5f6ae733d4a0c08d773d27f Mon Sep 17 00:00:00 2001 From: deepzz0 Date: Sun, 2 Oct 2016 19:53:21 +0800 Subject: [PATCH] rm runmode --- api.go | 2 +- back.go | 2 +- conf/app.yml | 28 +++++++++++----------------- disqus.go | 2 +- front.go | 2 +- router.go | 13 ++++++------- setting/setting.go | 6 +++--- xml.go | 5 +++-- 8 files changed, 27 insertions(+), 33 deletions(-) diff --git a/api.go b/api.go index 9926184..86875da 100644 --- a/api.go +++ b/api.go @@ -375,7 +375,7 @@ func apiTrashRecover(c *gin.Context) { } func responseNotice(c *gin.Context, typ, content, hl string) { - domain := runmode.Domain + domain := setting.Conf.Mode.Domain if i := strings.Index(domain, ":"); i > -1 { domain = domain[0:i] } diff --git a/back.go b/back.go index 64cece9..920235b 100644 --- a/back.go +++ b/back.go @@ -119,7 +119,7 @@ func HandlePost(c *gin.Context) { h["Post"] = true h["Path"] = c.Request.URL.Path h["Title"] = "撰写文章 | " + Ei.BTitle - h["Domain"] = runmode.Domain + h["Domain"] = setting.Conf.Mode.Domain h["Series"] = Ei.Series c.HTML(http.StatusOK, "backLayout.html", h) } diff --git a/conf/app.yml b/conf/app.yml index fdc07dc..be162a7 100644 --- a/conf/app.yml +++ b/conf/app.yml @@ -1,7 +1,7 @@ -# 静态文件版本 -staticversion: 2 # 运行模式 dev or prod runmode: prod +# 静态文件版本 +staticversion: 2 # 回收箱保留48小时 trash: -48 # 定时清理回收箱,%d小时 @@ -29,21 +29,15 @@ disqus: url: https://disqus.com/api/3.0/threads/set.json interval: 5 # 运行模式 -modes: - dev: - # don't modify - enablehttp: true - httpport: 9000 - domain: deepzz.com - prod: - # you can fix certfile, keyfile, domain - enablehttp: true - httpport: 9000 - enablehttps: false - httpsport: 443 - certfile: conf/certs/domain.pem - keyfile: conf/certs/domain.key - domain: deepzz.com +mode: + # you can fix certfile, keyfile, domain + enablehttp: true + httpport: 9000 + enablehttps: false + httpsport: 443 + certfile: conf/certs/domain.pem + keyfile: conf/certs/domain.key + domain: deepzz.com # twitter地址: //twitter.com/chenqijing2 twitter: //twitter.com/chenqijing2 # 以下数据初始化用,可在后台修改 diff --git a/disqus.go b/disqus.go index 3c9ae65..37a292a 100644 --- a/disqus.go +++ b/disqus.go @@ -33,7 +33,7 @@ func CommentsCount() { var threads []string for ; index < len(Ei.Articles) && count < 20; index++ { artc := Ei.Articles[index] - threads = append(threads, fmt.Sprintf("thread=link:https://%s/post/%s.html", runmode.Domain, artc.Slug)) + threads = append(threads, fmt.Sprintf("thread=link:https://%s/post/%s.html", setting.Conf.Mode.Domain, artc.Slug)) count++ } count = 0 diff --git a/front.go b/front.go index a75df25..a532581 100644 --- a/front.go +++ b/front.go @@ -69,7 +69,7 @@ func GetBase() gin.H { "CopyYear": time.Now().Year(), "BTitle": Ei.BTitle, "BeiAn": Ei.BeiAn, - "Domain": runmode.Domain, + "Domain": setting.Conf.Mode.Domain, "Static": setting.Conf.Static, } } diff --git a/router.go b/router.go index ce4283e..65592e1 100644 --- a/router.go +++ b/router.go @@ -14,7 +14,6 @@ import ( ) var router *gin.Engine -var runmode = setting.Conf.Modes[setting.Conf.RunMode] func init() { if setting.Conf.RunMode == setting.PROD { @@ -90,10 +89,10 @@ func Run() { endRunning = make(chan bool, 1) err error ) - if runmode.EnableHttp { + if setting.Conf.Mode.EnableHttp { go func() { - logd.Info(fmt.Sprintf("http server Running on %d", runmode.HttpPort)) - err = router.Run(fmt.Sprintf(":%d", runmode.HttpPort)) + logd.Info(fmt.Sprintf("http server Running on %d", setting.Conf.Mode.HttpPort)) + err = router.Run(fmt.Sprintf(":%d", setting.Conf.Mode.HttpPort)) if err != nil { logd.Info("ListenAndServe: ", err) time.Sleep(100 * time.Microsecond) @@ -101,10 +100,10 @@ func Run() { } }() } - if runmode.EnableHttps { + if setting.Conf.Mode.EnableHttps { go func() { - logd.Info(fmt.Sprintf("https server Running on %d", runmode.HttpsPort)) - err = router.RunTLS(fmt.Sprintf(":%d", runmode.HttpsPort), runmode.CertFile, runmode.KeyFile) + logd.Info(fmt.Sprintf("https server Running on %d", setting.Conf.Mode.HttpsPort)) + err = router.RunTLS(fmt.Sprintf(":%d", setting.Conf.Mode.HttpsPort), setting.Conf.Mode.CertFile, setting.Conf.Mode.KeyFile) if err != nil { logd.Info("ListenAndServe: ", err) time.Sleep(100 * time.Microsecond) diff --git a/setting/setting.go b/setting/setting.go index d4e530b..2ef6e84 100644 --- a/setting/setting.go +++ b/setting/setting.go @@ -40,9 +40,9 @@ type Config struct { URL string Interval int } - Modes map[string]RunMode // 运行模式 - Twitter string // twitter地址 - Blogger struct { // 初始化数据 + Mode RunMode // 运行模式 + Twitter string // twitter地址 + Blogger struct { // 初始化数据 BlogName string SubTitle string BeiAn string diff --git a/xml.go b/xml.go index e8e7e7f..69db94d 100644 --- a/xml.go +++ b/xml.go @@ -7,6 +7,7 @@ import ( "text/template" "time" + "github.com/eiblog/eiblog/setting" "github.com/eiblog/utils/logd" "github.com/eiblog/utils/tmpl" ) @@ -40,7 +41,7 @@ func doFeed() { params := map[string]interface{}{ "Title": Ei.BTitle, "SubTitle": Ei.SubTitle, - "Domain": runmode.Domain, + "Domain": setting.Conf.Mode.Domain, "BuildDate": buildDate.Format(time.RFC1123Z), "Artcs": artcs, } @@ -65,7 +66,7 @@ func doSitemap() { logd.Error("not found sitemapTpl.") return } - params := map[string]interface{}{"Artcs": Ei.Articles, "Domain": runmode.Domain} + params := map[string]interface{}{"Artcs": Ei.Articles, "Domain": setting.Conf.Mode.Domain} f, err := os.OpenFile("static/sitemap.xml", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) if err != nil { logd.Error(err)