当前位置: 首页>>代码示例>>Golang>>正文


Golang envconfig.Process函数代码示例

本文整理汇总了Golang中github.com/kelseyhightower/envconfig.Process函数的典型用法代码示例。如果您正苦于以下问题:Golang Process函数的具体用法?Golang Process怎么用?Golang Process使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Process函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: loadConfiguration

// loadConfiguration loads the configuration of application
func loadConfiguration(app *AppConfig, rdis *RedisConfig, nats *NatsConfig) {
	err := envconfig.Process(ServiceName, app)
	if err != nil {
		log.Panicln(err)
	}
	err = envconfig.Process("redis", rdis)
	if err != nil {
		log.Panicln(err)
	}
	err = envconfig.Process("nats", nats)
	if err != nil {
		log.Panicln(err)
	}
	if len(os.Getenv(KeyLogly)) > 0 {
		log.Printf("Loading logly token %s \n", os.Getenv(KeyLogly))
		hook := logrusly.NewLogglyHook(os.Getenv(KeyLogly),
			app.Host,
			log.InfoLevel,
			app.Name)
		log.AddHook(hook)
	}

	log.Println("#### LOADED CONFIG #####")
	log.Printf("REDIS_URI: %s \n", rdis.URI)
	log.Printf("NATS_ENDPOINT: %s \n", nats.Endpoint)
}
开发者ID:suricatatalk,项目名称:gate,代码行数:27,代码来源:gate.go

示例2: loadConfig

// LoadConfig will load the configuration file from filePath, if it can't open
// the file for reading, it assumes there is no configuration file and will try to create
// one on the default path (tyk.conf in the local directory)
func loadConfig(filePath string, configStruct *Config) {
	configuration, err := ioutil.ReadFile(filePath)
	if err != nil {
		log.Error("Couldn't load configuration file")
		log.Error(err)
		log.Info("Writing a default file to ./tyk.conf")

		WriteDefaultConf(configStruct)

		log.Info("Loading default configuration...")
		loadConfig("tyk.conf", configStruct)
	} else {
		if err := json.Unmarshal(configuration, &configStruct); err != nil {
			log.Error("Couldn't unmarshal configuration")
			log.Error(err)
		}

		overrideErr := envconfig.Process(ENV_PREVIX, configStruct)
		if overrideErr != nil {
			log.Error("Failed to process environment variables after file load: ", overrideErr)
		}
	}

	if configStruct.SlaveOptions.CallTimeout == 0 {
		configStruct.SlaveOptions.CallTimeout = 30
	}
	if configStruct.SlaveOptions.PingTimeout == 0 {
		configStruct.SlaveOptions.PingTimeout = 60
	}
	GlobalRPCPingTimeout = time.Second * time.Duration(configStruct.SlaveOptions.PingTimeout)
	GlobalRPCCallTimeout = time.Second * time.Duration(configStruct.SlaveOptions.CallTimeout)
	configStruct.EventTriggers = InitGenericEventHandlers(configStruct.EventHandlers)
}
开发者ID:TykTechnologies,项目名称:tyk,代码行数:36,代码来源:config_utils.go

示例3: WriteDefaultConf

// WriteDefaultConf will create a default configuration file and set the storage type to "memory"
func WriteDefaultConf(configStruct *Config) {
	configStruct.ListenAddress = ""
	configStruct.ListenPort = 8080
	configStruct.Secret = "352d20ee67be67f6340b4c0605b044b7"
	configStruct.TemplatePath = "./templates"
	configStruct.TykJSPath = "./js/tyk.js"
	configStruct.MiddlewarePath = "./middleware"
	configStruct.Storage.Type = "redis"
	configStruct.AppPath = "./apps/"
	configStruct.Storage.Host = "localhost"
	configStruct.Storage.Username = ""
	configStruct.Storage.Password = ""
	configStruct.Storage.Database = 0
	configStruct.Storage.MaxIdle = 100
	configStruct.Storage.Port = 6379
	configStruct.EnableAnalytics = false
	configStruct.HealthCheck.EnableHealthChecks = true
	configStruct.HealthCheck.HealthCheckValueTimeout = 60
	configStruct.AnalyticsConfig.IgnoredIPs = make([]string, 0)
	configStruct.UseAsyncSessionWrite = false
	configStruct.HideGeneratorHeader = false
	configStruct.OauthRedirectUriSeparator = ""
	newConfig, err := json.MarshalIndent(configStruct, "", "    ")
	overrideErr := envconfig.Process(ENV_PREVIX, &configStruct)
	if overrideErr != nil {
		log.Error("Failed to process environment variables: ", overrideErr)
	}
	if err != nil {
		log.Error("Problem marshalling default configuration!")
		log.Error(err)
	} else {
		ioutil.WriteFile("tyk.conf", newConfig, 0644)
	}
}
开发者ID:TykTechnologies,项目名称:tyk,代码行数:35,代码来源:config_utils.go

