From b7d8b94d46746af4ba36ebe602b7cd93d31febd5 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Sat, 25 May 2024 11:26:55 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + Makefile | 7 ++++++ cmd/bookworm/bookworm.go | 50 ++++++++++++++++++++++++++++++++++++++++ go.mod | 3 +++ 4 files changed, 61 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 cmd/bookworm/bookworm.go create mode 100644 go.mod diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f569d9a --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +build: + rm -rf bin + mkdir bin + go build -o bin ./... + +check: + go fmt ./... diff --git a/cmd/bookworm/bookworm.go b/cmd/bookworm/bookworm.go new file mode 100644 index 0000000..c4d0d9c --- /dev/null +++ b/cmd/bookworm/bookworm.go @@ -0,0 +1,50 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "os" +) + +type Config struct { + MinifluxURL string `json:"miniflux_url"` + MinifluxAPI string `json:"miniflux_api"` + MinifluxCategory string `json:"miniflux_category"` +} + +func (c *Config) IsValid() error { + return nil +} + +func ReadConfig(name string) (*Config, error) { + b, err := os.ReadFile(name) + if err != nil { + return nil, err + } + + var cfg Config + if err := json.Unmarshal(b, &cfg); err != nil { + return nil, err + } + + return &cfg, nil +} + +func checkErr(err error) { + if err != nil { + fmt.Fprintf(os.Stderr, "error: %s\n", err) + os.Exit(1) + } +} + +func main() { + cfgFlag := flag.String("config", "bookworm.json", "path to the configuration file") + flag.Parse() + + cfg, err := ReadConfig(*cfgFlag) + checkErr(err) + + cErr := cfg.IsValid() + checkErr(cErr) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bcd3f32 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.ctrlz.es/mgdelacroix/bookworm + +go 1.21.9