Skip to content

Commit

Permalink
refactor examples
Browse files Browse the repository at this point in the history
  • Loading branch information
andyxning committed Mar 15, 2019
1 parent abeb2b1 commit 4de27da
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion examples/nats-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const (
)

func usage() {
log.Fatalf("Usage: nats-bench [-s server (%s)] [--tls] [-np NUM_PUBLISHERS] [-ns NUM_SUBSCRIBERS] [-n NUM_MSGS] [-ms MESSAGE_SIZE] [-csv csvfile] <subject>\n", nats.DefaultURL)
log.Printf("Usage: nats-bench [-s server (%s)] [--tls] [-np NUM_PUBLISHERS] [-ns NUM_SUBSCRIBERS] [-n NUM_MSGS] [-ms MESSAGE_SIZE] [-csv csvfile] <subject>\n", nats.DefaultURL)
flag.PrintDefaults()
}

var benchmark *bench.Benchmark
Expand Down
5 changes: 3 additions & 2 deletions examples/nats-echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import (
// nats-echo -s demo.nats.io:4443 <subject> (TLS version)

func usage() {
log.Fatalf("Usage: nats-echo [-s server] [-creds file] [-t] <subject>")
log.Printf("Usage: nats-echo [-s server] [-creds file] [-t] <subject>\n")
flag.PrintDefaults()
}

func printMsg(m *nats.Msg, i int) {
Expand Down Expand Up @@ -157,7 +158,7 @@ func lookupGeo() string {
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
g := &geo{}
g := geo{}
if err := json.Unmarshal(body, &g); err != nil {
log.Fatalf("Error unmarshalling geo: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion examples/nats-pub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
// nats-pub -s demo.nats.io:4443 <subject> <msg> (TLS version)

func usage() {
log.Fatalf("Usage: nats-pub [-s server] [-creds file] <subject> <msg>")
log.Printf("Usage: nats-pub [-s server] [-creds file] <subject> <msg>\n")
flag.PrintDefaults()
}

func main() {
Expand Down
3 changes: 2 additions & 1 deletion examples/nats-qsub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import (
// nats-qsub -s demo.nats.io:4443 <subject> <queue> (TLS version)

func usage() {
log.Fatalf("Usage: nats-qsub [-s server] [-creds file] [-t] <subject> <queue>")
log.Printf("Usage: nats-qsub [-s server] [-creds file] [-t] <subject> <queue>\n")
flag.PrintDefaults()
}

func printMsg(m *nats.Msg, i int) {
Expand Down
3 changes: 2 additions & 1 deletion examples/nats-req/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
// nats-req -s demo.nats.io:4443 <subject> <msg> (TLS version)

func usage() {
log.Fatalf("Usage: nats-req [-s server] [-creds file] <subject> <msg>")
log.Printf("Usage: nats-req [-s server] [-creds file] <subject> <msg>\n")
flag.PrintDefaults()
}

func main() {
Expand Down
3 changes: 2 additions & 1 deletion examples/nats-rply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
// nats-rply -s demo.nats.io:4443 <subject> <response> (TLS version)

func usage() {
log.Fatalf("Usage: nats-rply [-s server] [-creds file] [-t] <subject> <response>")
log.Printf("Usage: nats-rply [-s server] [-creds file] [-t] <subject> <response>\n")
flag.PrintDefaults()
}

func printMsg(m *nats.Msg, i int) {
Expand Down
3 changes: 2 additions & 1 deletion examples/nats-sub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
// nats-sub -s demo.nats.io:4443 <subject> (TLS version)

func usage() {
log.Fatalf("Usage: nats-sub [-s server] [-creds file] [-t] <subject>")
log.Printf("Usage: nats-sub [-s server] [-creds file] [-t] <subject>\n")
flag.PrintDefaults()
}

func printMsg(m *nats.Msg, i int) {
Expand Down

6 comments on commit 4de27da

@tao-sj
Copy link

@tao-sj tao-sj commented on 4de27da May 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this change,
if user doesn't provide any parameter, it will panic. Though it's not a big deal for a demo code.

Usage: nats-pub [-s server] [-creds file] <subject> <msg>
  -creds string
    	User Credentials File
  -s string
    	The nats server URLs (separated by comma) (default "nats://127.0.0.1:4222")
panic: runtime error: index out of range

goroutine 1 [running]:
main.main()

@derekcollison
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @wallyqs or @sasbury could you take a look and clean up?

@wallyqs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taking a look

@kozlovic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the replacing of log.Fatalf() with printf and then printdefault that causes the issue since the process then does not terminate. we need to add os.Exit()

@kozlovic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see similar fix: #456

@tao-sj
Copy link

@tao-sj tao-sj commented on 4de27da May 17, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.