예제 #1
0
파일: setting.go 프로젝트: qiancy/gowalker
func init() {
	log.Prefix = "[Go Walker]"

	sources := []interface{}{"conf/app.ini"}
	if com.IsFile("custom/app.ini") {
		sources = append(sources, "custom/app.ini")
	}

	var err error
	Cfg, err = macaron.SetConfig(sources[0], sources[1:]...)
	if err != nil {
		log.FatalD(4, "Fail to set configuration: %v", err)
	}

	if Cfg.Section("").Key("RUN_MODE").String() == "prod" {
		ProdMode = true
		macaron.Env = macaron.PROD
		macaron.ColorLog = false
	}

	sec := Cfg.Section("server")
	HTTPPort = sec.Key("HTTP_PORT").MustInt(8080)
	FetchTimeout = time.Duration(sec.Key("FETCH_TIMEOUT").MustInt(60)) * time.Second
	DocsJsPath = sec.Key("DOCS_JS_PATH").MustString("raw/docs/")
	DocsGobPath = sec.Key("DOCS_GOB_PATH").MustString("raw/gob/")

	GitHubCredentials = "client_id=" + Cfg.Section("github").Key("CLIENT_ID").String() +
		"&client_secret=" + Cfg.Section("github").Key("CLIENT_SECRET").String()

}
예제 #2
0
파일: setting.go 프로젝트: harryyeh/switch
func init() {
	log.NewLogger(0, "console", `{"level": 0}`)

	sources := []interface{}{"conf/app.ini"}
	if com.IsFile("custom/app.ini") {
		sources = append(sources, "custom/app.ini")
	}

	var err error
	Cfg, err = macaron.SetConfig(sources[0], sources[1:]...)
	if err != nil {
		log.Fatal(4, "Fail to set configuration: %v", err)
	}

	AppName = Cfg.Section("").Key("APP_NAME").String()

	if Cfg.Section("").Key("RUN_MODE").MustString("dev") == "prod" {
		ProdMode = true
		macaron.Env = macaron.PROD
		macaron.ColorLog = false
	}

	HttpPort = Cfg.Section("server").Key("HTTP_PORT").MustInt(8084)
	ArchivePath = Cfg.Section("server").Key("ARCHIVE_PATH").MustString("data/archives")
	os.MkdirAll(ArchivePath, os.ModePerm)

	MaxUploadSize = Cfg.Section("server").Key("MAX_UPLOAD_SIZE").MustInt64(5)

	GithubCredentials = "client_id=" + Cfg.Section("github").Key("CLIENT_ID").String() +
		"&client_secret=" + Cfg.Section("github").Key("CLIENT_SECRET").String()

	conf.UP_HOST = Cfg.Section("qiniu").Key("UP_HOST").MustString(conf.UP_HOST)
	BucketName = Cfg.Section("qiniu").Key("BUCKET_NAME").String()
	BucketUrl = Cfg.Section("qiniu").Key("BUCKET_URL").String()
	conf.ACCESS_KEY = Cfg.Section("qiniu").Key("ACCESS_KEY").String()
	conf.SECRET_KEY = Cfg.Section("qiniu").Key("SECRET_KEY").String()

	AccessToken = Cfg.Section("admin").Key("ACCESS_TOKEN").String()
}
예제 #3
0
파일: setting.go 프로젝트: 0-T-0/peach
func NewContext() {
	log.Prefix = "[Peach]"

	if !com.IsFile(CustomConf) {
		log.Fatal("No custom configuration found: 'custom/app.ini'")
	}
	sources := []interface{}{"conf/app.ini", CustomConf}

	var err error
	Cfg, err = macaron.SetConfig(sources[0], sources[1:]...)
	if err != nil {
		log.Fatal("Fail to load config: %v", err)
	}

	sec := Cfg.Section("")
	if sec.Key("RUN_MODE").String() == "prod" {
		ProdMode = true
		macaron.Env = macaron.PROD
		macaron.ColorLog = false
	}

	HTTPPort = sec.Key("HTTP_PORT").MustInt(5555)

	sec = Cfg.Section("site")
	Site.Name = sec.Key("NAME").MustString("Peach Server")
	Site.Desc = sec.Key("DESC").String()
	Site.UseCDN = sec.Key("USE_CDN").MustBool()
	Site.URL = sec.Key("URL").String()

	sec = Cfg.Section("page")
	Page.HasLandingPage = sec.Key("HAS_LANDING_PAGE").MustBool()
	Page.DocsBaseURL = sec.Key("DOCS_BASE_URL").Validate(func(in string) string {
		if len(in) == 0 {
			return "/docs"
		} else if in[0] != '/' {
			return "/" + in
		}
		return in
	})

	Page.UseCustomTpl = sec.Key("USE_CUSTOM_TPL").MustBool()
	Page.NavbarTplPath = "navbar.html"
	Page.HomeTplPath = "home.html"
	Page.DocsTplPath = "docs.html"
	Page.FooterTplPath = "footer.html"
	Page.DisqusTplPath = "disqus.html"

	sec = Cfg.Section("navbar")
	list := sec.KeyStrings()
	Navbar.Items = make([]*NavbarItem, len(list))
	for i, name := range list {
		secName := "navbar." + sec.Key(name).String()
		Navbar.Items[i] = &NavbarItem{
			Icon:   Cfg.Section(secName).Key("ICON").String(),
			Locale: Cfg.Section(secName).Key("LOCALE").MustString(secName),
			Link:   Cfg.Section(secName).Key("LINK").MustString("/"),
			Blank:  Cfg.Section(secName).Key("BLANK").MustBool(),
		}
	}

	sec = Cfg.Section("asset")
	Asset.CustomCSS = sec.Key("CUSTOM_CSS").String()

	sec = Cfg.Section("docs")
	Docs.Type = sec.Key("TYPE").In("local", []string{"local", "remote"})
	Docs.Target = sec.Key("TARGET").String()
	Docs.Secret = sec.Key("SECRET").String()
	Docs.Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
	Docs.Locales = make(map[string][]byte)
	for _, lang := range Docs.Langs {
		if lang != "en-US" && lang != "zh-CN" {
			Docs.Locales["locale_"+lang+".ini"] = []byte("")
		}
	}

	sec = Cfg.Section("extension")
	Extension.EnableDisqus = sec.Key("ENABLE_DISQUS").MustBool()
	Extension.DisqusShortName = sec.Key("DISQUS_SHORT_NAME").String()
	Extension.HighlightJSCustomCSS = sec.Key("HIGHLIGHTJS_CUSTOM_CSS").String()
	Extension.EnableSearch = sec.Key("ENABLE_SEARCH").MustBool()
	Extension.GABlock = sec.Key("GA_BLOCK").String()
}