Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic when setting bool via envvar #734

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ type Configuration struct {
Port int `default:"80"`

SSL struct {
Enabled *bool `default:"false"`
RedirectToHTTPS *bool `default:"true"`
Enabled bool `default:"false"`
RedirectToHTTPS bool `default:"true"`
ListenAddr string `default:""`
Port int `default:"443"`
CertFile string `default:""`
CertKey string `default:""`
LetsEncrypt struct {
Enabled *bool `default:"false"`
AcceptTOS *bool `default:"false"`
Enabled bool `default:"false"`
AcceptTOS bool `default:"false"`
Cache string `default:"data/certs"`
Hosts []string
}
Expand Down
2 changes: 1 addition & 1 deletion router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co
g.Use(gin.LoggerWithFormatter(logFormatter), gin.Recovery(), gerror.Handler(), location.Default())
g.NoRoute(gerror.NotFound())

if conf.Server.SSL.Enabled != nil && conf.Server.SSL.RedirectToHTTPS != nil && *conf.Server.SSL.Enabled && *conf.Server.SSL.RedirectToHTTPS {
if conf.Server.SSL.Enabled && conf.Server.SSL.RedirectToHTTPS {
g.Use(func(ctx *gin.Context) {
if ctx.Request.TLS != nil {
ctx.Next()
Expand Down
6 changes: 3 additions & 3 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
defer httpListener.Close()

s := &http.Server{Handler: router}
if *conf.Server.SSL.Enabled {
if *conf.Server.SSL.LetsEncrypt.Enabled {
if conf.Server.SSL.Enabled {
if conf.Server.SSL.LetsEncrypt.Enabled {

Check warning on line 32 in runner/runner.go

View check run for this annotation

Codecov / codecov/patch

runner/runner.go#L31-L32

Added lines #L31 - L32 were not covered by tests
applyLetsEncrypt(s, conf)
}

Expand Down Expand Up @@ -93,7 +93,7 @@

func applyLetsEncrypt(s *http.Server, conf *config.Configuration) {
certManager := autocert.Manager{
Prompt: func(tosURL string) bool { return *conf.Server.SSL.LetsEncrypt.AcceptTOS },
Prompt: func(tosURL string) bool { return conf.Server.SSL.LetsEncrypt.AcceptTOS },

Check warning on line 96 in runner/runner.go

View check run for this annotation

Codecov / codecov/patch

runner/runner.go#L96

Added line #L96 was not covered by tests
HostPolicy: autocert.HostWhitelist(conf.Server.SSL.LetsEncrypt.Hosts...),
Cache: autocert.DirCache(conf.Server.SSL.LetsEncrypt.Cache),
}
Expand Down
Loading