func LoadRepoConfig() { // Load .gitignore and license files. types := []string{"gitignore", "license"} typeFiles := make([][]string, 2) for i, t := range types { files, err := bindata.AssetDir("conf/" + t) if err != nil { log.Fatal(4, "Fail to get %s files: %v", t, err) } customPath := path.Join(setting.CustomPath, "conf", t) if com.IsDir(customPath) { customFiles, err := com.StatDir(customPath) if err != nil { log.Fatal(4, "Fail to get custom %s files: %v", t, err) } for _, f := range customFiles { if !com.IsSliceContainsStr(files, f) { files = append(files, f) } } } typeFiles[i] = files } Gitignores = typeFiles[0] Licenses = typeFiles[1] sort.Strings(Gitignores) sort.Strings(Licenses) }
// newMacaron initializes Macaron instance. func newMacaron() *macaron.Macaron { m := macaron.New() m.Use(macaron.Logger()) m.Use(macaron.Recovery()) if setting.EnableGzip { m.Use(macaron.Gziper()) } if setting.Protocol == setting.FCGI { m.SetURLPrefix(setting.AppSubUrl) } m.Use(macaron.Static( path.Join(setting.StaticRootPath, "public"), macaron.StaticOptions{ SkipLogging: !setting.DisableRouterLog, }, )) m.Use(macaron.Static( setting.AvatarUploadPath, macaron.StaticOptions{ Prefix: "avatars", SkipLogging: !setting.DisableRouterLog, }, )) m.Use(macaron.Renderer(macaron.RenderOptions{ Directory: path.Join(setting.StaticRootPath, "templates"), Funcs: []template.FuncMap{base.TemplateFuncs}, IndentJSON: macaron.Env != macaron.PROD, })) localeNames, err := bindata.AssetDir("conf/locale") if err != nil { log.Fatal(4, "Fail to list locale files: %v", err) } localFiles := make(map[string][]byte) for _, name := range localeNames { localFiles[name] = bindata.MustAsset("conf/locale/" + name) } m.Use(i18n.I18n(i18n.Options{ SubURL: setting.AppSubUrl, Files: localFiles, CustomDirectory: path.Join(setting.CustomPath, "conf/locale"), Langs: setting.Langs, Names: setting.Names, Redirect: true, })) m.Use(cache.Cacher(cache.Options{ Adapter: setting.CacheAdapter, AdapterConfig: setting.CacheConn, Interval: setting.CacheInternal, })) m.Use(captcha.Captchaer(captcha.Options{ SubURL: setting.AppSubUrl, })) m.Use(session.Sessioner(setting.SessionConfig)) m.Use(csrf.Csrfer(csrf.Options{ Secret: setting.SecretKey, SetCookie: true, Header: "X-Csrf-Token", CookiePath: setting.AppSubUrl, })) m.Use(toolbox.Toolboxer(m, toolbox.Options{ HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{ &toolbox.HealthCheckFuncDesc{ Desc: "Database connection", Func: models.Ping, }, }, })) // OAuth 2. if setting.OauthService != nil { for _, info := range setting.OauthService.OauthInfos { m.Use(oauth2.NewOAuth2Provider(info.Options, info.AuthUrl, info.TokenUrl)) } } m.Use(middleware.Contexter()) return m }
// newMacaron initializes Macaron instance. func newMacaron() *macaron.Macaron { m := macaron.New() if !setting.DisableRouterLog { m.Use(macaron.Logger()) } m.Use(macaron.Recovery()) if setting.EnableGzip { m.Use(gzip.Gziper()) } if setting.Protocol == setting.FCGI { m.SetURLPrefix(setting.AppSubUrl) } m.Use(macaron.Static( path.Join(setting.StaticRootPath, "public"), macaron.StaticOptions{ SkipLogging: setting.DisableRouterLog, }, )) m.Use(macaron.Static( setting.AvatarUploadPath, macaron.StaticOptions{ Prefix: "avatars", SkipLogging: setting.DisableRouterLog, }, )) funcMap := template.NewFuncMap() m.Use(macaron.Renderer(macaron.RenderOptions{ Directory: path.Join(setting.StaticRootPath, "templates"), AppendDirectories: []string{path.Join(setting.CustomPath, "templates")}, Funcs: funcMap, IndentJSON: macaron.Env != macaron.PROD, })) models.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"), path.Join(setting.CustomPath, "templates/mail"), funcMap) localeNames, err := bindata.AssetDir("conf/locale") if err != nil { log.Fatal(4, "Fail to list locale files: %v", err) } localFiles := make(map[string][]byte) for _, name := range localeNames { localFiles[name] = bindata.MustAsset("conf/locale/" + name) } m.Use(i18n.I18n(i18n.Options{ SubURL: setting.AppSubUrl, Files: localFiles, CustomDirectory: path.Join(setting.CustomPath, "conf/locale"), Langs: setting.Langs, Names: setting.Names, DefaultLang: "en-US", Redirect: true, })) m.Use(cache.Cacher(cache.Options{ Adapter: setting.CacheAdapter, AdapterConfig: setting.CacheConn, Interval: setting.CacheInterval, })) m.Use(captcha.Captchaer(captcha.Options{ SubURL: setting.AppSubUrl, })) m.Use(session.Sessioner(setting.SessionConfig)) m.Use(csrf.Csrfer(csrf.Options{ Secret: setting.SecretKey, Cookie: setting.CSRFCookieName, SetCookie: true, Header: "X-Csrf-Token", CookiePath: setting.AppSubUrl, })) m.Use(toolbox.Toolboxer(m, toolbox.Options{ HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{ &toolbox.HealthCheckFuncDesc{ Desc: "Database connection", Func: models.Ping, }, }, })) m.Use(context.Contexter()) return m }