func setupMetadata(conf goss.ConfigProvider) error { metadataSource = conf.AsString("goss.metadata") if metadataSource == "" { return errors.New("goss requires configuration property goss.metadata is set.") } dbMetadata = new(DBMetadata) e := dbMetadata.RefreshOnDemand(metadataSource) fmt.Printf("metadata is %s\n", dbMetadata) return e }
// setupDB creates the database connection pool. This is shared across go-routines for all requests, // and the pool management is managed automatically by the sql package. func setupDB(config goss.ConfigProvider) error { // Get the properties we expect. driverName := config.AsString("goss.database.driverName") if driverName == "" { return errors.New("goss requires config property goss.database.driverName to be set.") } dataSourceName := config.AsString("goss.database.dataSourceName") if dataSourceName == "" { return errors.New("goss requires config property goss.database.dataSourceName to be set.") } maxIdleConnections := -1 // default is no idle connections mi := config.Get("goss.database.maxIdleConnections") mif, ok := mi.(float64) if ok { maxIdleConnections = int(mif) } else { return errors.New("goss expects config property goss.database.maxIdleConnections to be of type 'int'.") } // put back in once at go 1.2 maxOpenConnections := -1 // default is no limit on open connections mo := config.Get("goss.database.maxOpenConnections") mof, ok := mo.(float64) if ok { maxOpenConnections = int(mof) } else { return errors.New("goss expects config property goss.database.maxOpenConnections to be of type 'int'.") } var e error database, e = sql.Open(driverName, dataSourceName) if e != nil { return e } fmt.Printf("opened database %s: %s\n", driverName, dataSourceName) database.SetMaxIdleConns(maxIdleConnections) database.SetMaxOpenConns(maxOpenConnections) // requires go 1.2 // @todo hack alert, refactor driver-specific things. if driverName == "mysql" { _, e = database.Query("SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE;") _, e = database.Query("SET GLOBAL sql_mode = 'ANSI'") } return nil }
func setConfig(conf goss.ConfigProvider) error { i := conf.Get("goss.cache.menuTTL") ii, ok := i.(float64) if ok { configuration.cacheMenuTTL = int(ii) } else { return errors.New("goss expects config property goss.database.menuTTL to be of type 'int'.") } i = conf.Get("goss.cache.siteConfigTTL") ii, ok = i.(float64) if ok { configuration.cacheSiteConfigTTL = int(ii) } else { return errors.New("goss expects config property goss.database.siteConfigTTL to be of type 'int'.") } i = conf.Get("goss.cache.siteTreeTTL") ii, ok = i.(float64) if ok { configuration.cacheSiteTreeNavTTL = int(ii) } else { return errors.New("goss expects config property goss.database.siteTreeTTL to be of type 'int'.") } return nil }
// getConfig is invoked when configuration is provided by the application. We extract out of it what we want, // validate, and put the results in the config struct. func getConfig(c goss.ConfigProvider) error { fmt.Printf("template.getConfig got %s\n", c) base := c.AsString("goss.ssroot") fmt.Printf("base is %s\n", base) if base == "" { return errors.New("goss template rendering requires configuration property 'ssroot' is set") } if base[len(base)-1] != '/' { base += "/" } theme := c.AsString("goss.theme") if theme == "" { return errors.New("goss template rendering requires configuration property 'theme' is set") } siteUrl := c.AsString("goss.siteUrl") // optional defaultProtocol := c.AsString("goss.defaultProtocol") if defaultProtocol == "" { defaultProtocol = "http" } if defaultProtocol != "http" && defaultProtocol != "https" { return fmt.Errorf("goss only supports defaultProtocol of 'http' or 'https', and not '%s'", defaultProtocol) } configuration.initialised = true configuration.ssRoot = base configuration.themeName = theme configuration.siteUrl = siteUrl configuration.defaultProtocol = defaultProtocol configuration.templatesPath = configuration.ssRoot + "themes/" + configuration.themeName + "/templates/" configuration.cssURL = "themes/" + configuration.themeName + "/css/" configuration.layoutsPath = "Layout/" configuration.includesPath = "Includes/" return nil }