From 728183701594b3bf9bf69a39e4f5a86b95455bd5 Mon Sep 17 00:00:00 2001 From: perp Date: Wed, 9 Oct 2024 12:59:42 +0100 Subject: [PATCH] Added config with version --- cmd/twister/config.toml | 0 cmd/twister/main.go | 17 +++++++++++++++++ config/config.go | 6 ++++++ config/parse.go | 15 +++++++++++++++ go.mod | 2 ++ go.sum | 2 ++ 6 files changed, 42 insertions(+) create mode 100644 cmd/twister/config.toml create mode 100644 config/config.go create mode 100644 config/parse.go create mode 100644 go.sum diff --git a/cmd/twister/config.toml b/cmd/twister/config.toml new file mode 100644 index 0000000..e69de29 diff --git a/cmd/twister/main.go b/cmd/twister/main.go index da29a2c..307b118 100644 --- a/cmd/twister/main.go +++ b/cmd/twister/main.go @@ -1,4 +1,21 @@ package main +import ( + _ "embed" + "fmt" + + "git.supernets.org/vortex/twister/config" +) + +var ( + //go:embed config.toml + content []byte + + version = "0.1.0" +) + func main() { + conf := config.Parse(content) + conf.Version = version + fmt.Println(conf) } diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..75e4f02 --- /dev/null +++ b/config/config.go @@ -0,0 +1,6 @@ +package config + +// Config is a configuration +type Config struct { + Version string +} diff --git a/config/parse.go b/config/parse.go new file mode 100644 index 0000000..41ae8b6 --- /dev/null +++ b/config/parse.go @@ -0,0 +1,15 @@ +package config + +import "github.com/BurntSushi/toml" + +// Parse the config +func Parse(content []byte) *Config { + var cfg *Config + + err := toml.Unmarshal(content, &cfg) + if err != nil { + panic(err) + } + + return cfg +} diff --git a/go.mod b/go.mod index 70cf65c..8173456 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module git.supernets.org/vortex/twister go 1.23.0 + +require github.com/BurntSushi/toml v1.4.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8bc10f6 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=