Skip to content

Commit 76a88fe

Browse files
committed
feat(backend): allow specifying PostHog host
1 parent 9180cff commit 76a88fe

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

cmd/backend/dependencies.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ func ApqCache(redisClient rueidis.Client) graphql.Cache[string] {
5252
}
5353

5454
func PostHogClient(lifecycle fx.Lifecycle, cfg config.Config) (posthog.Client, error) {
55-
if cfg.PostHog.APIKey == nil {
56-
slog.Warn("PostHog client is not initialized, because you did not configure a PostHog API key.")
55+
if cfg.PostHog.APIKey == nil || cfg.PostHog.Host == nil {
56+
slog.Warn("PostHog client is not initialized, because you did not configure a PostHog API key and a host.")
5757
return nil, nil
5858
}
5959

6060
client, err := posthog.NewWithConfig(
6161
*cfg.PostHog.APIKey,
6262
posthog.Config{
63-
Endpoint: "https://us.i.posthog.com",
63+
Endpoint: *cfg.PostHog.Host,
6464
},
6565
)
6666
if err != nil {

docs/config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ PostHog 是一個產品統計平台。這個專案使用 [posthog-go](https://po
6565
如果不填寫 API Key 則代表不送出任何統計。
6666

6767
- `POSTHOG_API_KEY`: PostHog 的 API key。可以在 PostHog 的 Settings > Project > General > Project API key 中取得。
68+
- `POSTHOG_HOST`: PostHog API 的主機。可以在 PostHog 的 Settings > Project > General > Web snippet 中的 `api_host` 取得。
69+
- e.g. `https://us.i.posthog.com`

internal/config/models.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,17 @@ func (c SqlRunnerConfig) Validate() error {
157157

158158
type PostHogConfig struct {
159159
APIKey *string `env:"API_KEY"`
160+
Host *string `env:"HOST"`
160161
}
161162

162163
func (c PostHogConfig) Validate() error {
163164
if c.APIKey != nil && *c.APIKey == "" {
164165
return errors.New("POSTHOG_API_KEY cannot be empty")
165166
}
166167

168+
if c.Host != nil && *c.Host == "" {
169+
return errors.New("POSTHOG_HOST cannot be empty")
170+
}
171+
167172
return nil
168173
}

0 commit comments

Comments
 (0)