From 3cc3bf27edf424d7b7925aad37e0f0b4c556967b Mon Sep 17 00:00:00 2001 From: aceberg <1502200+aceberg@users.noreply.github.com> Date: Mon, 5 Sep 2022 22:19:31 +0700 Subject: [PATCH] Sort buttons --- src/getconfig.go | 13 +++++- src/main.go | 2 +- src/templates/footer.html | 5 --- src/templates/header.html | 59 ++++++++++++++++++++++++++- src/templates/index.html | 2 +- src/templates/offline.html | 74 ++++++++++++++++++++++++++++++++++ src/{index.go => web-index.go} | 4 ++ src/web-onoffline.go | 44 ++++++++++++++++++++ src/web-sort.go | 50 +++++++++++++++++++++++ src/web-theme.go | 21 ++++++++++ 10 files changed, 264 insertions(+), 10 deletions(-) create mode 100644 src/templates/offline.html rename src/{index.go => web-index.go} (89%) create mode 100644 src/web-onoffline.go create mode 100644 src/web-sort.go create mode 100644 src/web-theme.go diff --git a/src/getconfig.go b/src/getconfig.go index 24f8271..cb80354 100644 --- a/src/getconfig.go +++ b/src/getconfig.go @@ -4,7 +4,9 @@ import ( "github.com/spf13/viper" ) -func get_config(path string) (config Conf) { +const configPath = "/data/config" + +func get_config() (config Conf) { viper.SetDefault("IFACE", "enp1s0") viper.SetDefault("DBPATH", "/data/db.sqlite") viper.SetDefault("GUIIP", "localhost") @@ -13,7 +15,7 @@ func get_config(path string) (config Conf) { viper.SetDefault("SHOUTRRR_URL", "") viper.SetDefault("THEME", "solar") - viper.SetConfigFile(path) + viper.SetConfigFile(configPath) viper.SetConfigType("env") viper.ReadInConfig() @@ -28,4 +30,11 @@ func get_config(path string) (config Conf) { config.Theme = viper.Get("THEME").(string) return config +} + +func write_config() { + viper.SetConfigFile(configPath) + viper.SetConfigType("env") + viper.Set("THEME", AppConfig.Theme) + viper.WriteConfig() } \ No newline at end of file diff --git a/src/main.go b/src/main.go index be3c1ed..e64c974 100644 --- a/src/main.go +++ b/src/main.go @@ -44,7 +44,7 @@ func scan_and_compare() { func main() { AllHosts = []Host{} - AppConfig = get_config("/data/config") // Get config from Defaults, Config file, Env + AppConfig = get_config() // Get config from Defaults, Config file, Env db_create() // Check if DB exists. Create if not diff --git a/src/templates/footer.html b/src/templates/footer.html index 0032e6a..5dd8ca7 100644 --- a/src/templates/footer.html +++ b/src/templates/footer.html @@ -1,9 +1,4 @@ {{ define "footer"}} -