1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-05 14:56:49 +00:00

added version and ldflags example to set it

This commit is contained in:
postmannen 2021-09-10 10:04:25 +02:00
parent 6bdbc232b7
commit 69f6287ee8
3 changed files with 14 additions and 3 deletions

View file

@ -13,6 +13,12 @@ import (
"github.com/RaaLabs/steward"
)
// Use ldflags to set version
// env CONFIGFOLDER=./etc/ go run -ldflags "-X main.version=v0.1.10" --race ./cmd/steward/.
// or
// env GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=v0.1.10" -o steward
var version string
func main() {
// defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
// defer profile.Start(profile.TraceProfile, profile.ProfilePath(".")).Stop()
@ -33,7 +39,7 @@ func main() {
}
s, err := steward.NewServer(c)
s, err := steward.NewServer(c, version)
if err != nil {
log.Printf("%v\n", err)
os.Exit(1)

View file

@ -49,10 +49,12 @@ type server struct {
errorKernel *errorKernel
// metric exporter
metrics *metrics
// Version of package
version string
}
// newServer will prepare and return a server type
func NewServer(c *Configuration) (*server, error) {
func NewServer(c *Configuration, version string) (*server, error) {
// Set up the main background context.
ctx, cancel := context.WithCancel(context.Background())
@ -166,6 +168,7 @@ func NewServer(c *Configuration) (*server, error) {
processes: newProcesses(ctx, metrics),
newMessagesCh: make(chan []subjectAndMessage),
metrics: metrics,
version: version,
}
// Create the default data folder for where subscribers should
@ -191,6 +194,8 @@ func NewServer(c *Configuration) (*server, error) {
// if there is publisher process for a given message subject, and
// if it does not exist it will spawn one.
func (s *server) Start() {
fmt.Printf(" * VERSION = %+v\n", s.version)
// Start the error kernel that will do all the error handling
// that is not done within a process.
s.errorKernel = newErrorKernel(s.ctx)

View file

@ -67,7 +67,7 @@ func TestStewardServer(t *testing.T) {
StartSubREQTailFile: true,
// StartSubREQToSocket: flagNodeSlice{OK: true, Values: []Node{"*"}},
}
stewardServer, err := NewServer(conf)
stewardServer, err := NewServer(conf, "test")
if err != nil {
t.Fatalf(" * failed: could not start the Steward instance %v\n", err)
}