diff --git a/cmd/steward/main.go b/cmd/steward/main.go index 2ed3f28..2761d1b 100644 --- a/cmd/steward/main.go +++ b/cmd/steward/main.go @@ -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) diff --git a/server.go b/server.go index f6ad0e6..47a1518 100644 --- a/server.go +++ b/server.go @@ -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) diff --git a/steward_test.go b/steward_test.go index 488f108..3996326 100644 --- a/steward_test.go +++ b/steward_test.go @@ -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) }