Skip to content

Commit 4b2de87

Browse files
committed
refactor: reorganize buildinfo and update dependencies
2 parents ea17e19 + 9c12448 commit 4b2de87

37 files changed

+75
-1347
lines changed

buildinfo/build.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package buildinfo
2+
3+
var domain string
4+
var mainPath string
5+
6+
// git rev-parse HEAD
7+
// git describe --always --abbrev=7 --dirty
8+
var (
9+
// commitID, git commit id
10+
commitID string
11+
12+
// buildTime, build time, rfc3339
13+
buildTime string
14+
)
15+
16+
// git describe --tags --abbrev=0
17+
// git tag --sort=committerdate | tail -n 1
18+
var (
19+
// version, git tag
20+
version string
21+
22+
// project, project name
23+
project string
24+
)
25+
26+
var (
27+
// release tag
28+
release string
29+
)

buildinfo/version.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,6 @@ import (
1111
v "github.com/pubgo/funk/v2/buildinfo/version"
1212
)
1313

14-
func CommitID() string { return commitID }
15-
func MainPath() string { return mainPath }
16-
func Version() string { return version }
17-
func ReleaseVersion() string { return release }
18-
func BuildTime() string { return buildTime }
19-
func Project() string { return project }
20-
func Domain() string { return domain }
21-
22-
var domain string
23-
var mainPath string
24-
25-
// git rev-parse HEAD
26-
// git describe --always --abbrev=7 --dirty
27-
var (
28-
// commitID, git commit id
29-
commitID string
30-
31-
// buildTime, build time, rfc3339
32-
buildTime string
33-
)
34-
35-
// git describe --tags --abbrev=0
36-
// git tag --sort=committerdate | tail -n 1
37-
var (
38-
// version, git tag
39-
version string
40-
41-
// project, project name
42-
project string
43-
)
44-
45-
var (
46-
// release tag
47-
release string
48-
)
49-
5014
func init() {
5115
bi, ok := debug.ReadBuildInfo()
5216
if !ok {

cmds/testmain/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/urfave/cli/v3"
1111

1212
"github.com/pubgo/funk/v2/assert"
13-
"github.com/pubgo/funk/v2/buildinfo"
13+
"github.com/pubgo/funk/v2/buildinfo/version"
1414
"github.com/pubgo/funk/v2/cliutils"
1515
"github.com/pubgo/funk/v2/cmds/versioncmd"
1616
"github.com/pubgo/funk/v2/ctxutil"
@@ -22,7 +22,7 @@ func main() {
2222
Suggest: true,
2323
UseShortOptionHandling: true,
2424
ShellComplete: cli.DefaultAppComplete,
25-
Version: buildinfo.Version(),
25+
Version: version.Version(),
2626
Commands: []*cli.Command{
2727
versioncmd.New(),
2828
},

cmds/versioncmd/cmd.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/urfave/cli/v3"
8-
9-
"github.com/pubgo/funk/v2/buildinfo"
7+
"github.com/pubgo/funk/v2/buildinfo/version"
108
"github.com/pubgo/funk/v2/pretty"
119
"github.com/pubgo/funk/v2/recovery"
1210
"github.com/pubgo/funk/v2/running"
11+
"github.com/urfave/cli/v3"
1312
)
1413

1514
func New() *cli.Command {
1615
return &cli.Command{
1716
Name: "version",
18-
Usage: fmt.Sprintf("%s version info", buildinfo.Project()),
17+
Usage: fmt.Sprintf("%s version info", version.Project()),
1918
Commands: []*cli.Command{
2019
{
2120
Name: "validate",

component/cloudevent/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/nats-io/nats.go/jetstream"
1212
ants "github.com/panjf2000/ants/v2"
1313
"github.com/pubgo/funk/v2/assert"
14-
"github.com/pubgo/funk/v2/buildinfo"
1514
"github.com/pubgo/funk/v2/buildinfo/version"
1615
"github.com/pubgo/funk/v2/component/lifecycle"
1716
"github.com/pubgo/funk/v2/component/natsclient"
@@ -138,7 +137,7 @@ func (c *Client) initConsumer() (r error) {
138137
// A streaming consumer can only have one corresponding job handler
139138
assert.If(c.consumers[streamName][consumerName] != nil, "consumer %s already exists", consumerName)
140139

141-
metadata := map[string]string{"version": fmt.Sprintf("%s/%s", buildinfo.Project(), buildinfo.Version())}
140+
metadata := map[string]string{"version": fmt.Sprintf("%s/%s", version.Project(), version.Version())}
142141
consumerCfg := jetstream.ConsumerConfig{
143142
Name: consumerName,
144143
Durable: consumerName,
File renamed without changes.
File renamed without changes.
File renamed without changes.

migrates/entmigrates/migrate.go renamed to component/entmigrates/migrate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"gorm.io/gorm/logger"
2323

2424
"github.com/pubgo/funk/v2/assert"
25-
"github.com/pubgo/funk/v2/buildinfo"
25+
"github.com/pubgo/funk/v2/buildinfo/version"
2626
"github.com/pubgo/funk/v2/config"
2727
"github.com/pubgo/funk/v2/errors"
2828
"github.com/pubgo/funk/v2/generic"
@@ -149,7 +149,7 @@ func %s() *entmigrates.Migration {
149149
DataMigrate: nil,
150150
}
151151
}
152-
`, name, name, fmt.Sprint(now.String(), " ", buildinfo.Version()), name))
152+
`, name, name, fmt.Sprint(now.String(), " ", version.Version()), name))
153153

154154
filename = filepath.Join(g.config.MigrationPath, fmt.Sprintf("%s.go", name))
155155
err = os.WriteFile(filename, []byte(genFile.GoString()), 0o644)

component/natsclient/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func New(p Param) *Client {
2828

2929
nc := assert.Must1(nats.Connect(p.Cfg.Url, func(o *nats.Options) error {
3030
o.AllowReconnect = true
31-
o.Name = fmt.Sprintf("%s/%s/%s", running.Hostname, running.Project, running.InstanceID)
31+
o.Name = fmt.Sprintf("%s/%s/%s", running.Hostname, running.Project(), running.InstanceID)
3232
return nil
3333
}))
3434

0 commit comments

Comments
 (0)