Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webservice
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DevOps (Lecture FB VI)
webservice
Commits
09fd2dfb
Commit
09fd2dfb
authored
1 year ago
by
gjahn
Browse files
Options
Downloads
Patches
Plain Diff
Allow to set version during build time
parent
120ca78d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+1
-0
1 addition, 0 deletions
Makefile
README.md
+5
-3
5 additions, 3 deletions
README.md
configuration/config.go
+6
-2
6 additions, 2 deletions
configuration/config.go
with
12 additions
and
5 deletions
Makefile
+
1
−
0
View file @
09fd2dfb
...
...
@@ -37,6 +37,7 @@ $(BIN_DIR)/artifact.bin:
cd
$(
SRC_DIR
)
\
&&
go build
\
-o
$(
@
)
\
-ldflags
"-X webservice/configuration.version=0.0.1"
\
$(
SRC_DIR
)
/
*
.go
.PHONY
:
build-linux
...
...
This diff is collapsed.
Click to expand it.
README.md
+
5
−
3
View file @
09fd2dfb
...
...
@@ -24,9 +24,11 @@ information checkout the [configuration code](./configuration/config.go).
3.
Execute unit tests:
`go test -race -v ./...`
4.
Build artifact:
`go build -o ./artifact.bin ./*.go`
To build for another platform, set
`GOOS`
and
`GOARCH`
. To yield a static binary (fully
self-contained, no dynamic linking) set
`CGO_ENABLED=0`
. For more details, please refer
to the
[
Makefile
](
./Makefile
)
.
To build for another platform, set
`GOOS`
and
`GOARCH`
. To yield a static
binary (fully self-contained, no dynamic linking) set
`CGO_ENABLED=0`
.
To set a version during build time, add the following CLI option
`-ldflags "-X webservice/configuration.version=${VERSION}"`
.
For more information, please refer to the
[
Makefile
](
./Makefile
)
.
#### Run:
...
...
This diff is collapsed.
Click to expand it.
configuration/config.go
+
6
−
2
View file @
09fd2dfb
...
...
@@ -12,9 +12,11 @@ import (
const
BODY_SIZE_LIMIT
=
32
*
1024
*
1024
// 32 MB, in bytes
var
version
string
=
"n/a"
type
Config
struct
{
Version
string
`env:"VERSION" envDefault:"N/A"`
Version
string
LogLevel
string
`env:"LOG_LEVE" envDefault:"error"`
...
...
@@ -31,7 +33,9 @@ type Config struct {
func
New
()
(
*
Config
,
error
){
cfg
:=
Config
{}
cfg
:=
Config
{
Version
:
version
,
}
if
err
:=
configParser
.
Parse
(
&
cfg
);
err
!=
nil
{
return
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment