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:
parent
6bdbc232b7
commit
69f6287ee8
3 changed files with 14 additions and 3 deletions
|
@ -13,6 +13,12 @@ import (
|
||||||
"github.com/RaaLabs/steward"
|
"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() {
|
func main() {
|
||||||
// defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
|
// defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
|
||||||
// defer profile.Start(profile.TraceProfile, 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 {
|
if err != nil {
|
||||||
log.Printf("%v\n", err)
|
log.Printf("%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -49,10 +49,12 @@ type server struct {
|
||||||
errorKernel *errorKernel
|
errorKernel *errorKernel
|
||||||
// metric exporter
|
// metric exporter
|
||||||
metrics *metrics
|
metrics *metrics
|
||||||
|
// Version of package
|
||||||
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// newServer will prepare and return a server type
|
// 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.
|
// Set up the main background context.
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
@ -166,6 +168,7 @@ func NewServer(c *Configuration) (*server, error) {
|
||||||
processes: newProcesses(ctx, metrics),
|
processes: newProcesses(ctx, metrics),
|
||||||
newMessagesCh: make(chan []subjectAndMessage),
|
newMessagesCh: make(chan []subjectAndMessage),
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
|
version: version,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the default data folder for where subscribers should
|
// 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 there is publisher process for a given message subject, and
|
||||||
// if it does not exist it will spawn one.
|
// if it does not exist it will spawn one.
|
||||||
func (s *server) Start() {
|
func (s *server) Start() {
|
||||||
|
fmt.Printf(" * VERSION = %+v\n", s.version)
|
||||||
|
|
||||||
// Start the error kernel that will do all the error handling
|
// Start the error kernel that will do all the error handling
|
||||||
// that is not done within a process.
|
// that is not done within a process.
|
||||||
s.errorKernel = newErrorKernel(s.ctx)
|
s.errorKernel = newErrorKernel(s.ctx)
|
||||||
|
|
|
@ -67,7 +67,7 @@ func TestStewardServer(t *testing.T) {
|
||||||
StartSubREQTailFile: true,
|
StartSubREQTailFile: true,
|
||||||
// StartSubREQToSocket: flagNodeSlice{OK: true, Values: []Node{"*"}},
|
// StartSubREQToSocket: flagNodeSlice{OK: true, Values: []Node{"*"}},
|
||||||
}
|
}
|
||||||
stewardServer, err := NewServer(conf)
|
stewardServer, err := NewServer(conf, "test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(" * failed: could not start the Steward instance %v\n", err)
|
t.Fatalf(" * failed: could not start the Steward instance %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue