Skip to content

Commit

Permalink
feat: check if maxmind_license is set before updating db
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistTheNeil committed Oct 29, 2023
1 parent dd058cc commit dbd6ef2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/maxmind/Maxmind.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (m *DB) Close() error {
}

func (m *DB) Update() error {
if viper.GetString("MAXMIND_LICENSE") == "" {
return fmt.Errorf("Error: Can't update database when no license key is set (MAXMIND_LICENSE env var needs to be set)")
}
err := m.Close()
if err != nil {
fmt.Println("Failed to close maxmind database")
Expand Down
3 changes: 2 additions & 1 deletion internal/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func InitRouter() {
}
err := maxmind.GetInstance().Update()
if err != nil {
dto.Message = "error"
fmt.Println(err)
dto.Message = "error updating the maxmind database"
return c.JSON(http.StatusInternalServerError, dto)
}
dto.Message = "success"
Expand Down
5 changes: 4 additions & 1 deletion internal/signals/TrapSignals.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func Trap() {
switch <-signals {
case syscall.SIGUSR1:
fmt.Println("SIGUSR1 called. Updating maxmind db")
maxmind.GetInstance().Update()
err := maxmind.GetInstance().Update()
if err != nil {
fmt.Println(err)
}
}
}
}()
Expand Down

0 comments on commit dbd6ef2

Please sign in to comment.