Skip to content
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

Rename package #1

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: |
current_version="${{ steps.bump-version.outputs.current_version }}"
new_version="${{ steps.bump-version.outputs.new_version }}"
echo -e "## $new_version\n\n* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v${current_version}...v${new_version})\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
echo -e "## $new_version\n\n* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v${current_version}...v${new_version})\n\n$(cat CHANGELOG.md)" > CHANGELOG.md

- name: Commit and push changes
env:
Expand Down
37 changes: 21 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,65 @@
# Changelog

## 1.3.0 - 2024-08-14

1. Added the ability to explicitly specify the uuid for capturing events. If uuid is not specified, Posthog will calculate it automatically (suitable for most cases).
2. Removed unused config function `uid()`.

## 1.2.16

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.15...v1.2.16)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v1.2.15...v1.2.16)

## 1.2.15

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.14...v1.2.15)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v1.2.14...v1.2.15)

## 1.2.14

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.13...v1.2.14)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v1.2.13...v1.2.14)

## 1.2.13

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.12...v1.2.13)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v1.2.12...v1.2.13)

## 1.2.12

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.12)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.12)

## 1.2.11

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.11)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.11)

## 1.2.10

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.10)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.10)

## 1.2.9

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.9)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.9)

## 1.2.8

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.8)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.8)

## 1.2.7

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.7)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.7)

## 1.2.6

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.6)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.6)

## 1.2.5

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.5)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.5)

## 1.2.4

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.4)
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.4)

## 1.2.3

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v...v1.2.3)

