From 996f59c8af7486b476549878acd3ea2e1a16a644 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Thu, 23 Mar 2023 13:03:16 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Initial=20work=20on=20parsing=20con?= =?UTF-8?q?fig=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 39 +++++++++++++++++++++++++++++++++++++++ go.mod | 6 +++++- go.sum | 4 ++++ main.go | 6 +++--- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 config/config.go diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..850af5b --- /dev/null +++ b/config/config.go @@ -0,0 +1,39 @@ +package config + +import ( + "github.com/BurntSushi/toml" + "github.com/kirsle/configdir" + "path/filepath" +) + +type Config struct { + Domain string `toml:"domain"` + Username string `toml:"username"` + Password string `toml:"admin_password"` + Name string `toml:"name"` + Summary string `toml:"summary"` + Https bool `toml:"https"` + IconUrl string `toml:"icon_url""` + ImageUrl string `toml:"image_url"` + Secret string `toml:"secret"` + TrustedHosts []string `toml:"trusted_hosts"` + ManuallyApproveFollers bool `toml:"manually_approves_followers"` +} + +var config Config + +func init() { + configPath := configdir.LocalConfig("gopub") + if err := configdir.MakePath(configPath); err != nil { + panic(err) + } + + configFile := filepath.Join(configPath, "profile.toml") + if _, err := toml.DecodeFile(configFile, &config); err != nil { + panic(err) + } +} + +func GetConfig() Config { + return config +} diff --git a/go.mod b/go.mod index bd4022c..e35827d 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,11 @@ module codeberg.org/danjones000/gopub go 1.19 -require github.com/gofiber/fiber/v2 v2.42.0 +require ( + github.com/BurntSushi/toml v1.2.1 + github.com/gofiber/fiber/v2 v2.42.0 + github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f +) require ( github.com/andybalholm/brotli v1.0.4 // indirect diff --git a/go.sum b/go.sum index b6be3d8..92dd364 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,13 @@ +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/gofiber/fiber/v2 v2.42.0 h1:Fnp7ybWvS+sjNQsFvkhf4G8OhXswvB6Vee8hM/LyS+8= github.com/gofiber/fiber/v2 v2.42.0/go.mod h1:3+SGNjqMh5VQH5Vz2Wdi43zTIV16ktlFd3x3R6O1Zlc= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f h1:dKccXx7xA56UNqOcFIbuqFjAWPVtP688j5QMgmo6OHU= +github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f/go.mod h1:4rEELDSfUAlBSyUjPG0JnaNGjf13JySHFeRdD/3dLP0= github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= diff --git a/main.go b/main.go index 4cffe9f..24d1b47 100644 --- a/main.go +++ b/main.go @@ -3,16 +3,16 @@ package main import ( "log" + "codeberg.org/danjones000/gopub/config" "github.com/gofiber/fiber/v2" ) func main() { app := fiber.New() + config := config.GetConfig() app.Get("/", func(c *fiber.Ctx) error { - return c.JSON(&fiber.Map{ - "Hello": "World", - }) + return c.JSON(&config) }) log.Fatal(app.Listen(":3000"))