MCPcopy
hub / github.com/nats-io/nats.go / main

Function main

examples/nats-echo/main.go:58–164  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56}
57
58func main() {
59 var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)")
60 var userCreds = flag.String("creds", "", "User Credentials File")
61 var nkeyFile = flag.String("nkey", "", "NKey Seed File")
62 var serviceId = flag.String("id", "NATS Echo Service", "Identifier for this service")
63 var showTime = flag.Bool("t", false, "Display timestamps")
64 var showHelp = flag.Bool("h", false, "Show help message")
65 var geoloc = flag.Bool("geo", false, "Display geo location of echo service")
66 var geo string = "unknown"
67
68 log.SetFlags(0)
69 flag.Usage = usage
70 flag.Parse()
71
72 if *showHelp {
73 showUsageAndExit(0)
74 }
75
76 args := flag.Args()
77 if len(args) != 1 {
78 showUsageAndExit(1)
79 }
80
81 // Lookup geo if requested
82 if *geoloc {
83 geo = lookupGeo()
84 }
85 // Connect Options.
86 opts := []nats.Option{nats.Name(*serviceId)}
87 opts = setupConnOptions(opts)
88
89 if *userCreds != "" && *nkeyFile != "" {
90 log.Fatal("specify -seed or -creds")
91 }
92
93 // Use UserCredentials
94 if *userCreds != "" {
95 opts = append(opts, nats.UserCredentials(*userCreds))
96 }
97
98 // Use Nkey authentication.
99 if *nkeyFile != "" {
100 opt, err := nats.NkeyOptionFromSeed(*nkeyFile)
101 if err != nil {
102 log.Fatal(err)
103 }
104 opts = append(opts, opt)
105 }
106
107 // Connect to NATS
108 nc, err := nats.Connect(*urls, opts...)
109 if err != nil {
110 log.Fatal(err)
111 }
112
113 subj, iEcho, iStatus := args[0], 0, 0
114 statusSubj := subj + ".status"
115

Callers

nothing calls this directly

Calls 14

lookupGeoFunction · 0.85
printStatusMsgFunction · 0.85
ConnectMethod · 0.80
showUsageAndExitFunction · 0.70
setupConnOptionsFunction · 0.70
printMsgFunction · 0.70
NameMethod · 0.65
QueueSubscribeMethod · 0.65
PublishMethod · 0.65
SubscribeMethod · 0.65
DrainMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected