Skip to content

Commit 21ca8c1

Browse files
authored
Fix uninitialized api (#38)
* Fix package path for build variables. * fail startup if API client is not initialized. * set default values for build parameters.
1 parent b536722 commit 21ca8c1

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ RUN export VERSION=$(cat version) && \
2121
export BRANCH=$(cat branch) && \
2222
export REVISION=$(cat revision) && \
2323
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo \
24-
-ldflags="-w -s -X github.com/anas-aso/ssllabs_exporter/build.Branch=${BRANCH} -X github.com/anas-aso/ssllabs_exporter/build.Revision=${REVISION} -X github.com/anas-aso/ssllabs_exporter/build.Version=${VERSION}" \
24+
-ldflags="-w -s -X github.com/anas-aso/ssllabs_exporter/internal/build.Branch=${BRANCH} -X github.com/anas-aso/ssllabs_exporter/internal/build.Revision=${REVISION} -X github.com/anas-aso/ssllabs_exporter/internal/build.Version=${VERSION}" \
2525
-o /workdir/ssllabs_exporter
2626

2727
# Create a "nobody" user for the next image

internal/build/build.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import "runtime"
44

55
// build parameters
66
var (
7-
Branch string
7+
Branch = "dev"
88
GoVersion = runtime.Version()
9-
Revision string
10-
Version string
9+
Revision = "n/a"
10+
Version = "n/a"
1111
)

internal/ssllabs/analyze.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ var api *ssllabsApi.API
3030

3131
func init() {
3232
api, _ = ssllabsApi.NewAPI("ssllabs-exporter", build.Version)
33+
if api == nil {
34+
panic("failed to initialize API client. this should never happen!")
35+
}
3336
}
3437

3538
// Analyze executes the SSL test HTTP requests

0 commit comments

Comments
 (0)