• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang godotenv.Load函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: init

// init is responsible for initializing the entire configuration environment.
// In development, this means loading in and environment variables from both
// .env.default and .env. The .env.default file is commited into source control
// to provide sane defaults without sharing any secrets, whereas .env is ignored
// and should be used to store local development secrets, such as API keys for
// any services required to run.
func init() {
	_ = godotenv.Load(".env")
	_ = godotenv.Load(".env.default")
	baseDir := os.Getenv("BASE_DIR")
	if baseDir != "" {
		_ = godotenv.Load(baseDir + ".env")
		_ = godotenv.Load(baseDir + ".env.default")
	}

	initSneakerSecrets()
}
开发者ID:snikch,项目名称:api,代码行数:17,代码来源:config.go


示例2: main

func main() {

	// Load the environment variables we need
	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
	}

	// Read the port
	port := os.Getenv("PORT")

	tlsConfig, err := getTLSConfig(os.Getenv("SWARM_CREDS_DIR"))
	if err != nil {
		log.Fatal("Could not create TLS certificate.")
	}

	docker, _ := dockerclient.NewDockerClient(os.Getenv("DOCKER_HOST"), tlsConfig)

	mux := mux.NewRouter()
	// mux.HandleFunc("/events", get_events(dbmap)).Methods("GET")
	// mux.HandleFunc("/events/{year}", get_events_by_year(dbmap)).Methods("GET")
	mux.HandleFunc("/spawn", spawn(docker)).Methods("GET")
	mux.HandleFunc("/list-containers", list_containers(docker)).Methods("GET")
	n := negroni.Classic()
	n.UseHandler(mux)
	log.Printf("Listening on port %s\n", port)
	n.Run(":" + port)

}
开发者ID:odewahn,项目名称:thebe-server,代码行数:29,代码来源:main.go


示例3: run

func run(c *cli.Context) error {
	if c.String("env-file") != "" {
		_ = godotenv.Load(c.String("env-file"))
	}

	plugin := Plugin{
		Repo: Repo{
			Owner: c.String("repo.owner"),
			Name:  c.String("repo.name"),
		},
		Build: Build{
			Event: c.String("build.event"),
		},
		Commit: Commit{
			Ref: c.String("commit.ref"),
		},
		Config: Config{
			APIKey:     c.String("api-key"),
			Files:      c.StringSlice("files"),
			FileExists: c.String("file-exists"),
			Checksum:   c.StringSlice("checksum"),
			Draft:      c.Bool("draft"),
			BaseURL:    c.String("base-url"),
			UploadURL:  c.String("upload-url"),
		},
	}

	return plugin.Exec()
}
开发者ID:drone-plugins,项目名称:drone-github-release,代码行数:29,代码来源:main.go


示例4: main

func main() {
	// load up our ENV here. TODO Pass in file names for prod/test
	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file. You can't run the app without one!")
	}

	//config.DBHosts = os.Getenv("DATABASE_URL")
	config.DBName = os.Getenv("DATABASE_NAME")
	config.DBUser = os.Getenv("DATABASE_USER")
	//config.DBPassword = os.Getenv("DATABASE_PASSWORD")

	// Starts the app from config package struct. Returns Negroni (the
	// server), Router, Render and Database session
	app := config.StartApp()

	// Make database session available to config package
	//config.Session = app.Session

	// Keep our session open until we're done.
	defer app.DB.Close()

	// Register models here. Calling the Register() function passes our app
	// struct into our model to access the Router and register handlers
	pages.Register(app)
	users.Register(app)

	// start the server on 4567
	port := os.Getenv("PORT")

	// TODO pass in port based on ENV.
	app.Negroni.Run(":" + port)
}
开发者ID:ralphking,项目名称:goboiler,代码行数:33,代码来源:main.go


示例5: init

