diff --git a/api.go b/api.go index 7b5b34e..026e59d 100644 --- a/api.go +++ b/api.go @@ -110,9 +110,9 @@ func (h *productsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Warnf("cannot parse available query to boolean: %s", err) w.WriteHeader(http.StatusInternalServerError) return - } else { - trx = h.db.Preload("Shop").Where(map[string]interface{}{"available": available}).Find(&products) } + + trx = h.db.Preload("Shop").Where(map[string]interface{}{"available": available}).Find(&products) } else { trx = h.db.Preload("Shop").Find(&products) } @@ -147,7 +147,7 @@ func (h *productHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // StartAPI to handle HTTP requests -func StartAPI(db *gorm.DB, config ApiConfig) error { +func StartAPI(db *gorm.DB, config APIConfig) error { router := mux.NewRouter().StrictSlash(true) router.Path("/health").HandlerFunc(handleHealth) @@ -164,7 +164,6 @@ func StartAPI(db *gorm.DB, config ApiConfig) error { log.Printf("starting API on %s", config.Address) if config.Certfile != "" && config.Keyfile != "" { return http.ListenAndServeTLS(config.Address, config.Certfile, config.Keyfile, router) - } else { - return http.ListenAndServe(config.Address, router) } + return http.ListenAndServe(config.Address, router) } diff --git a/config.go b/config.go index ddfd31e..9a9b986 100644 --- a/config.go +++ b/config.go @@ -10,7 +10,7 @@ import ( type Config struct { TwitterConfig `json:"twitter"` TelegramConfig `json:"telegram"` - ApiConfig `json:"api"` + APIConfig `json:"api"` AmazonConfig `json:"amazon"` URLs []string `json:"urls"` IncludeRegex string `json:"include_regex"` @@ -36,8 +36,8 @@ type TelegramConfig struct { EnableReplies bool `json:"enable_replies"` } -// ApiConfig to store HTTP API configuration -type ApiConfig struct { +// APIConfig to store HTTP API configuration +type APIConfig struct { Address string `json:"address"` Certfile string `json:"cert_file"` Keyfile string `json:"key_file"` @@ -91,7 +91,7 @@ func (c *Config) HasTelegram() bool { return c.TelegramConfig.Token != "" && (c.TelegramConfig.ChatID != 0 || c.TelegramConfig.ChannelName != "") } -// HasURL returns true when list of URLS has been configured +// HasURLs returns true when list of URLS has been configured func (c *Config) HasURLs() bool { return len(c.URLs) > 0 } diff --git a/main.go b/main.go index b23c421..b4b6bbb 100644 --- a/main.go +++ b/main.go @@ -117,7 +117,7 @@ func main() { // start the api if *api { - log.Fatal(StartAPI(db, config.ApiConfig)) + log.Fatal(StartAPI(db, config.APIConfig)) } // register notifiers