static-deployer/config/mod.go
2025-04-24 22:16:52 +09:00

41 lines
720 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 {
Host string `toml:"host"`
Port int `toml:"port"`
}
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(format string, args ...any) {
var str = fmt.Sprintf(format, args)
version = &str
}