func init() {
	godotenv.Load()
	redisClient = storage.RedisClient(os.Getenv("REDIS_ADDR"), os.Getenv("REDIS_PASS"))
	translator = t.NewTranslateAdapter(
		[]backend_full.IBackendFull{
			backend_full.NewGoogleTranslator(httpclient.GetHttpClient(), os.Getenv("G_TR_KEY")),
			backend_full.NewYandexTranslator(httpclient.GetHttpClient(), os.Getenv("Y_TR_KEY")),
			//			backend_full.NewBingTranslator(os.Getenv("B_TR_KEY")),
		},
		components.NewChain(2),
	)
	//translator.AddParticular(&particular.AbbyyLingvoLiveTranslator{})
	if "" == os.Getenv("APP_SECRET") {
		os.Setenv("APP_SECRET", string(securecookie.GenerateRandomKey(32)))
	}
	cookieStore = &sessions.CookieStore{
		Codecs: securecookie.CodecsFromPairs([]byte(os.Getenv("APP_SECRET"))),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: 86400 * 30 * 10,
			//			Secure:true,
			HttpOnly: true,
		},
	}
}
开发者ID:unitrans,项目名称:unitrans,代码行数:25,代码来源:main.go


示例6: GetDBSession

func GetDBSession() *mgo.Session {

	//	if session == nil {
	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
	}

	if session != nil {
		fmt.Printf("DB: reusing same session")
		return session
	}

	session, err = mgo.Dial("localhost:27017")

	if err != nil {
		log.Fatal("Error Connecting Mongo")
	}

	session.SetMode(mgo.Monotonic, true)

	fmt.Printf("DB: creating new db session")

	return session
}
开发者ID:naikparag,项目名称:lego,代码行数:25,代码来源:db.go


示例7: main

func main() {
	logger := log.NewLogfmtLogger(os.Stderr)
	logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC)

	err := godotenv.Load()
	if err != nil {
		logger.Log("level", "fatal", "err", err)
	}

	config := &Config{
		Addr: os.Getenv("ADDR"),
		DSN:  os.Getenv("DSN"),
	}

	db, err := gorm.Open("postgres", config.DSN)
	if err != nil {
		panic(err)
	}

	app := cli.NewApp()

	app.Commands = []cli.Command{{
		Name:   "serve",
		Action: serve(logger, config, db),
	}}

	if err := app.Run(os.Args); err != nil {
		logger.Log("level", "fatal", "err", err)
	}

}
开发者ID:MetalMatze,项目名称:Krautreporter-API,代码行数:31,代码来源:api.go


示例8: InitServer

func InitServer() *martini.ClassicMartini {
	envFileName := martini.Env + ".env"
	err := godotenv.Load(envFileName)
	if err != nil {
		log.Fatalf("Error loading: %s", envFileName)
	}

	m := martini.Classic()
	m.Map(db.Connect())

	m.Use(render.Renderer(render.Options{
		Layout: "layout",
	}))

	m.Get("/", func(r render.Render) {
		r.HTML(200, "home", "")
	})
	m.Get("/api/projects", controllers.ProjectIndex)
	m.Get("/api/projects/new", controllers.ProjectNew)
	m.Get("/api/projects/:id", controllers.ProjectGet)
	m.Post("/api/projects", binding.Bind(models.Project{}), controllers.ProjectCreate)
	m.Put("/api/projects/:id", binding.Bind(models.Project{}), controllers.ProjectUpdate)
	m.Delete("/api/projects/:id", controllers.ProjectDelete)

	return m
}
开发者ID:jerryclinesmith,项目名称:notabbble,代码行数:26,代码来源:server.go


示例9: main

func main() {
	log.Println("Starting sqs processor")

	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
	}

	c.AWSAccess = os.Getenv("AWS_ACCESS")
	c.AWSSecret = os.Getenv("AWS_SECRET")
	done := make(chan bool)
	messageQueue := make(chan *sqs.Message)

	//notification queue
	s, err := sqs.NewFrom(c.AWSAccess, c.AWSSecret, "us-east-1")
	if err != nil {
		log.Panic(err)
	}
	q, err := s.GetQueue("spotify-ofp-notification")
	if err != nil {
		log.Panic(err)
	}

	go listenOnQueue("spotify-ofp", messageQueue)
	go processQueue(messageQueue)
	go polling(q)
	<-done
}
开发者ID:fun-alex-alex2006hw,项目名称:teamOFP,代码行数:28,代码来源:gobetween.go


示例10: LoadEnvironment

