Initial commit.
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Exclude binary files
|
||||
test-version
|
||||
13
build.sh
Executable file
13
build.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION=$(git describe --tags --always 2>/dev/null)
|
||||
|
||||
if [ ! -z "$VERSION" ]; then
|
||||
echo "Building version: $VERSION"
|
||||
LDFLAGS="-ldflags \"-X main.Version=$VERSION\""
|
||||
else
|
||||
echo "Building without version information"
|
||||
LDFLAGS=""
|
||||
fi
|
||||
|
||||
go build $LDFLAGS -o test-version .
|
||||
9
main.go
Normal file
9
main.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, World!")
|
||||
|
||||
fmt.Printf("The version is %s\n", Version)
|
||||
}
|
||||
3
version.go
Normal file
3
version.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
var Version string = "undefined"
|
||||
Reference in New Issue
Block a user