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

pace / bricks / 12827718001

17 Jan 2025 10:57AM UTC coverage: 56.909% (-0.3%) from 57.237%
12827718001

Pull #384

github

monstermunchkin
Satisfy linters
Pull Request #384: Extend linting

478 of 946 new or added lines in 109 files covered. (50.53%)

133 existing lines in 53 files now uncovered.

5667 of 9958 relevant lines covered (56.91%)

21.51 hits per line

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

92.31
/http/server.go
1
// Copyright © 2018 by PACE Telematics GmbH. All rights reserved.
2

3
package http
4

5
import (
6
        golog "log"
7
        "net/http"
8
        "strconv"
9
        "time"
10

11
        "github.com/caarlos0/env/v10"
12

13
        "github.com/pace/bricks/maintenance/log"
14
)
15

16
func init() {
1✔
17
        parseConfig()
1✔
18
}
1✔
19

20
type config struct {
21
        Addr           string        `env:"ADDR"`
22
        Port           int           `env:"PORT" envDefault:"3000"`
23
        Environment    string        `env:"ENVIRONMENT" envDefault:"edge"`
24
        MaxHeaderBytes int           `env:"MAX_HEADER_BYTES" envDefault:"1048576"` // 1MB
25
        IdleTimeout    time.Duration `env:"IDLE_TIMEOUT" envDefault:"1h"`
26
        ReadTimeout    time.Duration `env:"READ_TIMEOUT" envDefault:"60s"`
27
        WriteTimeout   time.Duration `env:"WRITE_TIMEOUT" envDefault:"60s"`
28
}
29

30
// addrOrPort returns ADDR if it is defined, otherwise PORT is used.
31
func (cfg config) addrOrPort() string {
2✔
32
        if cfg.Addr != "" {
3✔
33
                return cfg.Addr
1✔
34
        }
1✔
35

36
        return ":" + strconv.Itoa(cfg.Port)
1✔
37
}
38

39
var cfg config
40

41
func parseConfig() {
5✔
42
        if err := env.Parse(&cfg); err != nil {
5✔
UNCOV
43
                log.Fatalf("Failed to parse server environment: %v", err)
×
44
        }
×
45
}
46

47
// Server returns a http.Server configured using environment variables,
48
// following https://12factor.net/.
49
func Server(handler http.Handler) *http.Server {
2✔
50
        return &http.Server{
2✔
51
                Addr:           cfg.addrOrPort(),
2✔
52
                Handler:        handler,
2✔
53
                ReadTimeout:    cfg.ReadTimeout,
2✔
54
                WriteTimeout:   cfg.WriteTimeout,
2✔
55
                MaxHeaderBytes: cfg.MaxHeaderBytes,
2✔
56
                IdleTimeout:    cfg.IdleTimeout,
2✔
57
                ErrorLog:       golog.New(log.Logger(), "[http.Server] ", 0),
2✔
58
        }
2✔
59
}
2✔
60

61
// Environment returns the name of the current server environment.
62
func Environment() string {
2✔
63
        return cfg.Environment
2✔
64
}
2✔
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