本文整理汇总了Golang中github.com/kelseyhightower/envconfig.Process函数的典型用法代码示例。如果您正苦于以下问题:Golang Process函数的具体用法?Golang Process怎么用?Golang Process使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Process函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Load
// Load configuration settings from the environment, apply defaults, and validate them.
func (c *Context) Load() error {
if err := envconfig.Process("PIPE", &c.Settings); err != nil {
return err
}
if c.Port == 0 {
c.Port = 8000
}
if c.LogLevel == "" {
c.LogLevel = "info"
}
if c.MongoURL == "" {
c.MongoURL = "mongo"
}
if c.Poll == 0 {
c.Poll = 500
}
if c.DockerHost == "" {
if host := os.Getenv("DOCKER_HOST"); host != "" {
c.DockerHost = host
} else {
c.DockerHost = "unix:///var/run/docker.sock"
}
}
certRoot := os.Getenv("DOCKER_CERT_PATH")
if certRoot == "" {
certRoot = "/certificates"
}
if c.CACert == "" {
c.CACert = path.Join(certRoot, "ca.pem")
}
if c.Cert == "" {
c.Cert = path.Join(certRoot, "cloudpipe-cert.pem")
}
if c.Key == "" {
c.Key = path.Join(certRoot, "cloudpipe-key.pem")
}
if c.DefaultImage == "" {
c.DefaultImage = "cloudpipe/runner-py2"
}
if c.Settings.AuthService == "" {
c.Settings.AuthService = "https://authstore:9001/v1"
}
if _, err := log.ParseLevel(c.LogLevel); err != nil {
return err
}
return nil
}
开发者ID:nivertech,项目名称:cloudpipe,代码行数:61,代码来源:context.go
示例17: LoadBot
// LoadBot creates a new BotAPI instance using environmental variables.
// It also makes the maps needed for the bot to run, and loads admins.
func LoadBot() *tgbotapi.BotAPI {
var cfg Config
err := envconfig.Process("TELEGRAM", &cfg)
if err != nil {
log.Fatal(err)
}
tg, err := tgbotapi.NewBotAPI(cfg.APIToken)
if cfg.APIDebug {
tg.Debug = true
}
if err != nil {
log.Panic(err)
}
bot.Users = make(map[int]tgbotapi.User)
bot.Admins = make(map[int]bool)
for _, id := range strings.Split(cfg.Admins, ",") {
i, err := strconv.Atoi(id)
if err != nil {
log.Panic("Admin IDs must be numbers!")
}
bot.Admins[i] = true
}
return tg
}
开发者ID:rkakrik,项目名称:FoxBot,代码行数:31,代码来源:loader.go
示例18: GetConfig
// GetConfig uses envconfig to populate and return a Config struct. Returns all envconfig errors if they occurred
func GetConfig() (*Config, error) {
conf := new(Config)
if err := envconfig.Process(AppName, conf); err != nil {
return nil, err
}
return conf, nil
}
开发者ID:choirudin2210,项目名称:go-in-5-minutes,代码行数:8,代码来源:conf.go
示例19: main
// Main entry point that starts the messaging bridge, visit service, and web
// server.
func main() {
var s Specification
var port string
// Load environment variables.
if err := envconfig.Process("icra", &s); err != nil {
log.Fatalf("Could not read environment variables: %s", err.Error())
}
if port = os.Getenv("VCAP_APP_PORT"); len(port) == 0 {
log.Printf("Warning, VCAP_APP_PORT not set. Defaulting to %+v\n", s.Port)
port = s.Port
}
// Generate a client identifier.
id := fmt.Sprintf("icra-client-%d", os.Getpid())
// Configure the visit service and messaging bridge.
vs := NewVisitService(s.BufferSize, s.CacheSize)
mb := NewMessagingBridge([]string{s.Topic}, vs)
// Start the visit service.
go vs.Serve()
// Connect to the message broker.
mb.Connect(s.Broker, id)
// Configure the web server.
http.Handle("/ws/browsing", vs.MakeHandler())
http.Handle("/", http.FileServer(http.Dir("static")))
// Launch the web server.
http.ListenAndServe(":"+port, nil)
}
开发者ID:ClayMoreBoy,项目名称:icra,代码行数:37,代码来源:app.go
示例20: GetGit
// GetGit gets the Git config using envconfig
func GetGit(appName string) (*Git, error) {
conf := new(Git)
if err := envconfig.Process(appName, conf); err != nil {
return nil, err
}
return conf, nil
}
开发者ID:arschles,项目名称:goprox,代码行数:8,代码来源:git.go
注:本文中的github.com/kelseyhightower/envconfig.Process函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论