mirror of
https://git.robbyzambito.me/http-nats-proxy
synced 2025-12-20 08:14:51 +00:00
More connection options
This commit is contained in:
14
main.go
14
main.go
@@ -20,6 +20,10 @@ func printHelp() {
|
||||
fmt.Println(" NATS_URL - NATS connection URL (default: nats://127.0.0.1:4222)")
|
||||
fmt.Println(" NATS_USER - NATS username for authentication (optional)")
|
||||
fmt.Println(" NATS_PASSWORD - NATS password for authentication (optional)")
|
||||
fmt.Println(" NATS_TOKEN - NATS token for authentication (optional)")
|
||||
fmt.Println(" NATS_NKEY - NATS NKEY for authentication (optional)")
|
||||
fmt.Println(" NATS_NKEY_SEED - NATS NKEY seed for authentication (optional)")
|
||||
fmt.Println(" NATS_CREDS_FILE - Path to NATS credentials file (optional)")
|
||||
fmt.Println(" HTTP_PORT - HTTP port to listen on (default: 8080)")
|
||||
}
|
||||
|
||||
@@ -38,6 +42,10 @@ func main() {
|
||||
}
|
||||
natsUser := os.Getenv("NATS_USER")
|
||||
natsPassword := os.Getenv("NATS_PASSWORD")
|
||||
natsToken := os.Getenv("NATS_TOKEN")
|
||||
natsNkey := os.Getenv("NATS_NKEY")
|
||||
natsNkeySeed := os.Getenv("NATS_NKEY_SEED")
|
||||
natsCredsFile := os.Getenv("NATS_CREDS_FILE")
|
||||
|
||||
// Read HTTP port from environment variables
|
||||
httpPort := os.Getenv("HTTP_PORT")
|
||||
@@ -50,6 +58,12 @@ func main() {
|
||||
|
||||
if natsUser != "" && natsPassword != "" {
|
||||
opts = append(opts, nats.UserInfo(natsUser, natsPassword))
|
||||
} else if natsToken != "" {
|
||||
opts = append(opts, nats.Token(natsToken))
|
||||
} else if natsNkey != "" && natsNkeySeed != "" {
|
||||
opts = append(opts, nats.Nkey(natsNkey, []byte(natsNkeySeed)))
|
||||
} else if natsCredsFile != "" {
|
||||
opts = append(opts, nats.UserCredentials(natsCredsFile))
|
||||
}
|
||||
|
||||
nc, err := nats.Connect(natsURL, opts...)
|
||||
|
||||
Reference in New Issue
Block a user