# Changelog
* [Full Changelog](https://github.com/Cado-Labs/posthog-go/compare/v...v1.2.3)

## 1.2.2 - 2024-08-08

Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Specifically, the [Go integration](https://posthog.com/docs/integrations/go-inte

Install posthog to your gopath
```bash
$ go get github.com/posthog/posthog-go
$ go get github.com/Cado-Labs/posthog-go
```

Go 🦔!
Expand All @@ -17,7 +17,7 @@ package main

import (
"os"
"github.com/posthog/posthog-go"
"github.com/Cado-Labs/posthog-go"
)

func main() {
Expand Down Expand Up @@ -62,6 +62,18 @@ func main() {
Properties: posthog.NewProperties().
Set("$current_url", "https://example.com"),
})

// Capture event with calculated uuid to deduplicate repeated events.
// The library github.com/google/uuid is used
key := myEvent.Id + myEvent.Project
uid := uuid.NewSHA1(uuid.NameSpaceX500, []byte(key)).String()
client.Enqueue(posthog.Capture{
Uuid: uid,
DistinctId: "test-user",
Event: "$pageview",
Properties: posthog.NewProperties().
Set("$current_url", "https://example.com"),
})

// Check if a feature flag is enabled
isMyFlagEnabled, err := client.IsFeatureEnabled(
Expand All @@ -86,11 +98,11 @@ module example/posthog-go-app

go 1.22.5

require github.com/posthog/posthog-go v0.0.0-20240327112532-87b23fe11103
require github.com/Cado-Labs/posthog-go v0.0.0-20240327112532-87b23fe11103

require github.com/google/uuid v1.3.0 // indirect

replace github.com/posthog/posthog-go => /path-to-your-local/posthog-go
replace github.com/Cado-Labs/posthog-go => /path-to-your-local/posthog-go
```

## Questions?
Expand Down
6 changes: 5 additions & 1 deletion capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ type Capture struct {
// This field is exported for serialization purposes and shouldn't be set by
// the application, its value is always overwritten by the library.
Type string

// You don't usually need to specify this field - Posthog will generate it automatically.
// Use it only when necessary - for example, to prevent duplicate events.
Uuid string
DistinctId string
Event string
Timestamp time.Time
Expand Down Expand Up @@ -44,6 +46,7 @@ func (msg Capture) Validate() error {

type CaptureInApi struct {
Type string `json:"type"`
Uuid string `json:"uuid"`
Library string `json:"library"`
LibraryVersion string `json:"library_version"`
Timestamp time.Time `json:"timestamp"`
Expand Down Expand Up @@ -72,6 +75,7 @@ func (msg Capture) APIfy() APIMessage {

apified := CaptureInApi{
Type: msg.Type,
Uuid: msg.Uuid,
Library: library,
LibraryVersion: libraryVersion,
Timestamp: msg.Timestamp,
Expand Down
3 changes: 1 addition & 2 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"os"

"github.com/posthog/posthog-go"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -91,7 +90,7 @@ func main() {
os.Exit(1)
}

return nil
return nil
}

err := app.Run(os.Args)
Expand Down
19 changes: 0 additions & 19 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package posthog
import (
"net/http"
"time"

"github.com/google/uuid"
)

// Instances of this type carry the different configuration options that may
Expand Down Expand Up @@ -79,12 +77,6 @@ type Config struct {
// If not set the client will fallback to use a default retry policy.
RetryAfter func(int) time.Duration

// A function called by the client to generate unique message identifiers.
// The client uses a UUID generator if none is provided.
// This field is not exported and only exposed internally to let unit tests
// mock the id generation.
uid func() string

// A function called by the client to get the current time, `time.Now` is
// used by default.
// This field is not exported and only exposed internally to let unit tests
Expand Down Expand Up @@ -173,10 +165,6 @@ func makeConfig(c Config) Config {
c.RetryAfter = DefaultBacko().Duration
}

if c.uid == nil {
c.uid = uid
}

if c.now == nil {
c.now = time.Now
}
Expand All @@ -187,10 +175,3 @@ func makeConfig(c Config) Config {

return c
}

// This function returns a string representation of a UUID, it's the default
// function used for generating unique IDs.
func uid() string {
new_uuid, _ := uuid.NewRandom()
return new_uuid.String()
}
2 changes: 0 additions & 2 deletions examples/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package main
import (
"fmt"
"time"

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

func TestCapture() {
Expand Down
2 changes: 0 additions & 2 deletions examples/featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package main
import (
"fmt"
"time"

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

func TestIsFeatureEnabled() {
Expand Down
22 changes: 22 additions & 0 deletions fixtures/test-enqueue-capture-with-uuid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"api_key": "Csyjlnlun3OzyNJAafdlv",
"batch": [
{
"distinct_id": "123456",
"event": "Download",
"library": "posthog-go",
"library_version": "1.0.0",
"properties": {
"$lib": "posthog-go",
"$lib_version": "1.0.0",
"application": "PostHog Go",
"platform": "macos",
"version": "1.0.0"
},
"send_feature_flags": false,
"timestamp": "2009-11-10T23:00:00Z",
"type": "capture",
"uuid": "11111111-1111-1111-1111-111111111111"
}
]
}
3 changes: 2 additions & 1 deletion fixtures/test-enqueue-capture.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"send_feature_flags": false,
"timestamp": "2009-11-10T23:00:00Z",
"type": "capture"
"type": "capture",
"uuid": ""
}
]
}
3 changes: 2 additions & 1 deletion fixtures/test-interval-capture.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"send_feature_flags": false,
"timestamp": "2009-11-10T23:00:00Z",
"type": "capture"
"type": "capture",
"uuid": ""
}
]
}
9 changes: 6 additions & 3 deletions fixtures/test-many-capture.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"send_feature_flags": false,
"timestamp": "2009-11-10T23:00:00Z",
"type": "capture"
"type": "capture",
"uuid": ""
},
{
"distinct_id": "123456",
Expand All @@ -29,7 +30,8 @@
},
"send_feature_flags": false,
"timestamp": "2009-11-10T23:00:00Z",
"type": "capture"
"type": "capture",
"uuid": ""
},
{
"distinct_id": "123456",
Expand All @@ -44,7 +46,8 @@
},
"send_feature_flags": false,
"timestamp": "2009-11-10T23:00:00Z",
"type": "capture"
"type": "capture",
"uuid": ""
}
]
}
3 changes: 2 additions & 1 deletion fixtures/test-merge-capture.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"send_feature_flags": false,
"timestamp": "2015-07-10T23:00:00Z",
"type": "capture"
"type": "capture",
"uuid": ""
}
]
}
3 changes: 2 additions & 1 deletion fixtures/test-timestamp-capture.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"send_feature_flags": false,
"timestamp": "2015-07-10T23:00:00Z",
"type": "capture"
"type": "capture",
"uuid": ""
}
]
}
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module github.com/posthog/posthog-go
module github.com/Cado-Labs/posthog-go

go 1.18

require (
github.com/google/uuid v1.3.0
github.com/urfave/cli v1.22.5
)
require github.com/urfave/cli v1.22.5

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
Expand Down
4 changes: 1 addition & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
Expand All @@ -12,4 +10,4 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Loading
Loading