initial commit

This commit is contained in:
2023-01-31 02:40:19 +01:00
commit 552c004151
23 changed files with 1822 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
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
}