From cf1ecbc8268b9b7d2036f4bdbe449f82da0d41c8 Mon Sep 17 00:00:00 2001 From: yusing Date: Mon, 4 Nov 2024 01:44:58 +0800 Subject: [PATCH] added option to disable default app categories --- cmd/main.go | 2 +- config.example.yml | 10 ++++++++-- internal/config/query.go | 16 +++++++++------- internal/config/types/config.go | 5 ++++- internal/config/types/homepage_config.go | 5 +++++ 5 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 internal/config/types/homepage_config.go diff --git a/cmd/main.go b/cmd/main.go index 45d4223..764a723 100755 --- a/cmd/main.go +++ b/cmd/main.go @@ -168,5 +168,5 @@ func printJSON(obj any) { logging.Fatal().Err(err).Send() } rawLogger := log.New(os.Stdout, "", 0) - rawLogger.Printf("%s", j) // raw output for convenience using "jq" + rawLogger.Print(string(j)) // raw output for convenience using "jq" } diff --git a/config.example.yml b/config.example.yml index 6745a80..5a5937e 100644 --- a/config.example.yml +++ b/config.example.yml @@ -57,13 +57,19 @@ providers: # - my.site # - node1.my.app +# homepage config +# +homepage: + # use default app categories detected from alias or docker image name + use_default_categories: true + # Below are fixed options (non hot-reloadable) # timeout for shutdown (in seconds) # -# timeout_shutdown: 5 +timeout_shutdown: 5 # global setting redirect http requests to https (if https available, otherwise this will be ignored) # proxy..middlewares.redirect_http will override this # -# redirect_to_https: false +redirect_to_https: false diff --git a/internal/config/query.go b/internal/config/query.go index 6f7b6a7..9f04c60 100644 --- a/internal/config/query.go +++ b/internal/config/query.go @@ -69,15 +69,17 @@ func HomepageConfig() homepage.Config { ) } - if en.Container != nil && item.Category == "" { - if category, ok := homepage.PredefinedCategories[en.Container.ImageName]; ok { - item.Category = category + if instance.value.Homepage.UseDefaultCategories { + if en.Container != nil && item.Category == "" { + if category, ok := homepage.PredefinedCategories[en.Container.ImageName]; ok { + item.Category = category + } } - } - if item.Category == "" { - if category, ok := homepage.PredefinedCategories[strings.ToLower(alias)]; ok { - item.Category = category + if item.Category == "" { + if category, ok := homepage.PredefinedCategories[strings.ToLower(alias)]; ok { + item.Category = category + } } } diff --git a/internal/config/types/config.go b/internal/config/types/config.go index 5eef941..487cdf2 100644 --- a/internal/config/types/config.go +++ b/internal/config/types/config.go @@ -6,6 +6,7 @@ type ( AutoCert AutoCertConfig `json:"autocert" yaml:",flow"` ExplicitOnly bool `json:"explicit_only" yaml:"explicit_only"` MatchDomains []string `json:"match_domains" yaml:"match_domains"` + Homepage HomepageConfig `json:"homepage" yaml:"homepage"` TimeoutShutdown int `json:"timeout_shutdown" yaml:"timeout_shutdown"` RedirectToHTTPS bool `json:"redirect_to_https" yaml:"redirect_to_https"` } @@ -18,8 +19,10 @@ type ( func DefaultConfig() *Config { return &Config{ - Providers: Providers{}, TimeoutShutdown: 3, + Homepage: HomepageConfig{ + UseDefaultCategories: true, + }, RedirectToHTTPS: false, } } diff --git a/internal/config/types/homepage_config.go b/internal/config/types/homepage_config.go new file mode 100644 index 0000000..e44c636 --- /dev/null +++ b/internal/config/types/homepage_config.go @@ -0,0 +1,5 @@ +package types + +type HomepageConfig struct { + UseDefaultCategories bool `json:"use_default_categories" yaml:"use_default_categories"` +}