Move to Traefik

This commit is contained in:
Tom Wiesing 2022-10-07 19:46:14 +02:00
parent bf57c0d5a6
commit 471ccbadc5
No known key found for this signature in database
36 changed files with 200 additions and 190 deletions

View file

@ -1,7 +1,10 @@
package config
import (
"fmt"
"strings"
"github.com/tkw1536/goprogram/lib/collection"
)
// This file contains domain related derived configuration values.
@ -11,6 +14,22 @@ func (cfg Config) HTTPSEnabled() bool {
return cfg.CertbotEmail != ""
}
// HostRequirement returns a traefik rule for the given names
func (Config) HostRule(names ...string) string {
quoted := collection.MapSlice(names, func(name string) string {
return "`" + name + "`"
})
return fmt.Sprintf("Host(%s)", strings.Join(quoted, ","))
}
// HTTPSEnabledEnv returns "true" if https is enabled, and "false" otherwise.
func (cfg Config) HTTPSEnabledEnv() string {
if cfg.HTTPSEnabled() {
return "true"
}
return "false"
}
// IfHttps returns value when the distillery has https enabled, and the empty string otherwise.
func (cfg Config) IfHttps(value string) string {
if !cfg.HTTPSEnabled() {
@ -19,27 +38,17 @@ func (cfg Config) IfHttps(value string) string {
return value
}
// DefaultHost returns the default hostname for the distillery.
//
// DefaultHostRule returns the default traefik hostname rule for this distillery.
// This consists of the [DefaultDomain] as well as [ExtraDomains].
// Domain names are concatinated with commas.
func (cfg Config) DefaultHost() string {
var builder strings.Builder
builder.WriteString(cfg.DefaultDomain)
for _, domain := range cfg.SelfExtraDomains {
builder.WriteRune(',')
builder.WriteString(domain)
}
return builder.String()
func (cfg Config) DefaultHostRule() string {
return cfg.HostRule(append([]string{cfg.DefaultDomain}, cfg.SelfExtraDomains...)...)
}
// DefaultSSLHost returns the default hostname for the ssl version of the distillery.
//
// This is exactly [DefaultHost] when SSL is enabled, and the empty string otherwise.
func (cfg Config) DefaultSSLHost() string {
return cfg.IfHttps(cfg.DefaultHost())
func (cfg Config) xDefaultSSLHost() string {
panic("not implemented")
}
// SlugFromHost returns the slug belonging to the appropriate host.'