home/internal/domain/config.go

36 lines
881 B
Go
Raw Normal View History

2023-11-07 20:03:32 +00:00
package domain
import (
"net"
"net/netip"
2023-11-19 08:15:10 +00:00
"path/filepath"
2023-11-07 20:03:32 +00:00
"strconv"
"testing"
2023-11-07 20:03:32 +00:00
)
type Config struct {
2023-11-19 08:15:10 +00:00
ContentDir string `env:"CONTENT_DIR" envDefault:"content"`
2023-11-08 02:21:45 +00:00
Host string `env:"HOST" envDefault:"0.0.0.0"`
2023-11-19 08:15:10 +00:00
ThemeDir string `env:"THEME_DIR" envDefault:"theme"`
StaticDir string `env:"STATIC_DIR" envDefault:"static"`
2024-02-14 05:47:22 +00:00
CertKey string `env:"CERT_KEY"`
CertFile string `env:"CERT_FILE"`
Port uint16 `env:"PORT" envDefault:"3000"`
2023-11-07 20:03:32 +00:00
}
func TestConfig(tb testing.TB) *Config {
tb.Helper()
return &Config{
2023-11-19 08:15:10 +00:00
ContentDir: filepath.Join("testdata", "content"),
Host: "0.0.0.0",
2023-11-19 08:15:10 +00:00
ThemeDir: filepath.Join("testdata", "theme"),
StaticDir: filepath.Join("testdata", "static"),
Port: 3000,
}
}
2023-11-07 20:03:32 +00:00
func (c Config) AddrPort() netip.AddrPort {
return netip.MustParseAddrPort(net.JoinHostPort(c.Host, strconv.FormatUint(uint64(c.Port), 10)))
2023-11-07 20:03:32 +00:00
}