Example #1
0
func prepareOptions(options []Options) Options {
	var opt Options
	if len(options) > 0 {
		opt = options[0]
	}

	if len(opt.Section) == 0 {
		opt.Section = "i18n"
	}
	sec := macaron.Config().Section(opt.Section)

	opt.SubURL = strings.TrimSuffix(opt.SubURL, "/")

	if len(opt.Langs) == 0 {
		opt.Langs = sec.Key("LANGS").Strings(",")
	}
	if len(opt.Names) == 0 {
		opt.Names = sec.Key("NAMES").Strings(",")
	}
	if len(opt.Langs) == 0 {
		panic("no language is specified")
	} else if len(opt.Langs) != len(opt.Names) {
		panic("length of langs is not same as length of names")
	}

	if len(opt.Directory) == 0 {
		opt.Directory = sec.Key("DIRECTORY").MustString("conf/locale")
	}
	if len(opt.CustomDirectory) == 0 {
		opt.CustomDirectory = sec.Key("CUSTOM_DIRECTORY").MustString("custom/conf/locale")
	}
	if len(opt.Format) == 0 {
		opt.Format = sec.Key("FORMAT").MustString("locale_%s.ini")
	}
	if len(opt.Parameter) == 0 {
		opt.Parameter = sec.Key("PARAMETER").MustString("lang")
	}
	if !opt.Redirect {
		opt.Redirect = sec.Key("REDIRECT").MustBool()
	}
	if len(opt.TmplName) == 0 {
		opt.TmplName = sec.Key("TMPL_NAME").MustString("i18n")
	}

	return opt
}
Example #2
0
func prepareOptions(options []Options) Options {
	var opt Options
	if len(options) > 0 {
		opt = options[0]
	}
	if len(opt.Section) == 0 {
		opt.Section = "session"
	}
	sec := macaron.Config().Section(opt.Section)

	if len(opt.Provider) == 0 {
		opt.Provider = sec.Key("PROVIDER").MustString("memory")
	}
	if len(opt.ProviderConfig) == 0 {
		opt.ProviderConfig = sec.Key("PROVIDER_CONFIG").MustString("data/sessions")
	}
	if len(opt.CookieName) == 0 {
		opt.CookieName = sec.Key("COOKIE_NAME").MustString("MacaronSession")
	}
	if len(opt.CookiePath) == 0 {
		opt.CookiePath = sec.Key("COOKIE_PATH").MustString("/")
	}
	if opt.Gclifetime == 0 {
		opt.Gclifetime = sec.Key("GC_INTERVAL_TIME").MustInt64(3600)
	}
	if opt.Maxlifetime == 0 {
		opt.Maxlifetime = sec.Key("MAX_LIFE_TIME").MustInt64(opt.Gclifetime)
	}
	if !opt.Secure {
		opt.Secure = sec.Key("SECURE").MustBool()
	}
	if opt.CookieLifeTime == 0 {
		opt.CookieLifeTime = sec.Key("COOKIE_LIFE_TIME").MustInt()
	}
	if len(opt.Domain) == 0 {
		opt.Domain = sec.Key("DOMAIN").String()
	}
	if opt.IDLength == 0 {
		opt.IDLength = sec.Key("ID_LENGTH").MustInt(16)
	}

	return opt
}
Example #3
0
func prepareOptions(options []Options) Options {
	var opt Options
	if len(options) > 0 {
		opt = options[0]
	}
	if len(opt.Section) == 0 {
		opt.Section = "cache"
	}
	sec := macaron.Config().Section(opt.Section)

	if len(opt.Adapter) == 0 {
		opt.Adapter = sec.Key("ADAPTER").MustString("memory")
	}
	if opt.Interval == 0 {
		opt.Interval = sec.Key("INTERVAL").MustInt(60)
	}
	if len(opt.AdapterConfig) == 0 {
		opt.AdapterConfig = sec.Key("ADAPTER_CONFIG").MustString("data/caches")
	}

	return opt
}