summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-04-17 19:47:08 +0300
committerPaul Buetow <paul@buetow.org>2023-05-17 23:22:49 +0300
commitcd5a1478064ac01a9f1369101ac35c10d32df635 (patch)
treea4b7f1f65f5fc75883db8c18972ea29f984eab59
parente96f62acfd73d1c6b9a540927ada2ac8c81cffc1 (diff)
initial version
-rw-r--r--LICENSE2
-rw-r--r--README.md4
-rw-r--r--Taskfile.yml6
-rw-r--r--cmd/gorum/main.go28
-rw-r--r--go.mod3
-rw-r--r--gorum.json9
-rw-r--r--internal/config.go40
-rw-r--r--internal/run.go10
8 files changed, 99 insertions, 3 deletions
diff --git a/LICENSE b/LICENSE
index ea890af..7ff7fda 100644
--- a/LICENSE
+++ b/LICENSE
@@ -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:
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)
+ }
+}