示例4: readEnvironmentVariables

//environment variables must be in following format
//SETTINGS_URL_CHANNEL_API
//SETTINGS_QUEUE_HOST
func (settings *envSettings) readEnvironmentVariables() error {
	err := envconfig.Process("settings", settings)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:jmptrader,项目名称:shellscript-executor,代码行数:10,代码来源:env-variables.go

示例5: init

func init() {
	// Pull in the configuration
	err := envconfig.Process("buoy", &Config)
	if err != nil {
		tracelog.COMPLETED_ERROR(err, helper.MAIN_GO_ROUTINE, "Init")
	}
}
开发者ID:pmljm,项目名称:beego-mgo,代码行数:7,代码来源:buoyService.go

示例6: NewApp

func NewApp(name string) (AppCtx, error) {
	specs := Specs{}
	err := envconfig.Process(name, &specs)
	if err != nil {
		return AppCtx{}, err
	}

	url := fmt.Sprintf("%v:%[email protected](%v:%v)/%v",
		specs.DBUser,
		specs.DBPass,
		specs.DBHost,
		specs.DBPort,
		specs.DBName,
	)

	db, err := sql.Open("mysql", url)
	if err != nil {
		return AppCtx{}, err
	}

	ctx := AppCtx{
		Specs: specs,
		DB:    db,
	}

	return ctx, nil
}
开发者ID:tochti,项目名称:sj,代码行数:27,代码来源:utils.go

示例7: LoadConfig

func LoadConfig() (*Config, error) {
	var config Config

	err := envconfig.Process(configPrefix, &config)

	if err != nil {
		return nil, errors.Wrap(err, "Failed to load config from envs.")
	}

	if _, err := os.Stat(configFilePath); err != nil {
		return &config, nil
	}

	configFromFile, err := loadConfigFromFile(configFilePath)

	if err != nil {
		return nil, err
	}

	for _, configName := range configNames {
		if configName == "MaxAppDeploy" {
			n, err := strconv.ParseInt(configFromFile[configName], 10, 64)

			if err != nil {
				return nil, errors.Wrapf(err, "Failed to parse %s as integer. value: %s", configName, configFromFile[configName])
			}

			reflect.ValueOf(&config).Elem().FieldByName(configName).SetInt(n)
		} else {
			reflect.ValueOf(&config).Elem().FieldByName(configName).SetString(configFromFile[configName])
		}
	}

	return &config, nil
}
开发者ID:dtan4,项目名称:paus-gitreceive,代码行数:35,代码来源:config.go

示例8: configure

func configure() {
	err := envconfig.Process(appName, &config)
	if err != nil {
		log.Println("Errof: %v\n", err.Error())
	}

	log.Println("Initial generation of static files...")
	generateStaticFiles()

	log.Println("Initializing image watchdog...")
	watcher, err = fsnotify.NewWatcher()
	if err != nil {
		log.Printf("Error: %v\n", err.Error())
	}

	err = watcher.Watch("src/assets/photos")
	if err != nil {
		log.Printf("Error: %v\n", err.Error())
	}

	go func() {
		for {
			select {
			case ev := <-watcher.Event:
				if ev.IsCreate() {
					log.Println("Regenerating static files...")
					generateStaticFiles()
				}
			}
		}
	}()

	log.Println("Configuration complete...")
}
开发者ID:dan9186,项目名称:gobaby,代码行数:34,代码来源:main.go

示例9: Host

func (pureInfoService) Host() (server.HostResponse, error) {
	var errResp string
	var hostSpec HostSpec

	err := envconfig.Process("infosvc", &hostSpec)
	if err != nil {
		errResp = err.Error()
	}

	var ips []string

	addrs, _ := net.InterfaceAddrs()
	for _, addr := range addrs {
		if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
			if ipnet.IP.To4() != nil {
				ips = append(ips, ipnet.IP.String())
			}
		}
	}

	myHostName, err := os.Hostname()
	if err != nil {
		errResp = err.Error()
	}

	var myOS = fmt.Sprintf("%s %s", hostSpec.OS, hostSpec.Arch)
	return server.HostResponse{Name: myHostName, OS: myOS, Addrs: ips, Err: errResp}, nil
}
开发者ID:pinterb,项目名称:infosvc,代码行数:28,代码来源:service.go

示例10: Startup

