mirror of
https://github.com/SourceFellows/gobuch.git
synced 2025-08-03 13:12:16 +02:00
initial import
This commit is contained in:
28
configuration/application-configuration/cmd/main.go
Normal file
28
configuration/application-configuration/cmd/main.go
Normal file
@ -0,0 +1,28 @@
|
||||
/*Package main show how to use envconfig.
|
||||
|
||||
Start the app in the root folder with:
|
||||
|
||||
SERVER_PORT=8080 SERVER_HOST=localhost go run cmd/main.go
|
||||
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
"golang.source-fellows.com/samples/applicationconfiguration"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
cfg := applicationconfiguration.Config{}
|
||||
err := envconfig.Process("", &cfg)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(cfg.Server.Port)
|
||||
|
||||
}
|
12
configuration/application-configuration/configuration.go
Normal file
12
configuration/application-configuration/configuration.go
Normal file
@ -0,0 +1,12 @@
|
||||
package applicationconfiguration
|
||||
|
||||
type Config struct {
|
||||
Server struct {
|
||||
Port string `envconfig:"SERVER_PORT" required:"true"`
|
||||
Host string `envconfig:"SERVER_HOST" required:"true"`
|
||||
}
|
||||
Database struct {
|
||||
Username string `envconfig:"DB_USERNAME"`
|
||||
Password string `envconfig:"DB_PASSWORD"`
|
||||
}
|
||||
}
|
5
configuration/application-configuration/go.mod
Normal file
5
configuration/application-configuration/go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module golang.source-fellows.com/samples/applicationconfiguration
|
||||
|
||||
go 1.14
|
||||
|
||||
require github.com/kelseyhightower/envconfig v1.4.0 // indirect
|
2
configuration/application-configuration/go.sum
Normal file
2
configuration/application-configuration/go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
||||
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
Reference in New Issue
Block a user