func LoadEnvironment(env string) (err error) {
	if !isValidEnvironment(env) {
		return fmt.Errorf("'%s' is not one of the supported enviroments: %v", env, strings.Join(Environments, ","))
	}
	Env = env

	// Load environment variables
	envFileName := Env + ".env"
	if err = godotenv.Load(envFileName); err != nil {
		return
	}

	// Connect to database
	if err = connectDB(); err != nil {
		return
	}

	// Initialize render
	Render = render.New(render.Options{
		Directory:     "templates",
		Layout:        "",
		Delims:        render.Delims{Left: "{{%", Right: "%}}"},
		Extensions:    []string{".tmpl", ".html"},
		IsDevelopment: Env == EnvDevelopment,
	})

	return
}
开发者ID:jerryclinesmith,项目名称:whosaidthat,代码行数:28,代码来源:global.go


示例11: run

func run(c *cli.Context) error {
	if c.String("env-file") != "" {
		_ = godotenv.Load(c.String("env-file"))
	}

	plugin := Plugin{
		Repo: Repo{
			Owner: c.String("repo.owner"),
			Name:  c.String("repo.name"),
		},
		Commit: Commit{
			Sha:    c.String("commit.sha"),
			Ref:    c.String("commit.ref"),
			Branch: c.String("commit.branch"),
			Author: c.String("commit.author"),
			Link:   c.String("commit.link"),
		},
		Build: Build{
			Number: c.Int("build.number"),
			Event:  c.String("build.event"),
			Status: c.String("build.status"),
			Deploy: c.String("build.deploy"),
			Link:   c.String("build.link"),
		},
		Config: Config{
			Webhook: c.StringSlice("webhook"),
		},
	}

	return plugin.Exec()
}
开发者ID:drone-plugins,项目名称:drone-gitter,代码行数:31,代码来源:main.go


示例12: main

func main() {
	if martini.Env != "production" {
		err := godotenv.Load()
		if err != nil {
			log.Fatal(err)
		}
	}

	mondoApiUri := os.Getenv("MONDO_API_URI")
	mondoAccessToken := os.Getenv("MONDO_ACCESS_TOKEN")
	addr := os.Getenv("ATTACHMENT_PUBLISHER_ADDR")
	vendors := os.Getenv("ATTACHMENT_PUBLISHER_VENDORS")
	if vendors == "" {
		log.Fatalf("no vendors configured!")
	}
	controllers.Vendors = strings.Split(vendors, ",")

	m := martini.Classic()
	mondoApiClient := &mondo.MondoApiClient{Url: mondoApiUri, AccessToken: mondoAccessToken}
	m.Map(matcher)
	m.Map(mondoApiClient)
	m.Post("/webhooks/mondo/transaction", controllers.PostMondoWebhook)
	m.Post("/webhooks/email", controllers.PostEmailWebhook)
	m.Get("/", func() string {
		return "Hello Mondo crowd!"
	})

	m.RunOnAddr(addr)
}
开发者ID:rdingwall,项目名称:hackathon-attachment-publisher,代码行数:29,代码来源:main.go


示例13: GetDBSession

func GetDBSession() *mgo.Session {

	//	if session == nil {
	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
	}

	if session != nil {
		fmt.Printf("DB: reusing same session")
		return Session
	}

	session, err = mgo.Dial(os.Getenv("MONGO_URL"))

	if err != nil {
		panic(err)
	}

	session.SetMode(mgo.Monotonic, true)

	fmt.Printf("DB: creating new db session")

	return session.Clone()
}
开发者ID:zannet,项目名称:lego,代码行数:25,代码来源:db.go


示例14: init

func init() {
	godotenv.Load("../.env")
	stathat = &Stathat{
		StatName: os.Getenv("STATHAT_STAT_NAME"),
		Ezkey:    os.Getenv("STATHAT_EZKEY"),
	}
}
开发者ID:jingweno,项目名称:travisarchive,代码行数:7,代码来源:main.go


示例15: main

func main() {
	err := godotenv.Load()
	if err != nil {
		log.Fatalln("Error loading .env file")
		os.Exit(-1)
	}

	if len(os.Args) < 2 {
		log.Fatalln(usage())
		os.Exit(-1)
	}

	os.Getenv("NEIGHBORS")

	m := mux.Mux{
		Handlers: Handlers,
	}

	Port := os.Args[1]

	s := server.New(
		Type,
		Host,
		Port,
		m,
		Protocol,
		Logger,
	)

	s.Serve()
}
开发者ID:domarps,项目名称:dLog,代码行数:31,代码来源:dgrep_server.go


