// Load mime-types.conf on init. func LoadMimeConfig() { var err error mimeConfig, err = config.LoadContext("mime-types.conf", ConfPaths) if err != nil { ERROR.Fatalln("Failed to load mime type config:", err) } }
// Init initializes Revel -- it provides paths for getting around the app. // // Params: // mode - the run mode, which determines which app.conf settings are used. // importPath - the Go import path of the application. // srcPath - the path to the source directory, containing Revel and the app. // If not specified (""), then a functioning Go installation is required. func Init(mode, importPath, srcPath string) { // Ignore trailing slashes. ImportPath = strings.TrimRight(importPath, "/") SourcePath = srcPath RunMode = mode if runtime.GOOS == "windows" { gocolorize.SetPlain(true) } // If the SourcePath is not specified, find it using build.Import. var revelSourcePath string // may be different from the app source path if SourcePath == "" { revelSourcePath, SourcePath = findSrcPaths(importPath) } else { // If the SourcePath was specified, assume both Revel and the app are within it. SourcePath = path.Clean(SourcePath) revelSourcePath = SourcePath packaged = true } RevelPath = filepath.Join(revelSourcePath, filepath.FromSlash(REVEL_IMPORT_PATH)) BasePath = filepath.Join(SourcePath, filepath.FromSlash(importPath)) AppPath = filepath.Join(BasePath, "app") ViewsPath = filepath.Join(AppPath, "views") CodePaths = []string{AppPath} if ConfPaths == nil { ConfPaths = []string{} } // Config load order // 1. framework (revel/conf/*) // 2. application (conf/*) // 3. user supplied configs (...) - User configs can override/add any from above ConfPaths = append( []string{ path.Join(RevelPath, "conf"), path.Join(BasePath, "conf"), }, ConfPaths...) TemplatePaths = []string{ ViewsPath, path.Join(RevelPath, "templates"), } // Load app.conf var err error Config, err = config.LoadContext("app.conf", ConfPaths) if err != nil || Config == nil { log.Fatalln("Failed to load app.conf:", err) } // Ensure that the selected runmode appears in app.conf. // If empty string is passed as the mode, treat it as "DEFAULT" if mode == "" { mode = config.DEFAULT_SECTION } if !Config.HasSection(mode) { log.Fatalln("app.conf: No mode found:", mode) } Config.SetSection(mode) // Configure properties from app.conf DevMode = Config.BoolDefault("mode.dev", false) HttpPort = Config.IntDefault("http.port", 9000) HttpAddr = Config.StringDefault("http.addr", "") HttpSsl = Config.BoolDefault("http.ssl", false) HttpSslCert = Config.StringDefault("http.sslcert", "") HttpSslKey = Config.StringDefault("http.sslkey", "") if HttpSsl { if HttpSslCert == "" { log.Fatalln("No http.sslcert provided.") } if HttpSslKey == "" { log.Fatalln("No http.sslkey provided.") } } AppName = Config.StringDefault("app.name", "(not set)") AppRoot = Config.StringDefault("app.root", "") CookiePrefix = Config.StringDefault("cookie.prefix", "REVEL") CookieDomain = Config.StringDefault("cookie.domain", "") CookieSecure = Config.BoolDefault("cookie.secure", !DevMode) TemplateDelims = Config.StringDefault("template.delimiters", "") if secretStr := Config.StringDefault("app.secret", ""); secretStr != "" { secretKey = []byte(secretStr) } // Configure logging if !Config.BoolDefault("log.colorize", true) { gocolorize.SetPlain(true) } TRACE = getLogger("trace") INFO = getLogger("info") WARN = getLogger("warn") ERROR = getLogger("error") // Revel request access logger, not exposed from package. // However output settings can be controlled from app.conf requestLog = getLogger("request") loadModules() Initialized = true INFO.Printf("Initialized Revel v%s (%s) for %s", Version, BuildDate, MinimumGoVersion) }