This repository has been archived on 2024-04-25. You can view files and clone it, but cannot push or open issues or pull requests.
golang-rest-example/pkg/config/config.go

21 lines
459 B
Go
Raw Normal View History

2024-02-02 14:39:13 +00:00
package config
import (
"github.com/kelseyhightower/envconfig"
)
type Config struct {
Port int `envconfig:"PORT" default:"8080"`
DatabaseURL string `envconfig:"DATABASE_URL" required:"true"`
DatabaseMigrations string `envconfig:"DATABASE_MIGRATIONS" default:"file:///migrations"`
2024-02-02 14:39:13 +00:00
}
func NewConfig() (*Config, error) {
var cfg Config
err := envconfig.Process("", &cfg)
if err != nil {
return nil, err
}
return &cfg, nil
}