func (self *Configuration) Init() error { if self.initialized { panic("view.Config already initialized") } if !self.IsProductionServer { addrs, err := net.InterfaceAddrs() if err != nil { return err } for _, addr := range addrs { if ipNet, ok := addr.(*net.IPNet); ok { ip := ipNet.IP.String() for _, prodIP := range Config.ProductionServerIPs { if ip == prodIP { self.IsProductionServer = true break } } } } } if !self.IsProductionServer { self.Debug.Mode = true } // Check if dirs exists and make them absolute for i := range Config.BaseDirs { dir, err := filepath.Abs(os.ExpandEnv(Config.BaseDirs[i])) if err != nil { return err } if !utils.DirExists(dir) { return errs.Format("BaseDir does not exist: %s", dir) } Config.BaseDirs[i] = dir fmt.Println("BaseDir:", dir) } for i := range Config.StaticDirs { Config.StaticDirs[i] = os.ExpandEnv(Config.StaticDirs[i]) fmt.Println("StaticDir:", Config.StaticDirs[i]) } for i := range Config.TemplateDirs { Config.TemplateDirs[i] = os.ExpandEnv(Config.TemplateDirs[i]) fmt.Println("TemplateDir:", Config.TemplateDirs[i]) } self.initialized = true return nil }
// Init updates Config with the site-name, cookie secret and base directories used for static and template file search. // For every directory of baseDirs, Config.StaticDirs are appended to create search paths for static files // and Config.TemplateDirs are appended to search for template files. func Init(siteName, cookieSecret string, baseDirs ...string) (err error) { Config.SiteName = siteName Config.CookieSecret = cookieSecret if len(baseDirs) > 0 { for i, dir := range baseDirs { dir, err = filepath.Abs(dir) if err != nil { return err } if !utils.DirExists(dir) { return errs.Format("BaseDir does not exist: %s", dir) } baseDirs[i] = dir } Config.BaseDirs = baseDirs } return nil }