示例16: main

func main() {
	if godotenv.Load() != nil {
		log.Fatal("Can't load .env file")
	}

	client, err := docker.NewClientFromEnv()
	if err != nil {
		log.Fatal("Err: %v", err)
	}

	dockerHost := os.Getenv("COURIER_DOCKER_HOST")
	if dockerHost == "" {
		dockerHost = "localhost"
	}

	proxy := &Proxy{
		Transport:    http.DefaultTransport,
		DockerHost:   dockerHost,
		DockerClient: client,
	}

	port := os.Getenv("COURIER_PORT")
	if port == "" {
		port = "8080"
	}

	log.Printf("Listen %s", port)
	runtime.GOMAXPROCS(runtime.NumCPU())
	http.ListenAndServe(":"+port, proxy)
}
开发者ID:corrupt952,项目名称:courier,代码行数:30,代码来源:courier.go


示例17: main

func main() {
	watchDir, targetDir := "tmp/source", "tmp/target"

	godotenv.Load(".env")

	fm, err := fm.NewFM("mms_prod")
	if err != nil {
		panic(err)
	}
	defer fm.Destroy()

	fm.Watch(watchDir, targetDir)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		<-c
		fmt.Println("Bye Bye")
		fm.Destroy()
		os.Exit(0)
	}()

	quit := make(chan bool, 1)
	/*
		for {
			fmt.Println("sleeping...")
			time.Sleep(10 * time.Second) // or runtime.Gosched() or similar per @misterbee
		}
	*/
	<-quit
}
开发者ID:Bnei-Baruch,项目名称:mms-file-manager-old,代码行数:32,代码来源:main.go


示例18: init

func init() {
	// Load environment variables from .env file.
	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
	}
}
开发者ID:vgardner,项目名称:signedoff-api,代码行数:7,代码来源:main.go


示例19: main

func main() {
	flag.Parse()

	err := godotenv.Load(fmt.Sprintf("config/%s.env", *env))
	if err != nil {
		log.Fatal(err)
		return
	}

	goth.UseProviders(
		github.New(os.Getenv("GITHUB_CLIENT_KEY"), os.Getenv("GITHUB_SECRET"), os.Getenv("GITHUB_CALLBACK")),
	)

	p := pat.New()

	r := newRoom()
	r.tracer = trace.New(os.Stdout)
	p.Add("GET", "/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	p.Add("GET", "/login", &templateHandler{filename: "login.html"})
	p.Get("/auth/{action}/{provider}", loginHandler)
	p.Add("GET", "/room", r)

	// チャットルームの開始
	go r.run()
	// Webサーバの起動
	log.Println("Webサーバーを開始します。ポート: ", *addr)
	if err := http.ListenAndServe(*addr, p); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
开发者ID:kakawamura,项目名称:donuts-tech-calendar,代码行数:30,代码来源:main.go


示例20: main

func main() {
	var (
		base64Encode bool
	)

	if len(os.Args) != 2 && len(os.Args) != 3 {
		fmt.Fprintln(os.Stderr, Usage)
		os.Exit(1)
	}

	flag.BoolVar(&base64Encode, "base64", false, "Embed Base64-encoded variables")
	flag.Parse()

	err := godotenv.Load()
	if err != nil {
		fmt.Fprintln(os.Stderr, "Failed to load .env!")
		os.Exit(1)
	}

	templateFile := os.Args[len(os.Args)-1]
	tmpl, err := template.ParseFiles(templateFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to parse template file: %s\n", templateFile)
		os.Exit(1)
	}

	err = tmpl.Execute(os.Stdout, envmap(base64Encode))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to apply from template file: %s\n", templateFile)
		os.Exit(1)
	}
}
开发者ID:dtan4,项目名称:teppan,代码行数:32,代码来源:teppan.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang peony.Flash类代码示例发布时间:2022-05-23
下一篇:
Golang bytengine.Command类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap