diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd5ab5f --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +run/ diff --git a/README.md b/README.md index 293c34e..26f1048 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,9 @@ Host's state consists of: Node's state is table of hosts' states + their last heartbeat time. Node state must also include generation ID, which must be guaranteed to be unique in scope of last 128 generations. A new generation should only happen when any of the hosts has new heartbeat. + +## Software architecture + +- Config are INI files. +- Daemon, that constantly runs and serves protocol. Also provides UNIX socket for cli configuration +- CLI to communicate with UNIX socket and issue commands diff --git a/conf/config.go b/conf/config.go new file mode 100644 index 0000000..be65267 --- /dev/null +++ b/conf/config.go @@ -0,0 +1,27 @@ +package conf + +import "gopkg.in/ini.v1" + +type LuxConnection struct { + Bind string `ini:"bind"` + Port int `ini:"port"` +} + +type LuxConfig struct { + Exterior LuxConnection `ini:"exterior"` + Interior LuxConnection `ini:"interior"` + Mode string `ini:"mode"` +} + +func (conf *LuxConfig) ParseConfig(path string) error { + ini, err := ini.Load(path) + if err != nil { + return err + } + + if err = ini.MapTo(conf); err != nil { + return err + } + + return nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5721b4f --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module lux + +go 1.23.4 + +require gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a8937af --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/main.go b/main.go new file mode 100644 index 0000000..3d2713a --- /dev/null +++ b/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "log" + "lux/conf" +) + +var config *conf.LuxConfig = &conf.LuxConfig{} + +func main() { + err := config.ParseConfig("run/etc/lux.conf") + if err != nil { + log.Fatal(err) + } + + fmt.Println(config) +}