本文整理汇总了Golang中github.com/joho/godotenv.Load函数的典型用法代码示例。如果您正苦于以下问题:Golang Load函数的具体用法?Golang Load怎么用?Golang Load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
}
示例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)
}
示例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()
}
示例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)
}
示例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,
},
}
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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()
}
示例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)
}
示例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()
}
示例14: init
func init() {
godotenv.Load("../.env")
stathat = &Stathat{
StatName: os.Getenv("STATHAT_STAT_NAME"),
Ezkey: os.Getenv("STATHAT_EZKEY"),
}
}
示例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()
}