Skip to content

Commit 46a26b0

Browse files
committed
Release v0.0.246
0 parents  commit 46a26b0

File tree

15 files changed

+1817
-0
lines changed

15 files changed

+1817
-0
lines changed

.fernignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Specify files that shouldn't be modified by Fern

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: ci
2+
3+
on: [push]
4+
5+
jobs:
6+
compile:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout repo
10+
uses: actions/checkout@v3
11+
12+
- name: Set up go
13+
uses: actions/setup-go@v4
14+
15+
- name: Compile
16+
run: go build ./...
17+
test:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v3
22+
23+
- name: Set up go
24+
uses: actions/setup-go@v4
25+
26+
- name: Test
27+
run: go test ./...

client/client.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This file was auto-generated by Fern from our API Definition.
2+
3+
package client
4+
5+
import (
6+
core "github.com/fern-api/generator-exec-go/core"
7+
logging "github.com/fern-api/generator-exec-go/logging"
8+
http "net/http"
9+
)
10+
11+
type Client interface {
12+
Logging() logging.Client
13+
}
14+
15+
func NewClient(opts ...core.ClientOption) Client {
16+
options := core.NewClientOptions()
17+
for _, opt := range opts {
18+
opt(options)
19+
}
20+
return &client{
21+
baseURL: options.BaseURL,
22+
httpClient: options.HTTPClient,
23+
header: options.ToHeader(),
24+
loggingClient: logging.NewClient(opts...),
25+
}
26+
}
27+
28+
type client struct {
29+
baseURL string
30+
httpClient core.HTTPClient
31+
header http.Header
32+
loggingClient logging.Client
33+
}
34+
35+
func (c *client) Logging() logging.Client {
36+
return c.loggingClient
37+
}

client/client_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package client
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestNewClient(t *testing.T) {
12+
t.Run("default", func(t *testing.T) {
13+
c := NewClient()
14+
assert.Empty(t, c.(*client).baseURL)
15+
assert.Equal(t, http.DefaultClient, c.(*client).httpClient)
16+
})
17+
18+
t.Run("base url", func(t *testing.T) {
19+
c := NewClient(
20+
ClientWithBaseURL("test.co"),
21+
)
22+
assert.Equal(t, "test.co", c.(*client).baseURL)
23+
assert.Equal(t, http.DefaultClient, c.(*client).httpClient)
24+
})
25+
26+
t.Run("http client", func(t *testing.T) {
27+
httpClient := &http.Client{
28+
Timeout: 5 * time.Second,
29+
}
30+
c := NewClient(
31+
ClientWithHTTPClient(httpClient),
32+
)
33+
assert.Empty(t, c.(*client).baseURL)
34+
assert.Equal(t, httpClient, c.(*client).httpClient)
35+
})
36+
37+
t.Run("http header", func(t *testing.T) {
38+
header := make(http.Header)
39+
header.Set("X-API-Tenancy", "test")
40+
c := NewClient(
41+
ClientWithHTTPHeader(header),
42+
)
43+
assert.Empty(t, c.(*client).baseURL)
44+
assert.Equal(t, http.DefaultClient, c.(*client).httpClient)
45+
assert.Equal(t, "test", c.(*client).header.Get("X-API-Tenancy"))
46+
})
47+
}

client/options.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This file was auto-generated by Fern from our API Definition.
2+
3+
package client
4+
5+
import (
6+
core "github.com/fern-api/generator-exec-go/core"
7+
http "net/http"
8+
)
9+
10+
// ClientWithBaseURL sets the client's base URL, overriding the
11+
// default environment, if any.
12+
func ClientWithBaseURL(baseURL string) core.ClientOption {
13+
return func(opts *core.ClientOptions) {
14+
opts.BaseURL = baseURL
15+
}
16+
}
17+
18+
// ClientWithHTTPClient uses the given HTTPClient to issue all HTTP requests.
19+
func ClientWithHTTPClient(httpClient core.HTTPClient) core.ClientOption {
20+
return func(opts *core.ClientOptions) {
21+
opts.HTTPClient = httpClient
22+
}
23+
}
24+
25+
// ClientWithHTTPHeader adds the given http.Header to all requests
26+
// issued by the client.
27+
func ClientWithHTTPHeader(httpHeader http.Header) core.ClientOption {
28+
return func(opts *core.ClientOptions) {
29+
// Clone the headers so they can't be modified after the option call.
30+
opts.HTTPHeader = httpHeader.Clone()
31+
}
32+
}

0 commit comments

Comments
 (0)