()
| 35 | } |
| 36 | |
| 37 | func main() { |
| 38 | var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") |
| 39 | var userCreds = flag.String("creds", "", "User Credentials File") |
| 40 | var nkeyFile = flag.String("nkey", "", "NKey Seed File") |
| 41 | var tlsClientCert = flag.String("tlscert", "", "TLS client certificate file") |
| 42 | var tlsClientKey = flag.String("tlskey", "", "Private key file for client certificate") |
| 43 | var tlsCACert = flag.String("tlscacert", "", "CA certificate to verify peer against") |
| 44 | var reply = flag.String("reply", "", "Sets a specific reply subject") |
| 45 | var showHelp = flag.Bool("h", false, "Show help message") |
| 46 | |
| 47 | log.SetFlags(0) |
| 48 | flag.Usage = usage |
| 49 | flag.Parse() |
| 50 | |
| 51 | if *showHelp { |
| 52 | showUsageAndExit(0) |
| 53 | } |
| 54 | |
| 55 | args := flag.Args() |
| 56 | if len(args) != 2 { |
| 57 | showUsageAndExit(1) |
| 58 | } |
| 59 | |
| 60 | // Connect Options. |
| 61 | opts := []nats.Option{nats.Name("NATS Sample Publisher")} |
| 62 | |
| 63 | if *userCreds != "" && *nkeyFile != "" { |
| 64 | log.Fatal("specify -seed or -creds") |
| 65 | } |
| 66 | |
| 67 | // Use UserCredentials |
| 68 | if *userCreds != "" { |
| 69 | opts = append(opts, nats.UserCredentials(*userCreds)) |
| 70 | } |
| 71 | |
| 72 | // Use TLS client authentication |
| 73 | if *tlsClientCert != "" && *tlsClientKey != "" { |
| 74 | opts = append(opts, nats.ClientCert(*tlsClientCert, *tlsClientKey)) |
| 75 | } |
| 76 | |
| 77 | // Use specific CA certificate |
| 78 | if *tlsCACert != "" { |
| 79 | opts = append(opts, nats.RootCAs(*tlsCACert)) |
| 80 | } |
| 81 | |
| 82 | // Use Nkey authentication. |
| 83 | if *nkeyFile != "" { |
| 84 | opt, err := nats.NkeyOptionFromSeed(*nkeyFile) |
| 85 | if err != nil { |
| 86 | log.Fatal(err) |
| 87 | } |
| 88 | opts = append(opts, opt) |
| 89 | } |
| 90 | |
| 91 | // Connect to NATS |
| 92 | nc, err := nats.Connect(*urls, opts...) |
| 93 | if err != nil { |
| 94 | log.Fatal(err) |
nothing calls this directly
no test coverage detected