Exemple #1
0
// 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)
	}
}
func (engine *MixedEngine) templateEngineNameFrom(templateName, basePath string) (string, *Error) {
	basePath = filepath.ToSlash(filepath.Join(strings.TrimSuffix(basePath, "/app/views"), "conf"))

	// Load app.conf from basePath
	config, err := revConfig.LoadContext("app.conf", []string{basePath})
	if err != nil || config == nil {
		return "", &Error{
			Title:       "Panic (Template Loader)",
			Description: "Failed to load template(" + templateName + "): cann't load " + basePath + "/app.conf:" + err.Error(),
		}
	}

	// Ensure that the selected runmode appears in app.conf.
	// If empty string is passed as the mode, treat it as "DEFAULT"
	mode := RunMode
	if mode == "" {
		mode = robfigConfig.DEFAULT_SECTION
	}
	if !config.HasSection(mode) {
		return "", &Error{
			Title:       "Panic (Template Loader)",
			Description: "Failed to load template(" + templateName + "): cann't load " + basePath + "/app.conf: No mode found: " + mode,
		}
	}
	config.SetSection(mode)

	templateEngineName := config.StringDefault(REVEL_TEMPLATE_ENGINE, "")
	// preventing recursive load template engine.
	if MIXED_TEMPLATE == templateEngineName {
		templateEngineName = ""
	}
	return templateEngineName, nil
}
Exemple #3
0
func loadTestI18nConfig(t *testing.T) {
	ConfPaths = append(ConfPaths, testConfigPath)
	testConfig, err := config.LoadContext(testConfigName, ConfPaths)
	if err != nil {
		t.Fatalf("Unable to load test config '%s': %s", testConfigName, err.Error())
	}
	Config = testConfig
	CookiePrefix = Config.StringDefault("cookie.prefix", "REVEL")
}
Exemple #4
0
// 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 = path.Join(revelSourcePath, filepath.FromSlash(REVEL_IMPORT_PATH))
	BasePath = path.Join(SourcePath, filepath.FromSlash(importPath))
	AppPath = path.Join(BasePath, "app")
	ViewsPath = path.Join(AppPath, "views")

	CodePaths = []string{AppPath}

	if ConfPaths == nil {
		ConfPaths = []string{}
	}
	ConfPaths = append(
		ConfPaths,
		path.Join(BasePath, "conf"),
		path.Join(RevelPath, "conf"),
	)

	TemplatePaths = []string{
		ViewsPath,
	}

	// Load app.conf
	var err error
	Config, err = revConfig.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)

	if nil != ConfigHook {
		ConfigHook(Config)
	}

	// 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)
	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")

	if tmpl := Config.StringDefault(REVEL_TEMPLATE_ENGINE, GO_TEMPLATE); GO_TEMPLATE == tmpl || MIXED_TEMPLATE == tmpl {
		TemplatePaths = append(TemplatePaths, path.Join(RevelPath, "templates"))
	}

	loadModules()

	Initialized = true
	INFO.Printf("Initialized Revel v%s (%s) for %s", VERSION, BUILD_DATE, MINIMUM_GO)
}