diff options
| author | Paul Buetow <paul@buetow.org> | 2023-04-17 19:47:08 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-05-17 23:22:49 +0300 |
| commit | cd5a1478064ac01a9f1369101ac35c10d32df635 (patch) | |
| tree | a4b7f1f65f5fc75883db8c18972ea29f984eab59 | |
| parent | e96f62acfd73d1c6b9a540927ada2ac8c81cffc1 (diff) | |
initial version
| -rw-r--r-- | LICENSE | 2 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | Taskfile.yml | 6 | ||||
| -rw-r--r-- | cmd/gorum/main.go | 28 | ||||
| -rw-r--r-- | go.mod | 3 | ||||
| -rw-r--r-- | gorum.json | 9 | ||||
| -rw-r--r-- | internal/config.go | 40 | ||||
| -rw-r--r-- | internal/run.go | 10 |
8 files changed, 99 insertions, 3 deletions
@@ -1,4 +1,4 @@ -Copyright (c) <year> <owner>. +Copyright (c) 2023 Paul Buetow. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -1,3 +1,3 @@ -# gogios +# Gorum -Minimalist monitoring system, compatible with the Nagios Check API.
\ No newline at end of file +Gogios is a minimalistic quorum manager. diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..342395b --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,6 @@ +version: '3' + +tasks: + build: + cmds: + - go build -o gorum cmd/gorum/main.go diff --git a/cmd/gorum/main.go b/cmd/gorum/main.go new file mode 100644 index 0000000..223da9d --- /dev/null +++ b/cmd/gorum/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "context" + "flag" + "fmt" + + "codeberg.org/snonux/gorum/internal" +) + +const versionStr = "v0.0.0" + +func main() { + configFile := flag.String("cfg", "/etc/gorum.json", "The config file") + version := flag.Bool("version", false, "Display version") + flag.Parse() + + if *version { + fmt.Printf("This is Gorum version %s; (C) by Paul Buetow\n", versionStr) + fmt.Println("https://codeberg.org/snonux/gorum") + return + } + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + internal.Run(ctx, *configFile) +} @@ -0,0 +1,3 @@ +module codeberg.org/snonux/gorum + +go 1.19 diff --git a/gorum.json b/gorum.json new file mode 100644 index 0000000..076b045 --- /dev/null +++ b/gorum.json @@ -0,0 +1,9 @@ +{ + "Hostname": "earth", + "Port": 1234, + "Participants": [ + { "Hostname": "earth", "Port": 1234 }, + { "Hostname": "earth", "Port": 2341 }, + { "Hostname": "earth", "Port": 3412 } + ] +} diff --git a/internal/config.go b/internal/config.go new file mode 100644 index 0000000..c3fff26 --- /dev/null +++ b/internal/config.go @@ -0,0 +1,40 @@ +package internal + +import ( + "encoding/json" + "io/ioutil" + "os" +) + +type participant struct { + Hostname string + Port int +} + +type config struct { + Hostname string + Port int + Participants []participant +} + +func newConfig(configFile string) (config, error) { + var config config + + file, err := os.Open(configFile) + if err != nil { + return config, err + } + defer file.Close() + + bytes, err := ioutil.ReadAll(file) + if err != nil { + return config, err + } + + err = json.Unmarshal(bytes, &config) + if err != nil { + return config, err + } + + return config, nil +} diff --git a/internal/run.go b/internal/run.go new file mode 100644 index 0000000..2d177ea --- /dev/null +++ b/internal/run.go @@ -0,0 +1,10 @@ +package internal + +import "context" + +func Run(ctx context.Context, configFile string) { + _, err := newConfig(configFile) + if err != nil { + panic(err) + } +} |
