Skip to content

Commit

Permalink
Make binding the httpPost configurable (#232)
Browse files Browse the repository at this point in the history
* Make binding configurable

* Fix outputting the current choice

* Ping is very noisy - only print it when on debug

* Spelling
  • Loading branch information
kairichard committed Jul 22, 2019
1 parent 813a296 commit 97e54c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions cmd/slang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var SupportedRunModes = []string{"process", "httpPost"}

func main() {
runMode := flag.String("mode", SupportedRunModes[0], fmt.Sprintf("Choose run mode for operator: %s", SupportedRunModes))
bind := flag.String("bind", "localhost:0", "To which address httpPost should bind")
help := flag.Bool("h", false, "Show help")
flag.Parse()

Expand All @@ -37,7 +38,7 @@ func main() {
}

if !funk.ContainsString(SupportedRunModes, *runMode) {
log.Fatalf("invalid run mode: %s must be one of following %s", runMode, SupportedRunModes)
log.Fatalf("invalid run mode: %s must be one of following %s", *runMode, SupportedRunModes)
}

slBundle, err := readSlangBundleJSON(slangBundlePath)
Expand All @@ -54,7 +55,7 @@ func main() {

log.SetOperator(operator.Id(), operator.Name())

if err := run(operator, *runMode); err != nil {
if err := run(operator, *runMode, *bind); err != nil {
log.Fatal(err)
}

Expand All @@ -72,12 +73,12 @@ func readSlangBundleJSON(slBundlePath string) (*core.SlangBundle, error) {
return &slFile, err
}

func run(operator *core.Operator, mode string) error {
func run(operator *core.Operator, mode string, bind string) error {
switch mode {
case "process":
runProcess(operator)
case "httpPost":
runHttpPost(operator)
runHttpPost(operator, bind)
default:
log.Fatal("invalid or not implemented run mode: %s")
}
Expand All @@ -99,14 +100,14 @@ func run(operator *core.Operator, mode string) error {
func runProcess(operator *core.Operator) {
operator.Main().Out().Bufferize()
operator.Start()
log.Print("started")
log.Print("started as process mode")

if isQuasiTrigger(operator.Main().In()) {
operator.Main().In().Push(true)
}
}

func runHttpPost(operator *core.Operator) {
func runHttpPost(operator *core.Operator, bind string) {
inDef := operator.Main().In().Define()

r := mux.NewRouter()
Expand Down Expand Up @@ -135,10 +136,9 @@ func runHttpPost(operator *core.Operator) {

operator.Main().Out().Bufferize()
operator.Start()
log.Print("started")

log.Print("started as httpPost")
go func() {
log.Fatal(http.ListenAndServe("localhost:0", r))
log.Fatal(http.ListenAndServe(bind, r))
}()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func SetOperator(operatorId uuid.UUID, operatorName string) {
}

func Ping() {
logger.Print("ping")
logger.Debug("ping")
}

func Print(args ...interface{}) {
Expand Down

0 comments on commit 97e54c9

Please sign in to comment.