Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/generate-references.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Generate references

# Regenerates references/ by hand, for when the release's best-effort reference step fails
# or the pages need a refresh. Same shape as posthog-js's generate-references.yml.
on:
workflow_dispatch:

permissions: {}

jobs:
generate-references:
name: Generate SDK reference
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Get GitHub App token
id: releaser
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
client-id: ${{ secrets.GH_APP_POSTHOG_GO_RELEASER_APP_ID }}
private-key: ${{ secrets.GH_APP_POSTHOG_GO_RELEASER_PRIVATE_KEY }}

- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
token: ${{ steps.releaser.outputs.token }}

- name: Check out sdk-specs
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: PostHog/sdk-specs
path: .sdk-specs
persist-credentials: false

- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.x'
cache: false

- name: Generate references
id: changes
run: |
go run ./internal/cmd/reference --sdk-specs .sdk-specs
git add references
git diff --cached --quiet || echo "changed=true" >> "$GITHUB_OUTPUT"

- name: Commit generated references
if: steps.changes.outputs.changed == 'true'
uses: planetscale/ghcommit-action@a6b150b81dca5dd027baa898604418eec9e11465 # v0.2.22
with:
commit_message: "docs: update the SDK reference [skip ci]"
repo: ${{ github.repository }}
branch: main
file_pattern: references/
env:
GITHUB_TOKEN: ${{ steps.releaser.outputs.token }}
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ jobs:
(cd "$MODULE" && go mod edit "-require=github.com/posthog/posthog-go@v${NEW_VERSION}")
done

# The reference headings come from the sdk-specs capabilities.
- name: Check out sdk-specs
# Best-effort: a failure never blocks the release. Run generate-references.yml to retry.
continue-on-error: true
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: PostHog/sdk-specs
path: .sdk-specs
persist-credentials: false

- name: Regenerate SDK reference
id: reference
# Best-effort: a failure never blocks the release. Run generate-references.yml to retry.
continue-on-error: true
# Stage the pages, so a new page shows in git status as a file, not as an untracked folder.
run: |
go run ./internal/cmd/reference --sdk-specs .sdk-specs
git add references

- name: Warn if the SDK reference didn't regenerate
if: steps.reference.outcome == 'failure'
run: echo "::warning::The SDK reference didn't regenerate. Run generate-references.yml to retry."

- name: Check for version bump changes
id: check-changes
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ node_modules/

# built compliance adapter binary
sdk_compliance_adapter/sdk_compliance_adapter
.sdk-specs/
40 changes: 40 additions & 0 deletions docs/capabilities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"Alias": "alias",
"BeforeSendFunc": "before-send-hook",
"Capture": "capture",
"Client.Close": "shutdown",
"Client.CloseWithContext": "shutdown",
"Client.Emails": "emails",
"Client.EvaluateFlags": "evaluate-flags",
"Client.Flush": "flush",
"Client.FlushWithContext": "flush",
"Client.GetAllFlags": "get-feature-flags",
"Client.GetFeatureFlag": "get-feature-flag",
"Client.GetFeatureFlagPayload": "get-feature-flag-payload",
"Client.GetFeatureFlagResult": "get-feature-flag-result",
"Client.IsFeatureEnabled": "is-feature-enabled",
"Client.ReloadFeatureFlags": "reload-feature-flags",
"Config": "setup",
"EnqueueClient.Enqueue": "capture",
"EvaluateFlagsPayload": "evaluate-flags",
"Exception": "capture-exception",
"GroupIdentify": "group-identify",
"Identify": "identify",
"next": {
"Client.EnqueueAI": "capture-ai",
"posthog.EnqueueAIWithContext": "capture-ai"
},
"posthog.EnqueueWithContext": "capture",
"posthog.EvaluateFlagsWithContext": "evaluate-flags",
"posthog.New": "setup",
"posthog.NewSlogCaptureHandler": "capture-exception",
"posthog.NewWithConfig": "setup",
"utils": [
Comment thread
eli-r-ph marked this conversation as resolved.
Resolved
"Client.GetRemoteConfigPayload",
"posthog.NewRequestContextMiddleware",
"posthog.Ptr",
"posthog.SimpleInAppDecider",
"posthog.WithFreshRequestContext",
"posthog.WithRequestContext"
]
}
34 changes: 34 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Getting started

The Go SDK runs on your server, on Go 1.21 or later.

To send your first event, create a client with your project token and host from your [project settings](https://app.posthog.com/project/settings), then call `Enqueue` with a `Capture`.

The client queues events and sends them in batches, so call `Close` before your program exits, or the last events are lost.

Install the module (Go 1.21 or later):

```bash
go get github.com/posthog/posthog-go
```

Create a client with your project API key, send an event, and close the client to flush the queue:

```go
package main

import "github.com/posthog/posthog-go"

func main() {
client, _ := posthog.NewWithConfig("<ph_project_api_key>", posthog.Config{
Endpoint: "<ph_client_api_host>",
})
defer client.Close() // flushes queued events

client.Enqueue(posthog.Capture{
DistinctId: "user_123",
Event: "button_clicked",
Properties: posthog.NewProperties().Set("plan", "pro"),
})
}
```
Loading
Loading