// Startup brings the manager to a running state.
func Startup(sessionID string) error {
	// If the system has already been started ignore the call.
	if singleton.sessions != nil {
		return nil
	}

	log.Started(sessionID, "Startup")

	// Pull in the configuration.
	var config mongoConfiguration
	if err := envconfig.Process("mgo", &config); err != nil {
		log.CompletedError(err, sessionID, "Startup")
		return err
	}

	// Create the Mongo Manager.
	singleton = mongoManager{
		sessions: make(map[string]mongoSession),
	}

	// Create the strong session.
	if err := CreateSession(sessionID, "strong", MasterSession, config.Url); err != nil {
		log.CompletedError(err, sessionID, "Startup")
		return err
	}

	// Create the monotonic session.
	if err := CreateSession(sessionID, "monotonic", MonotonicSession, config.Url); err != nil {
		log.CompletedError(err, sessionID, "Startup")
		return err
	}

	log.Completed(sessionID, "Startup")
	return nil
}
开发者ID:liuhong1happy,项目名称:ConsoleWindowApp,代码行数:36,代码来源:mongo.go

示例11: main

func main() {
	log = log15.New()
	log.Info("starting server...")

	envconfig.Process("", &settings)

	schema, err := graphql.NewSchema(makeSchema())
	if err != nil {
		log.Info("error creating schema", "err", err)
		return
	}

	h := handler.New(&handler.Config{
		Schema: &schema,
		Pretty: false,
	})

	mux := http.NewServeMux()
	mux.Handle("/graphql", h)
	mux.Handle("/", http.FileServer(http.Dir("dist")))

	log.Info("Listening at " + settings.Port + "...")
	graceful.Run(":"+settings.Port, 1*time.Second, mux)
	log.Info("Exiting...")
}
开发者ID:Xcopyco,项目名称:stack-forum,代码行数:25,代码来源:web.go

示例12: init

func init() {
	var c Config

	envconfig.Process("proxym_mesos_master", &c)

	if c.Enabled {
		err := sanitizeConfig(&c)
		if err != nil {
			log.ErrorLog.Critical("Not initializing module Mesos Master: '%s'", err)
			return
		}

		lr := &leaderRegistry{
			mutex: &sync.Mutex{},
		}

		n, err := NewMesosNotifier(&c, lr)
		if err != nil {
			log.ErrorLog.Fatal(err)
		}
		manager.AddNotifier(n)

		sg := &MesosMasterServiceGenerator{
			config:         &c,
			leaderRegistry: lr,
		}
		manager.AddServiceGenerator(sg)
	}
}
开发者ID:nickwales,项目名称:proxym,代码行数:29,代码来源:mesos_master.go

示例13: Get

func Get() (*Config, error) {
	var ret Config
	if err := envconfig.Process(AppName, &ret); err != nil {
		return nil, err
	}
	return &ret, nil
}
开发者ID:bacongobbler,项目名称:riak,代码行数:7,代码来源:config.go

示例14: InitContex

// InitContex initializes the app context
func InitContex() *Context {
	if _context != nil {
		panic("Context already exists")
	}

	_context = new(Context)

	if err := envconfig.Process("api", &_context.Params); err != nil {
		panic(err)
	}

	// Setup database
	session, err := mgo.Dial(_context.Params.MongoURI)
	if err != nil {
		fmt.Println("Cannot start mongo")
		panic(err)
	}
	_context.Session = session
	_context.Session.SetMode(mgo.Monotonic, true)
	_context.DB = session.DB("")

	// LogEntries
	if _context.Params.LogEntriesToken != "" {
		_context.LogEntries, err = le_go.Connect(_context.Params.LogEntriesToken)
		if err != nil {
			panic(err)
		}
	}

	return _context
}
开发者ID:Nivl,项目名称:api.melvin.la,代码行数:32,代码来源:app.go

示例15: Read

// Read the configuration from the environment
// Defaults will be set for unset fields
func (config *Configuration) Read() error {
	err := envconfig.Process("", config)
	if err != nil {
		log.Fatal("Failed to load configuration, error is - " + err.Error())
		return err
	}

	if config.DownloadListFile == "" {
		config.DownloadListFile = "./list.json"
	}
	if config.WWWRoot == "" {
		config.WWWRoot = "/www"
	}
	if config.Port == 0 {
		config.Port = 80
	}
	if config.MaximumNumberRetry == 0 {
		config.MaximumNumberRetry = 3
	}
	if config.MaximumParallelDownloads == 0 {
		config.MaximumParallelDownloads = 5
	}

	log.Printf("Staging UI configuration: %+v", config)
	return nil
}
开发者ID:li0ji02,项目名称:staging-ui,代码行数:28,代码来源:configuration.go


注:本文中的github.com/kelseyhightower/envconfig.Process函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。