Repository navigation
docs: generate the SDK reference as Markdown with go/doc #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4b84cfd
docs: add Markdown SDK reference generator
gewenyu99 d7a4d1b
docs: generate the reference with go/doc instead of gomarkdoc
gewenyu99 4adf950
chore: update the public API snapshot for the capability tags
gewenyu99 bc87bb9
ci: stage generated reference pages before the release commit
gewenyu99 e3a1866
docs: read capability tags from docs/capabilities.json
gewenyu99 3931c71
docs: map EnqueueAI to capture-ai on 2.x
gewenyu99 01c6ac9
ci: add a workflow that regenerates the reference by hand
gewenyu99 02c3a65
ci: don't let the sdk-specs checkout block a release
gewenyu99 5e1bb9c
ci: warn when the SDK reference doesn't regenerate
gewenyu99 b01313e
docs: open the Go getting-started page with the steps to a first event
gewenyu99 349ecb3
fix(reference): fence code examples, list typed constants, create ref…
gewenyu99 bed9314
fix(reference): clean up the generated Go reference
gewenyu99 e617299
fix(reference): drop the blank line nest leaves after the dropped H1
gewenyu99 3cc634a
fix(reference): tag an example go only when it parses, and trim blank…
gewenyu99 7eaa591
Merge main into markdown-reference-adapter
gewenyu99 8274f60
docs: map Client.Emails to the emails capability
gewenyu99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,4 @@ node_modules/ | |
|
|
||
| # built compliance adapter binary | ||
| sdk_compliance_adapter/sdk_compliance_adapter | ||
| .sdk-specs/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": [ | ||
| "Client.GetRemoteConfigPayload", | ||
| "posthog.NewRequestContextMiddleware", | ||
| "posthog.Ptr", | ||
| "posthog.SimpleInAppDecider", | ||
| "posthog.WithFreshRequestContext", | ||
| "posthog.WithRequestContext" | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"), | ||
| }) | ||
| } | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.