fix: adjust some code structure to satisfy linter
This commit is contained in:
parent
7b30a04933
commit
4060ec09c4
7 changed files with 38 additions and 31 deletions
|
@ -22,14 +22,14 @@ type AppSettings struct {
|
|||
|
||||
//nolint:lll // ignore line length
|
||||
type CLI struct {
|
||||
ServerAddress string `name:"listen-address" env:"GEOIP_LISTEN_ADDRESS" help:"Address to use for the api server" default:"${default_address}"`
|
||||
DataFile string `name:"data-file" env:"GEOIP_DATA_FILE" help:"path to data file" default:"${default_file_path}"`
|
||||
DataURL string `name:"data-url" env:"GEOIP_DATA_URL" help:"url to data file"`
|
||||
CacheTTL string `name:"cache-ttl" env:"GEOIP_CACHE_TTL" help:"ttl for response cache" default:"${default_cache_ttl}"`
|
||||
ReadHeaderTimeout string `name:"read-header-timeout" env:"GEOIP_READ_HEADER_TIMEOUT" help:"timeout for reading http header" default:"${default_read_header_timeout}"`
|
||||
EnableExporter bool `name:"enable-exporter" env:"GEOIP_ENABLE_EXPORTER" help:"enable prometheus exporter" default:"${default_enable_exporter}"`
|
||||
ExporterAddress string `name:"exporter-address" env:"GEOIP_EXPORTER_ADDRESS" help:"Address to use for the prometheus metrics server" default:"${default_exporter_address}"`
|
||||
ExporterInterval string `name:"exporter-interval" env:"GEOIP_EXPORTER_INTERVAL" help:"Interval to scrape the new metrics data" default:"${default_exporter_interval}"`
|
||||
ServerAddress string `name:"listen-address" env:"GEOIP_LISTEN_ADDRESS" help:"Address to use for the api server" default:"${default_address}"`
|
||||
DataFile string `name:"data-file" env:"GEOIP_DATA_FILE" help:"path to data file" default:"${default_file_path}"`
|
||||
DataURL string `name:"data-url" env:"GEOIP_DATA_URL" help:"url to data file"`
|
||||
CacheTTL string `name:"cache-ttl" env:"GEOIP_CACHE_TTL" help:"ttl for response cache" default:"${default_cache_ttl}"`
|
||||
ReadHeaderTimeout string `name:"read-header-timeout" env:"GEOIP_READ_HEADER_TIMEOUT" help:"timeout for reading http header" default:"${default_read_header_timeout}"`
|
||||
EnableExporter bool `name:"enable-exporter" env:"GEOIP_ENABLE_EXPORTER" help:"enable prometheus exporter" default:"${default_enable_exporter}"`
|
||||
ExporterAddress string `name:"exporter-address" env:"GEOIP_EXPORTER_ADDRESS" help:"Address to use for the prometheus metrics server" default:"${default_exporter_address}"`
|
||||
ExporterInterval string `name:"exporter-interval" env:"GEOIP_EXPORTER_INTERVAL" help:"Interval to scrape the new metrics data" default:"${default_exporter_interval}"`
|
||||
}
|
||||
|
||||
func (c *CLI) Parse() (*AppSettings, error) {
|
||||
|
|
|
@ -40,7 +40,10 @@ func (c *Context) Download() error {
|
|||
}
|
||||
return err
|
||||
}
|
||||
defer resp.Close()
|
||||
if err = resp.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
return ErrInvalidURL
|
||||
}
|
||||
|
@ -50,19 +53,19 @@ func (c *Context) Download() error {
|
|||
if resp.StatusCode != http.StatusOK {
|
||||
return errors.New(resp.RawResponse.Status)
|
||||
}
|
||||
resp.Close()
|
||||
|
||||
resp, err = req.Get(c.Link, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Close()
|
||||
|
||||
var filesize int64
|
||||
if resp.RawResponse.ContentLength > -1 {
|
||||
filesize = resp.RawResponse.ContentLength
|
||||
}
|
||||
|
||||
destFile, err := os.OpenFile(c.Filename, os.O_CREATE|os.O_WRONLY, 0644)
|
||||
destFile, err := os.OpenFile(c.Filename, os.O_CREATE|os.O_WRONLY, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -58,7 +58,10 @@ func TestDownload(t *testing.T) {
|
|||
|
||||
t.Run("CertificateError", func(t *testing.T) {
|
||||
// This test assumes a self-signed certificate or similar issue. This is hard to simulate in a unit test.
|
||||
ctx := downloader.NewContext("test_cert_error.txt", "https://self-signed.badssl.com/") // Example URL that can be used
|
||||
ctx := downloader.NewContext(
|
||||
"test_cert_error.txt",
|
||||
"https://self-signed.badssl.com/", // Example URL that can be used
|
||||
)
|
||||
|
||||
if err := ctx.Download(); err == nil || err.Error() != "certificate from unknown authority" {
|
||||
t.Errorf("expected certificate from unknown authority error, got %v", err)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package exporter
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
@ -95,7 +95,7 @@ func (m *Metrics) collectCurrentlyCachedMetric() {
|
|||
func (m *Metrics) collectDatabaseTimestampMetric() {
|
||||
timestamp, err := m.exporter.database.Timestamp()
|
||||
if err != nil {
|
||||
log.Printf("failed to read file timestamp: %v", err)
|
||||
slog.Warn("failed to read file timestamp", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue