diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index d62d64a..7d5ac8d 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -2,12 +2,12 @@ # To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml version: 0.1 cli: - version: 1.22.6 + version: 1.22.8 # Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) plugins: sources: - id: trunk - ref: v1.6.3 + ref: v1.6.5 uri: https://github.com/trunk-io/plugins # Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) runtimes: @@ -21,18 +21,18 @@ lint: - markdownlint - yamllint enabled: - - hadolint@2.12.0 - - actionlint@1.7.3 - - checkov@3.2.257 + - hadolint@2.12.1-beta + - actionlint@1.7.4 + - checkov@3.2.324 - git-diff-check - gofmt@1.20.4 - - golangci-lint@1.61.0 - - osv-scanner@1.9.0 - - oxipng@9.1.2 - - prettier@3.3.3 + - golangci-lint@1.62.2 + - osv-scanner@1.9.1 + - oxipng@9.1.3 + - prettier@3.4.1 - shellcheck@0.10.0 - shfmt@3.6.0 - - trufflehog@3.82.7 + - trufflehog@3.84.1 actions: disabled: - trunk-announce diff --git a/internal/autocert/provider.go b/internal/autocert/provider.go index 1854142..de9ded7 100644 --- a/internal/autocert/provider.go +++ b/internal/autocert/provider.go @@ -204,15 +204,14 @@ func (p *Provider) registerACME() error { p.user.Registration = reg logger.Info().Msg("reused acme registration from private key") return nil - } else { - reg, err := p.client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true}) - if err != nil { - return err - } - p.user.Registration = reg - logger.Info().Interface("reg", reg).Msg("acme registered") } + reg, err := p.client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true}) + if err != nil { + return err + } + p.user.Registration = reg + logger.Info().Interface("reg", reg).Msg("acme registered") return nil } diff --git a/internal/common/crypto.go b/internal/common/crypto.go index 367025b..5afd0bf 100644 --- a/internal/common/crypto.go +++ b/internal/common/crypto.go @@ -1,7 +1,6 @@ package common import ( - "crypto/rand" "crypto/sha512" "encoding/base64" @@ -14,14 +13,6 @@ func HashPassword(pwd string) []byte { return h.Sum(nil) } -func generateJWTKey(size int) string { - bytes := make([]byte, size) - if _, err := rand.Read(bytes); err != nil { - log.Panic().Err(err).Msg("failed to generate jwt key") - } - return base64.StdEncoding.EncodeToString(bytes) -} - func decodeJWTKey(key string) []byte { if key == "" { return nil diff --git a/internal/docker/inspect.go b/internal/docker/inspect.go index 3531af5..6a30d96 100644 --- a/internal/docker/inspect.go +++ b/internal/docker/inspect.go @@ -8,12 +8,11 @@ import ( func Inspect(dockerHost string, containerID string) (*Container, error) { client, err := ConnectClient(dockerHost) - defer client.Close() - if err != nil { return nil, err } + defer client.Close() return client.Inspect(containerID) } diff --git a/internal/homepage/categories.go b/internal/homepage/categories.go index 7de09b8..80e4d67 100644 --- a/internal/homepage/categories.go +++ b/internal/homepage/categories.go @@ -1,6 +1,6 @@ package homepage -// PredefinedCategories by alias or docker image name +// PredefinedCategories by alias or docker image name. var PredefinedCategories = map[string]string{ "sonarr": "Torrenting", "radarr": "Torrenting", diff --git a/internal/homepage/homepage.go b/internal/homepage/homepage.go index 73c6dee..2dba64c 100644 --- a/internal/homepage/homepage.go +++ b/internal/homepage/homepage.go @@ -10,8 +10,8 @@ type ( Icon string `json:"icon" yaml:"icon"` URL string `json:"url" yaml:"url"` // alias + domain Category string `json:"category" yaml:"category"` - Description string `json:"description" yaml:"description"` - WidgetConfig map[string]any `json:"widget_config" yaml:",flow"` + Description string `json:"description" yaml:"description" aliases:"desc"` + WidgetConfig map[string]any `json:"widget_config" yaml:",flow" aliases:"widget"` SourceType string `json:"source_type" yaml:"-"` AltURL string `json:"alt_url" yaml:"-"` // original proxy target diff --git a/internal/net/http/loadbalancer/loadbalancer.go b/internal/net/http/loadbalancer/loadbalancer.go index 46ebae0..89b06f6 100644 --- a/internal/net/http/loadbalancer/loadbalancer.go +++ b/internal/net/http/loadbalancer/loadbalancer.go @@ -218,7 +218,9 @@ func (lb *LoadBalancer) ServeHTTP(rw http.ResponseWriter, r *http.Request) { if r.Header.Get(common.HeaderCheckRedirect) != "" { // wake all servers for _, srv := range srvs { - srv.TryWake() + if err := srv.TryWake(); err != nil { + lb.l.Warn().Err(err).Str("server", srv.Name).Msg("failed to wake server") + } } } lb.impl.ServeHTTP(srvs, rw, r) diff --git a/internal/net/http/middleware/cloudflare_real_ip.go b/internal/net/http/middleware/cloudflare_real_ip.go index 64182a9..05af4f4 100644 --- a/internal/net/http/middleware/cloudflare_real_ip.go +++ b/internal/net/http/middleware/cloudflare_real_ip.go @@ -109,7 +109,7 @@ func fetchUpdateCFIPRange(endpoint string, cfCIDRs []*types.CIDR) error { return fmt.Errorf("cloudflare responeded an invalid CIDR: %s", line) } - cfCIDRs = append(cfCIDRs, (*types.CIDR)(cidr)) + cfCIDRs = append(cfCIDRs, cidr) } return nil diff --git a/internal/notif/webhook.go b/internal/notif/webhook.go index 18a1c5a..65c09d9 100644 --- a/internal/notif/webhook.go +++ b/internal/notif/webhook.go @@ -40,7 +40,10 @@ func jsonIfTemplateNotUsed(fl validator.FieldLevel) bool { } func init() { - utils.Validator().RegisterValidation("jsonIfTemplateNotUsed", jsonIfTemplateNotUsed) + err := utils.Validator().RegisterValidation("jsonIfTemplateNotUsed", jsonIfTemplateNotUsed) + if err != nil { + panic(err) + } } // Name implements Provider. @@ -52,9 +55,8 @@ func (webhook *Webhook) Name() string { func (webhook *Webhook) Method() string { if webhook.Meth != "" { return webhook.Meth - } else { - return http.MethodPost } + return http.MethodPost } // URL implements Provider. @@ -71,17 +73,16 @@ func (webhook *Webhook) Token() string { func (webhook *Webhook) MIMEType() string { if webhook.MIMETyp != "" { return webhook.MIMETyp - } else { - return "application/json" } + return "application/json" } -func (Webhook *Webhook) ColorMode() string { - switch Webhook.Template { +func (webhook *Webhook) ColorMode() string { + switch webhook.Template { case "discord": return "dec" default: - return Webhook.ColorM + return webhook.ColorM } } @@ -119,7 +120,7 @@ func (webhook *Webhook) MakeBody(logMsg *LogMessage) (io.Reader, error) { plTempl := strings.NewReplacer( "$title", string(title), "$message", string(message), - "$fields", string(fields), + "$fields", fields, "$color", color, ) var pl string diff --git a/internal/route/provider/docker_test.go b/internal/route/provider/docker_test.go index d2d2945..103934c 100644 --- a/internal/route/provider/docker_test.go +++ b/internal/route/provider/docker_test.go @@ -8,7 +8,6 @@ import ( "github.com/docker/docker/api/types/network" "github.com/docker/docker/client" "github.com/yusing/go-proxy/internal/common" - "github.com/yusing/go-proxy/internal/docker" D "github.com/yusing/go-proxy/internal/docker" E "github.com/yusing/go-proxy/internal/error" "github.com/yusing/go-proxy/internal/route" @@ -17,9 +16,7 @@ import ( . "github.com/yusing/go-proxy/internal/utils/testing" ) -var ( - dummyNames = []string{"/a"} -) +var dummyNames = []string{"/a"} func makeEntries(cont *types.Container, dockerHost ...string) route.RawEntries { var p DockerProvider @@ -29,7 +26,7 @@ func makeEntries(cont *types.Container, dockerHost ...string) route.RawEntries { } else { host = client.DefaultDockerHost } - entries := E.Must(p.entriesFromContainerLabels(docker.FromDocker(cont, host))) + entries := E.Must(p.entriesFromContainerLabels(D.FromDocker(cont, host))) entries.RangeAll(func(k string, v *route.RawEntry) { v.Finalize() }) @@ -269,7 +266,9 @@ func TestPrivateIPLocalhost(t *testing.T) { "network": { IPAddress: "172.17.0.123", }, - }}} + }, + }, + } raw, ok := makeEntries(c).Load("a") ExpectTrue(t, ok) ExpectEqual(t, raw.Container.PrivateIP, "172.17.0.123") @@ -286,7 +285,8 @@ func TestPrivateIPRemote(t *testing.T) { IPAddress: "172.17.0.123", }, }, - }} + }, + } raw, ok := makeEntries(c, "tcp://1.2.3.4:2375").Load("a") ExpectTrue(t, ok) ExpectEqual(t, raw.Container.PrivateIP, "") diff --git a/internal/route/route.go b/internal/route/route.go index cf09f22..aaabddd 100755 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -40,8 +40,10 @@ const ( ) // function alias. -var NewRoutes = F.NewMap[Routes] -var NewProxyEntries = types.NewProxyEntries +var ( + NewRoutes = F.NewMap[Routes] + NewProxyEntries = types.NewProxyEntries +) func (rt *Route) Container() *docker.Container { if rt.Entry.Container == nil { diff --git a/internal/watcher/health/config.go b/internal/watcher/health/config.go index 6ecb198..fda787d 100644 --- a/internal/watcher/health/config.go +++ b/internal/watcher/health/config.go @@ -5,7 +5,7 @@ import ( ) type HealthCheckConfig struct { - Disable bool `json:"disable,omitempty" yaml:"disable"` + Disable bool `json:"disable,omitempty" yaml:"disable" aliases:"disabled"` Path string `json:"path,omitempty" yaml:"path"` UseGet bool `json:"use_get,omitempty" yaml:"use_get"` Interval time.Duration `json:"interval" yaml:"interval"`