You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
website/services/config/config.go

53 lines
815 B
Go

2 years ago
package config
import (
"phc/website/sl"
"github.com/joho/godotenv"
)
type Interface interface {
sl.Service
Mode() string
Host() string
}
type Custom struct {
ModeValue string
HostValue string
}
func (c Custom) Mode() string { return c.ModeValue }
func (c Custom) Host() string { return c.HostValue }
func (Custom) Initialize(l *sl.ServiceLocator) error {
return nil
}
type EnvConfig struct {
mode string
host string
}
func (c EnvConfig) Mode() string { return c.mode }
func (c EnvConfig) Host() string { return c.host }
func (c *EnvConfig) Initialize(l *sl.ServiceLocator) error {
m, err := godotenv.Read(".env")
if err != nil {
return err
}
c.mode = "production"
if v, ok := m["MODE"]; ok {
c.mode = v
}
c.host = ":4000"
if v, ok := m["HOST"]; ok {
c.host = v
}
return nil
}