mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
chanced it into it's own package
This commit is contained in:
parent
d2b3994f26
commit
223f472f5b
3 changed files with 44 additions and 38 deletions
33
cmd/main.go
Normal file
33
cmd/main.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/RaaLabs/steward"
|
||||
)
|
||||
|
||||
func main() {
|
||||
nodeName := flag.String("node", "0", "some unique string to identify this Edge unit")
|
||||
brokerAddress := flag.String("brokerAddress", "0", "the address of the message broker")
|
||||
modePublisher := flag.Bool("modePublisher", false, "set to true if it should be able to publish")
|
||||
modeSubscriber := flag.Bool("modeSubscriber", false, "set to true if it should be able to subscribe")
|
||||
flag.Parse()
|
||||
|
||||
s, err := steward.NewServer(*brokerAddress, *nodeName)
|
||||
if err != nil {
|
||||
log.Printf("error: failed to connect to broker: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *modePublisher {
|
||||
go s.RunPublisher()
|
||||
}
|
||||
|
||||
if *modeSubscriber {
|
||||
go s.RunSubscriber()
|
||||
}
|
||||
|
||||
select {}
|
||||
}
|
|
@ -1,13 +1,11 @@
|
|||
// Notes:
|
||||
package main
|
||||
package steward
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -62,9 +60,16 @@ type server struct {
|
|||
}
|
||||
|
||||
// newServer will prepare and return a server type
|
||||
func newServer(brokerAddress string) (*server, error) {
|
||||
func NewServer(brokerAddress string, nodeName string) (*server, error) {
|
||||
conn, err := nats.Connect(brokerAddress, nil)
|
||||
if err != nil {
|
||||
log.Printf("error: nats.Connect failed: %v\n", err)
|
||||
}
|
||||
|
||||
return &server{
|
||||
processes: make(map[node]process),
|
||||
thisNodeName: nodeName,
|
||||
natsConn: conn,
|
||||
processes: make(map[node]process),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -220,35 +225,3 @@ func gobEncodePayload(m Message) ([]byte, error) {
|
|||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
node := flag.String("node", "0", "some unique string to identify this Edge unit")
|
||||
modePublisher := flag.Bool("modePublisher", false, "set to true if it should be able to publish")
|
||||
modeSubscriber := flag.Bool("modeSubscriber", false, "set to true if it should be able to subscribe")
|
||||
flag.Parse()
|
||||
|
||||
s, err := newServer("localhost")
|
||||
if err != nil {
|
||||
log.Printf("error: failed to connect to broker: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
s.thisNodeName = *node
|
||||
|
||||
// Create a connection to nats server
|
||||
s.natsConn, err = nats.Connect("localhost", nil)
|
||||
if err != nil {
|
||||
log.Printf("error: nats.Connect failed: %v\n", err)
|
||||
}
|
||||
defer s.natsConn.Close()
|
||||
|
||||
if *modePublisher {
|
||||
go s.RunPublisher()
|
||||
}
|
||||
|
||||
if *modeSubscriber {
|
||||
go s.RunSubscriber()
|
||||
}
|
||||
|
||||
select {}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package steward
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
|
Loading…
Reference in a new issue