Skip to content

Commit 4b48936

Browse files
authored
Fix hot reload and gosec issues (#7)
1 parent 1c9a596 commit 4b48936

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

cmd/root.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var (
3333
cfg config.Config
3434
appContext *utils.AppContext
3535
scheduler *gocron.Scheduler
36-
configChangeCallback func()
3736

3837
rootCmd = &cobra.Command{
3938
Use: "k8s-shredder",
@@ -122,12 +121,10 @@ func discoverConfig() {
122121
viper.WatchConfig()
123122
viper.OnConfigChange(func(e fsnotify.Event) {
124123
log.Infof("Configuration file `%s` changed, attempting to reload", e.Name)
125-
if configChangeCallback != nil {
126-
reset()
127-
parseConfig()
128-
configChangeCallback()
129-
run(&cobra.Command{}, []string{})
130-
}
124+
reset()
125+
parseConfig()
126+
appContext.Config = cfg
127+
run(&cobra.Command{}, []string{})
131128
})
132129
}
133130

pkg/metrics/types.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package metrics
1414
import (
1515
"fmt"
1616
"net/http"
17+
"time"
1718

1819
log "github.com/sirupsen/logrus"
1920

@@ -63,8 +64,13 @@ func serve(port int) error {
6364
}
6465
})
6566

67+
server := &http.Server{
68+
Addr: fmt.Sprintf(":%d", port),
69+
ReadHeaderTimeout: 3 * time.Second,
70+
}
71+
6672
go func() {
67-
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
73+
log.Fatal(server.ListenAndServe(), nil)
6874
}()
6975
return nil
7076
}

0 commit comments

Comments
 (0)