From cd5a1478064ac01a9f1369101ac35c10d32df635 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 17 Apr 2023 19:47:08 +0300 Subject: initial version --- LICENSE | 2 +- README.md | 4 ++-- Taskfile.yml | 6 ++++++ cmd/gorum/main.go | 28 ++++++++++++++++++++++++++++ go.mod | 3 +++ gorum.json | 9 +++++++++ internal/config.go | 40 ++++++++++++++++++++++++++++++++++++++++ internal/run.go | 10 ++++++++++ 8 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 Taskfile.yml create mode 100644 cmd/gorum/main.go create mode 100644 go.mod create mode 100644 gorum.json create mode 100644 internal/config.go create mode 100644 internal/run.go diff --git a/LICENSE b/LICENSE index ea890af..7ff7fda 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) . +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: diff --git a/README.md b/README.md index 166f0d2..53b4516 100644 --- a/README.md +++ b/README.md @@ -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) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4cddad0 --- /dev/null +++ b/go.mod @@ -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) + } +} -- cgit v1.2.3