Added config with version

This commit is contained in:
perp 2024-10-09 12:59:42 +01:00
parent 9b65b01ccb
commit 7281837015
6 changed files with 42 additions and 0 deletions

0
cmd/twister/config.toml Normal file
View File

View File

@ -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)
}

6
config/config.go Normal file
View File

@ -0,0 +1,6 @@
package config
// Config is a configuration
type Config struct {
Version string
}

15
config/parse.go Normal file
View File

@ -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
}

2
go.mod
View File

@ -1,3 +1,5 @@
module git.supernets.org/vortex/twister
go 1.23.0
require github.com/BurntSushi/toml v1.4.0

2
go.sum Normal file
View File

@ -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=