static-deployer/config/mod.go

48 lines
874 B
Go

package config
import (
"fmt"
"github.com/pelletier/go-toml/v2"
"os"
)
type Config struct {
Version string
Environment string `toml:"environment"`
Service ServiceConfig `toml:"service"`
}
type ServiceConfig struct {
Index string `toml:"index"`
Host string `toml:"host"`
Port int `toml:"port"`
TLS bool `toml:"tls"`
TLSOpt TLSOption `toml:"tls-opt"`
}
type TLSOption struct {
KeyFile string `toml:"key-file"`
CertFile string `toml:"cert-file"`
}
var version *string
func Get() *Config {
ret := Config{Version: *version}
buf, err := os.ReadFile("config.toml")
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v", err)
return nil
}
if err = toml.Unmarshal(buf, &ret); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v", err)
return nil
}
return &ret
}
func DefineVersion(str string) {
version = &str
}