Skip to content

Commit

Permalink
Add github workflow for ci testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mdogan committed Jan 30, 2024
1 parent eb6abb9 commit 35cfdac
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 6 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build

on:
push:
branches:
- master
- main
pull_request:
workflow_dispatch:

env:
UPSTASH_VECTOR_REST_URL: ${{ secrets.UPSTASH_VECTOR_REST_URL }}
UPSTASH_VECTOR_REST_TOKEN: ${{ secrets.UPSTASH_VECTOR_REST_TOKEN }}

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'

- name: Install Go tools
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Build
run: make

- name: Test
run: make test
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ func main() {
}
```

Alternatively, you can set following environment variables:

```shell
UPSTASH_VECTOR_REST_URL="your_rest_url"
UPSTASH_VECTOR_REST_TOKEN="your_rest_token"
```

and then create client by using:

```go
import (
"github.com/upstash/vector-go"
)

func main() {
client := vector.NewClientFromEnv()
}
```

#### Using a custom HTTP client

By default, `http.DefaultClient` will be used for doing requests. It is possible
Expand Down Expand Up @@ -190,4 +209,4 @@ err := client.Reset()

```go
info, err := client.Info()
```
```
23 changes: 22 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
"errors"
"io"
"net/http"
"os"
)

const (
UrlEnvProperty = "UPSTASH_VECTOR_REST_URL"
TokenEnvProperty = "UPSTASH_VECTOR_REST_TOKEN"
)

type Options struct {
Expand All @@ -23,6 +29,12 @@ func (o *Options) init() {
if o.Client == nil {
o.Client = http.DefaultClient
}
if o.Url == "" {
panic("Missing Upstash Vector URL")
}
if o.Token == "" {
panic("Missing Upstash Vector Token")
}
}

// NewClient returns a client to be used with Upstash Vector
Expand All @@ -34,7 +46,16 @@ func NewClient(url string, token string) *Client {
})
}

// NewClient returns a client to be used with Upstash Vector
// NewClientFromEnv returns a client to be used with Upstash Vector
// by reading URL and token from the environment variables.
func NewClientFromEnv() *Client {
return NewClientWith(Options{
Url: os.Getenv(UrlEnvProperty),
Token: os.Getenv(TokenEnvProperty),
})
}

// NewClientWith returns a client to be used with Upstash Vector
// with the given options.
func NewClientWith(options Options) *Client {
options.init()
Expand Down
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

func newTestClient() (*Client, error) {
client := NewClient(
os.Getenv("UPSTASH_VECTOR_REST_URL"),
os.Getenv("UPSTASH_VECTOR_REST_TOKEN"),
os.Getenv(UrlEnvProperty),
os.Getenv(TokenEnvProperty),
)

err := client.Reset()
Expand All @@ -24,8 +24,8 @@ func newTestClient() (*Client, error) {

func newTestClientWith(client *http.Client) (*Client, error) {
opts := Options{
Url: os.Getenv("UPSTASH_VECTOR_REST_URL"),
Token: os.Getenv("UPSTASH_VECTOR_REST_TOKEN"),
Url: os.Getenv(UrlEnvProperty),
Token: os.Getenv(TokenEnvProperty),
Client: client,
}

Expand Down

0 comments on commit 35cfdac

Please sign in to comment.