• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rm-hull / gps-routes-api / 14272299206

04 Apr 2025 07:00PM UTC coverage: 34.023% (-0.8%) from 34.774%
14272299206

push

github

web-flow
Bump golangci/golangci-lint-action from 6 to 7 (#19)

Bumps
[golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action)
from 6 to 7.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/golangci/golangci-lint-action/releases">golangci/golangci-lint-action's
releases</a>.</em></p>
<blockquote>
<h2>v7.0.0</h2>
<!-- raw HTML omitted -->
<h2>What's Changed</h2>
<h3>Changes</h3>
<ul>
<li>feat: golangci-lint v2 support by <a
href="https://github.com/ldez"><code>@​ldez</code></a> in <a
href="https://redirect.github.com/golangci/golangci-lint-action/pull/1198">golangci/golangci-lint-action#1198</a></li>
</ul>
<h3>Documentation</h3>
<ul>
<li>docs: update annotation permissions by <a
href="https://github.com/ldez"><code>@​ldez</code></a> in <a
href="https://redirect.github.com/golangci/golangci-lint-action/pull/1203">golangci/golangci-lint-action#1203</a></li>
<li>docs: fix checks permissions for annotations by <a
href="https://github.com/kema-dev"><code>@​kema-dev</code></a> in <a
href="https://redirect.github.com/golangci/golangci-lint-action/pull/1204">golangci/golangci-lint-action#1204</a></li>
</ul>
<h3>Dependencies</h3>
<ul>
<li>build(deps-dev): bump the dev-dependencies group with 3 updates by
<a href="https://github.com/dependabot"><code>@​dependabot</code></a> in
<a
href="https://redirect.github.com/golangci/golangci-lint-action/pull/1207">golangci/golangci-lint-action#1207</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/kema-dev"><code>@​kema-dev</code></a>
made their first contribution in <a
href="https://redirect.github.com/golangci/golangci-lint-action/pull/1204">golangci/golangci-lint-action#1204</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/golangci/golangci-lint-action/compare/v6.5.2...v7.0.0">https://github.com/golangci/golangci-lint-action/compare/v6.5.2...v7.0.0</a></p>
<h2>v6.5.2</h2>
<!-- raw HTML omitted -->
<h2>What's... (continued)

14 of 39 new or added lines in 5 files covered. (35.9%)

362 of 1064 relevant lines covered (34.02%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.23
/cmds/http_server.go
1
package cmds
2

3
import (
4
        "context"
5
        "log"
6
        "log/slog"
7
        "os"
8
        "runtime/debug"
9
        "time"
10

11
        "github.com/Depado/ginprom"
12
        ratelimit "github.com/JGLTechnologies/gin-rate-limit"
13
        "github.com/aurowora/compress"
14
        "github.com/earthboundkid/versioninfo/v2"
15
        "github.com/gin-contrib/cors"
16
        limits "github.com/gin-contrib/size"
17
        "github.com/gin-gonic/gin"
18
        "github.com/jackc/pgx/v5/stdlib"
19
        sloggin "github.com/samber/slog-gin"
20
        healthcheck "github.com/tavsec/gin-healthcheck"
21
        "github.com/tavsec/gin-healthcheck/checks"
22
        hc_config "github.com/tavsec/gin-healthcheck/config"
23
        cachecontrol "go.eigsys.de/gin-cachecontrol/v2"
24

25
        "github.com/rm-hull/gps-routes-api/db"
26
        "github.com/rm-hull/gps-routes-api/middlewares"
27
        "github.com/rm-hull/gps-routes-api/repositories"
28
        "github.com/rm-hull/gps-routes-api/routes"
29
        "github.com/rm-hull/gps-routes-api/services"
30
)
31

32
func NewHttpServer() {
1✔
33

1✔
34
        // Connect to Postgres
1✔
35
        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
1✔
36
        defer cancel()
1✔
37

1✔
38
        dbConfig := db.ConfigFromEnv()
1✔
39
        pool, err := db.NewDBPool(ctx, dbConfig)
1✔
40
        if err != nil {
1✔
41
                log.Fatalf("failed to create database pool: %v", err)
×
42
        }
×
43
        defer pool.Close()
1✔
44

1✔
45
        engine := gin.New()
1✔
46
        logger := createLogger()
1✔
47

1✔
48
        prometheus := ginprom.New(
1✔
49
                ginprom.Engine(engine),
1✔
50
                ginprom.Namespace("gps_routes"),
1✔
51
                ginprom.Subsystem("api"),
1✔
52
        )
1✔
53

1✔
54
        rlStore := ratelimit.InMemoryStore(&ratelimit.InMemoryOptions{
1✔
55
                Rate:  time.Second,
1✔
56
                Limit: 5,
1✔
57
        })
1✔
58
        rateLimiter := ratelimit.RateLimiter(rlStore, &ratelimit.Options{
1✔
59
                ErrorHandler: func(c *gin.Context, info ratelimit.Info) {
1✔
60
                        c.JSON(429, gin.H{
×
61
                                "error":   "Too many requests",
×
62
                                "message": "Try again in " + time.Until(info.ResetTime).String(),
×
63
                        })
×
64
                },
×
65
                KeyFunc: func(c *gin.Context) string {
1✔
66
                        return c.ClientIP()
1✔
67
                },
1✔
68
        })
69

70
        engine.Use(
1✔
71
                sloggin.NewWithConfig(logger, sloggin.Config{
1✔
72
                        WithSpanID:  true,
1✔
73
                        WithTraceID: true,
1✔
74
                        Filters: []sloggin.Filter{
1✔
75
                                sloggin.IgnorePath("/healthz", "/metrics"),
1✔
76
                        }}),
1✔
77
                gin.Recovery(),
1✔
78
                cors.Default(),
1✔
79
                middlewares.ErrorHandler(),
1✔
80
                compress.Compress(),
1✔
81
                limits.RequestSizeLimiter(10*1024),
1✔
82
                cachecontrol.New(cachecontrol.CacheAssetsForeverPreset),
1✔
83
                prometheus.Instrument(),
1✔
84
                rateLimiter,
1✔
85
        )
1✔
86

1✔
87
        db := stdlib.OpenDB(*pool.Config().ConnConfig)
1✔
88
        defer func() {
1✔
NEW
89
                if err := db.Close(); err != nil {
×
NEW
90
                        log.Printf("failed to close database connection: %v", err)
×
NEW
91
                }
×
92
        }()
93
        err = healthcheck.New(engine, hc_config.DefaultConfig(), []checks.Check{
1✔
94
                checks.SqlCheck{Sql: db},
1✔
95
        })
1✔
96
        if err != nil {
1✔
97
                log.Fatalf("failed to initialize healthcheck: %v", err)
×
98
        }
×
99

100
        pg := repositories.NewPostgresRouteRepository(pool, dbConfig.Schema)
1✔
101
        repo := repositories.NewCachedRepository(prometheus, pg)
1✔
102
        service := services.NewRoutesService(repo)
1✔
103

1✔
104
        router := routes.NewRouterWithGinEngine(engine, routes.ApiHandleFunctions{
1✔
105
                RoutesAPI: routes.RoutesAPI{
1✔
106
                        Service: service,
1✔
107
                },
1✔
108
        })
1✔
109

1✔
110
        logger.
1✔
111
                With("version", versioninfo.Short()).
1✔
112
                Info("Server started")
1✔
113

1✔
114
        err = router.Run(":8080")
1✔
115
        logger.
1✔
116
                With("error", err).
1✔
117
                With("stack", string(debug.Stack())).
1✔
118
                Error("Unhandled/unexpected crash")
1✔
119
}
120

121
func createLogger() *slog.Logger {
1✔
122
        if gin.IsDebugging() {
2✔
123
                return slog.New(slog.NewTextHandler(os.Stdout, nil))
1✔
124
        }
1✔
125

126
        return slog.New(slog.NewJSONHandler(os.Stdout, nil))
×
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc