Skip to content

Commit 60c5ecf

Browse files
authored
Merge pull request #26 from prplecake/ua-version
2 parents 03b66ad + 92b5e78 commit 60c5ecf

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
${{ runner.os }}-go-
2929
3030
- name: Build
31-
run: go build -v ./...
31+
run: make build
3232

3333
#- name: Test
3434
# run: go test -v ./...

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ jobs:
2323
github_token: ${{ secrets.GITHUB_TOKEN }}
2424
goos: ${{ matrix.goos }}
2525
goarch: ${{ matrix.goarch }}
26+
build_command: "make"
27+
build_flags: "build"
2628
extra_files: LICENSE README.md gof.example.yaml

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
VERSION := $(shell git describe --tags --abbrev=0)
2+
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
3+
4+
GOLDFLAGS += -X main.Version=$(VERSION)
5+
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
6+
GOFLAGS = -ldflags "$(GOLDFLAGS)"
7+
8+
run: build
9+
./gof
10+
11+
dry-run: build
12+
./gof -dry-run
13+
14+
build:
15+
go build -o gof $(GOFLAGS) .

config.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56
"os"
67
"time"
78

89
"gopkg.in/yaml.v2"
910
)
1011

11-
const (
12-
HttpUserAgent = "gof"
13-
)
14-
1512
var (
13+
Version string
14+
Buildtime string
1615
configFile string
1716
)
1817

@@ -28,6 +27,13 @@ type config struct {
2827
Accounts []account
2928
LastUpdated time.Time
3029
HttpConfig httpConfig
30+
Meta meta
31+
}
32+
33+
type meta struct {
34+
Name string
35+
Version string
36+
Buildtime string
3137
}
3238

3339
type account struct {
@@ -56,7 +62,11 @@ func readConfig(fileName string) *config {
5662
if debug {
5763
log.Printf("Config:\n\n%v", config)
5864
}
59-
config.HttpConfig.UserAgent = HttpUserAgent
65+
config.Meta.Name = "gof"
66+
config.Meta.Version = Version
67+
config.Meta.Buildtime = Buildtime
68+
config.HttpConfig.UserAgent = fmt.Sprintf("%s/%s",
69+
config.Meta.Name, config.Meta.Version)
6070
return config
6171
}
6272

gof.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func main() {
3636

3737
log.Println("gof starting up...")
3838
conf = readConfig(configFile)
39+
log.Printf("Version: %s\n", conf.Meta.Version)
40+
log.Printf("Build time: %s\n", conf.Meta.Buildtime)
3941

4042
var tpls = make(map[string]*template.Template)
4143
var formats = make(map[string]string)

0 commit comments

Comments
 (0)