forked from mykola/lux
begin writing config parsing
This commit is contained in:
parent
c8bc8897b1
commit
f1a6c65ef5
6 changed files with 82 additions and 0 deletions
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
|
@ -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/
|
|
@ -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
|
||||
|
|
27
conf/config.go
Normal file
27
conf/config.go
Normal file
|
@ -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
|
||||
}
|
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module lux
|
||||
|
||||
go 1.23.4
|
||||
|
||||
require gopkg.in/ini.v1 v1.67.0 // indirect
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -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=
|
18
main.go
Normal file
18
main.go
Normal file
|
@ -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)
|
||||
}
|
Loading…
Add table
Reference in a new issue