Skip to content

Commit cc7da2a

Browse files
authored
Merge pull request #734 from gotify/panic-bool
fix: panic when setting bool via envvar
2 parents 8639316 + 6b3ff77 commit cc7da2a

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Diff for: config/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ type Configuration struct {
1616
Port int `default:"80"`
1717

1818
SSL struct {
19-
Enabled *bool `default:"false"`
20-
RedirectToHTTPS *bool `default:"true"`
19+
Enabled bool `default:"false"`
20+
RedirectToHTTPS bool `default:"true"`
2121
ListenAddr string `default:""`
2222
Port int `default:"443"`
2323
CertFile string `default:""`
2424
CertKey string `default:""`
2525
LetsEncrypt struct {
26-
Enabled *bool `default:"false"`
27-
AcceptTOS *bool `default:"false"`
26+
Enabled bool `default:"false"`
27+
AcceptTOS bool `default:"false"`
2828
Cache string `default:"data/certs"`
2929
Hosts []string
3030
}

Diff for: router/router.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co
4141
g.Use(gin.LoggerWithFormatter(logFormatter), gin.Recovery(), gerror.Handler(), location.Default())
4242
g.NoRoute(gerror.NotFound())
4343

44-
if conf.Server.SSL.Enabled != nil && conf.Server.SSL.RedirectToHTTPS != nil && *conf.Server.SSL.Enabled && *conf.Server.SSL.RedirectToHTTPS {
44+
if conf.Server.SSL.Enabled && conf.Server.SSL.RedirectToHTTPS {
4545
g.Use(func(ctx *gin.Context) {
4646
if ctx.Request.TLS != nil {
4747
ctx.Next()

Diff for: runner/runner.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func Run(router http.Handler, conf *config.Configuration) error {
2828
defer httpListener.Close()
2929

3030
s := &http.Server{Handler: router}
31-
if *conf.Server.SSL.Enabled {
32-
if *conf.Server.SSL.LetsEncrypt.Enabled {
31+
if conf.Server.SSL.Enabled {
32+
if conf.Server.SSL.LetsEncrypt.Enabled {
3333
applyLetsEncrypt(s, conf)
3434
}
3535

@@ -93,7 +93,7 @@ func getNetworkAndAddr(listenAddr string, port int) (string, string) {
9393

9494
func applyLetsEncrypt(s *http.Server, conf *config.Configuration) {
9595
certManager := autocert.Manager{
96-
Prompt: func(tosURL string) bool { return *conf.Server.SSL.LetsEncrypt.AcceptTOS },
96+
Prompt: func(tosURL string) bool { return conf.Server.SSL.LetsEncrypt.AcceptTOS },
9797
HostPolicy: autocert.HostWhitelist(conf.Server.SSL.LetsEncrypt.Hosts...),
9898
Cache: autocert.DirCache(conf.Server.SSL.LetsEncrypt.Cache),
9999
}

0 commit comments

Comments
 (0)