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"
|
2023-11-09 17:29:45 +00:00
|
|
|
"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"`
|
2023-11-07 21:49:37 +00:00
|
|
|
Port uint16 `env:"PORT" envDefault:"3000"`
|
2023-11-07 20:03:32 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 17:29:45 +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"),
|
2023-11-09 17:29:45 +00:00
|
|
|
Host: "0.0.0.0",
|
2023-11-19 08:15:10 +00:00
|
|
|
ThemeDir: filepath.Join("testdata", "theme"),
|
|
|
|
StaticDir: filepath.Join("testdata", "static"),
|
2023-11-09 17:29:45 +00:00
|
|
|
Port: 3000,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-07 20:03:32 +00:00
|
|
|
func (c Config) AddrPort() netip.AddrPort {
|
2023-11-07 20:19:53 +00:00
|
|
|
return netip.MustParseAddrPort(net.JoinHostPort(c.Host, strconv.FormatUint(uint64(c.Port), 10)))
|
2023-11-07 20:03:32 +00:00
|
|
|
}
|