Skip to content

Commit

Permalink
Upgrade to /v2 Go module
Browse files Browse the repository at this point in the history
Adds a mod file, upgrades path to conform to module versioning standard
  • Loading branch information
hownowstephen authored Jun 17, 2021
2 parents 5bdd94a + 5163d03 commit 2f4c054
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 36 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.10', '1.11', '1.12' ]
go: [ '1.15', '1.16' ]
env:
TEST_RESULTS: /tmp/test-results
name: Go ${{ matrix.go }} test
steps:
- uses: actions/checkout@v2
with:
path: src/github.com/customerio/go-customerio
- name: setup go
uses: actions/setup-go@v2
with:
Expand All @@ -25,5 +23,4 @@ jobs:
run: |
curl -sSL "https://github.com/gotestyourself/gotestsum/releases/download/v0.6.0/gotestsum_0.6.0_linux_amd64.tar.gz" | sudo tar -xz -C /usr/local/bin gotestsum
- run: |
export GOPATH="${GOPATH}:${GITHUB_WORKSPACE}"
gotestsum --junitfile ${TEST_RESULTS}/unit-tests.xml -- -timeout 5m -p 1 ./...
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Changelog

## March 24, 2021
## June 16, 2021 v2.2.0

### Added
- Modules support
- Updated license date
- Upgraded version support

## March 24, 2021 v2.1.0
### Added
- Support for EU region
- Allow using custom `*http.Client`
### Removed
### Changed
- `customerio.NewAPIClient` and `customerio.NewTrackClient` have a new variadic parameter for options in order to choose US/EU region and/or customer HTTP client.

## December 3, 2020
## December 3, 2020 v2.0.0
### Added
- Support for transactional api

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Customer IO
Copyright (c) 2021 Customer IO

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# go-customerio [![CircleCI](https://circleci.com/gh/customerio/go-customerio/tree/master.svg?style=svg)](https://circleci.com/gh/customerio/go-customerio/tree/master)

A golang client for the [Customer.io](http://customer.io) [event API](https://app.customer.io/api/docs/index.html).
_Tested with Go1.12_
_Tested with Go1.16_

Godoc here: [https://godoc.org/github.com/customerio/go-customerio](https://godoc.org/github.com/customerio/go-customerio)

Expand All @@ -14,7 +14,7 @@ Add this line to your application's imports:
```go
import (
// ...
"github.com/customerio/go-customerio"
"github.com/customerio/go-customerio/v2"
)
```

Expand All @@ -24,7 +24,7 @@ And then execute:

Or install it yourself:

$ go get "github.com/customerio/go-customerio"
$ go get github.com/customerio/go-customerio

## Usage

Expand Down
2 changes: 1 addition & 1 deletion customerio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"testing"

"github.com/customerio/go-customerio"
"github.com/customerio/go-customerio/v2"
)

var cio *customerio.CustomerIO
Expand Down
2 changes: 1 addition & 1 deletion examples/transactional.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/customerio/go-customerio"
"github.com/customerio/go-customerio/v2"
)

func main() {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/customerio/go-customerio/v2

go 1.16
16 changes: 8 additions & 8 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ type option struct {
}

type region struct {
apiURL string
trackURL string
ApiURL string
TrackURL string
}

var (
RegionUS = region{
apiURL: "https://api.customer.io",
trackURL: "https://track.customer.io",
ApiURL: "https://api.customer.io",
TrackURL: "https://track.customer.io",
}
RegionEU = region{
apiURL: "https://api-eu.customer.io",
trackURL: "https://track-eu.customer.io",
ApiURL: "https://api-eu.customer.io",
TrackURL: "https://track-eu.customer.io",
}
)

func WithRegion(r region) option {
return option{
api: func(a *APIClient) {
a.URL = r.apiURL
a.URL = r.ApiURL
},
track: func(c *CustomerIO) {
c.URL = r.trackURL
c.URL = r.TrackURL
},
}
}
Expand Down
32 changes: 17 additions & 15 deletions options_test.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
package customerio
package customerio_test

import (
"net/http"
"reflect"
"testing"

"github.com/customerio/go-customerio/v2"
)

func TestAPIOptions(t *testing.T) {

client := NewAPIClient("mykey")
if client.URL != RegionUS.apiURL {
t.Errorf("wrong default url. got: %s, want: %s", client.URL, RegionUS.apiURL)
client := customerio.NewAPIClient("mykey")
if client.URL != customerio.RegionUS.ApiURL {
t.Errorf("wrong default url. got: %s, want: %s", client.URL, customerio.RegionUS.ApiURL)
}

client = NewAPIClient("mykey", WithRegion(RegionEU))
if client.URL != RegionEU.apiURL {
t.Errorf("wrong url. got: %s, want: %s", client.URL, RegionEU.apiURL)
client = customerio.NewAPIClient("mykey", customerio.WithRegion(customerio.RegionEU))
if client.URL != customerio.RegionEU.ApiURL {
t.Errorf("wrong url. got: %s, want: %s", client.URL, customerio.RegionEU.ApiURL)
}

hc := &http.Client{}
client = NewAPIClient("mykey", WithHTTPClient(hc))
client = customerio.NewAPIClient("mykey", customerio.WithHTTPClient(hc))
if !reflect.DeepEqual(client.Client, hc) {
t.Errorf("wrong http client. got: %#v, want: %#v", client.Client, hc)
}
}

func TestTrackOptions(t *testing.T) {

client := NewTrackClient("site_id", "api_key")
if client.URL != RegionUS.trackURL {
t.Errorf("wrong default url. got: %s, want: %s", client.URL, RegionUS.trackURL)
client := customerio.NewTrackClient("site_id", "api_key")
if client.URL != customerio.RegionUS.TrackURL {
t.Errorf("wrong default url. got: %s, want: %s", client.URL, customerio.RegionUS.TrackURL)
}

client = NewTrackClient("site_id", "api_key", WithRegion(RegionEU))
if client.URL != RegionEU.trackURL {
t.Errorf("wrong url. got: %s, want: %s", client.URL, RegionEU.trackURL)
client = customerio.NewTrackClient("site_id", "api_key", customerio.WithRegion(customerio.RegionEU))
if client.URL != customerio.RegionEU.TrackURL {
t.Errorf("wrong url. got: %s, want: %s", client.URL, customerio.RegionEU.TrackURL)
}

hc := &http.Client{}
client = NewTrackClient("site_id", "api_key", WithHTTPClient(hc))
client = customerio.NewTrackClient("site_id", "api_key", customerio.WithHTTPClient(hc))
if !reflect.DeepEqual(client.Client, hc) {
t.Errorf("wrong http client. got: %#v, want: %#v", client.Client, hc)
}
Expand Down
2 changes: 1 addition & 1 deletion send_email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/customerio/go-customerio"
"github.com/customerio/go-customerio/v2"
)

func TestSendEmail(t *testing.T) {
Expand Down

0 comments on commit 2f4c054

Please sign in to comment.