Преглед изворни кода

Default CHATTO_BASE_URL to chat.chatto.run

Paul Klumpp пре 3 дана
родитељ
комит
8c54282f61
2 измењених фајлова са 10 додато и 5 уклоњено
  1. 2 1
      README.md
  2. 8 4
      cmd/cheapo/chatto.go

+ 2 - 1
README.md

@@ -124,8 +124,9 @@ CLI commands (credentials deliberately provided by the operator, never
 fetched automatically):
 
 ```bash
-export CHATTO_BASE_URL="https://chat.example.com"
 export CHATTO_TOKEN="<token>"        # set by the operator
+# Base URL default: https://chat.chatto.run
+# (overridable via CHATTO_BASE_URL)
 
 cheapo chatto-rooms                     # list rooms (client verification)
 cheapo chatto-send --room <room_id>     # post current free games

+ 8 - 4
cmd/cheapo/chatto.go

@@ -11,14 +11,18 @@ import (
 	"gogs.netdome.biz/paul/cheapo/internal/game"
 )
 
-// chattoClientFromEnv builds a Chatto client from CHATTO_BASE_URL and
-// CHATTO_TOKEN environment variables. The token is provided by the operator;
+// chattoClientFromEnv builds a Chatto client from the CHATTO_TOKEN
+// environment variable; CHATTO_BASE_URL defaults to the public Chatto
+// server (https://chat.chatto.run). The token is provided by the operator;
 // this tool never fetches credentials itself.
 func chattoClientFromEnv() (*chatto.Client, error) {
 	base := os.Getenv("CHATTO_BASE_URL")
+	if base == "" {
+		base = "https://chat.chatto.run"
+	}
 	token := os.Getenv("CHATTO_TOKEN")
-	if base == "" || token == "" {
-		return nil, fmt.Errorf("CHATTO_BASE_URL and CHATTO_TOKEN must be set")
+	if token == "" {
+		return nil, fmt.Errorf("CHATTO_TOKEN must be set (base URL: %s, overridable via CHATTO_BASE_URL)", base)
 	}
 	return chatto.NewClient(base, token), nil
 }