Skip to content

Commit 23f7fd8

Browse files
committed
add new env vars
Signed-off-by: Jess Frazelle <[email protected]>
1 parent 3fea866 commit 23f7fd8

File tree

6 files changed

+49
-15
lines changed

6 files changed

+49
-15
lines changed

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.2.37
1+
v0.2.38

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func run() error {
5353

5454
data := Data{
5555
PackageName: "kittycad",
56-
BaseURL: "https://api.kittycad.io",
57-
EnvVariable: "KITTYCAD_API_TOKEN",
56+
BaseURL: "https://api.zoo.dev",
57+
EnvVariable: "ZOO_API_TOKEN",
5858
Tags: []Tag{},
5959
Examples: []string{},
6060
Paths: []string{},

cmd/tmpl/lib.tmpl

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type service struct {
2525
// You need to pass in your API token to create the client.
2626
func NewClient(token, userAgent string) (*Client, error) {
2727
if token == "" {
28-
return nil, fmt.Errorf("you need to pass in an API token to create the client. Create a token at https://kittycad.io/account")
28+
return nil, fmt.Errorf("you need to pass in an API token to create the client. Create a token at https://zoo.dev/account")
2929
}
3030

3131
client := &Client{
@@ -59,14 +59,31 @@ func NewClient(token, userAgent string) (*Client, error) {
5959
}
6060

6161
// NewClientFromEnv creates a new client for the KittyCad API, using the token
62-
// stored in the environment variable `KITTYCAD_API_TOKEN`.
62+
// stored in the environment variable `KITTYCAD_API_TOKEN` or `ZOO_API_TOKEN`.
63+
// Optionally, you can pass in a different base url from the default with `ZOO_HOST`. But that
64+
// is not recommended, unless you know what you are doing or you are hosting
65+
// your own instance of the KittyCAD API.
6366
func NewClientFromEnv(userAgent string) (*Client, error) {
6467
token := os.Getenv(TokenEnvVar)
6568
if token == "" {
66-
return nil, fmt.Errorf("the environment variable %s must be set with your API token. Create a token at https://kittycad.io/account", TokenEnvVar)
69+
// Try the old environment variable name.
70+
token = os.Getenv("KITTYCAD_API_TOKEN")
71+
if token == "" {
72+
return nil, fmt.Errorf("the environment variable %s must be set with your API token. Create a token at https://zoo.dev/account", TokenEnvVar)
73+
}
6774
}
6875

69-
return NewClient(token, userAgent)
76+
host := os.Getenv("ZOO_HOST")
77+
if host == "" {
78+
host = DefaultServerURL
79+
}
80+
81+
c, err := NewClient(token, userAgent)
82+
if err != nil {
83+
return nil, err
84+
}
85+
c.WithBaseURL(host)
86+
return c, nil
7087
}
7188

7289
// WithBaseURL overrides the baseURL.

examples_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kittycad.go.patch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"value": {
4-
"client": "// Create a client with your token.\nfunc ExampleNewClient() {\n\tclient, err := kittycad.NewClient(\"$TOKEN\", \"your apps user agent\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Call the client's methods.\n\tresult, err := client.Meta.Ping()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(result)\n}\n\n// - OR -\n\n// Create a new client with your token parsed from the environment\n// variable: `KITTYCAD_API_TOKEN`.\nfunc ExampleNewClientFromEnv() {\n\tclient, err := kittycad.NewClientFromEnv(\"your apps user agent\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Call the client's methods.\n\tresult, err := client.Meta.Ping()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"%#v\", result)\n}\n",
4+
"client": "// Create a client with your token.\nfunc ExampleNewClient() {\n\tclient, err := kittycad.NewClient(\"$TOKEN\", \"your apps user agent\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Call the client's methods.\n\tresult, err := client.Meta.Ping()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(result)\n}\n\n// - OR -\n\n// Create a new client with your token parsed from the environment\n// variable: `ZOO_API_TOKEN`.\nfunc ExampleNewClientFromEnv() {\n\tclient, err := kittycad.NewClientFromEnv(\"your apps user agent\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Call the client's methods.\n\tresult, err := client.Meta.Ping()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"%#v\", result)\n}\n",
55
"install": "go get github.com/kittycad/kittycad.go"
66
},
77
"op": "add",

lib.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
)
1414

1515
// DefaultServerURL is the default server URL for the KittyCad API.
16-
const DefaultServerURL = "https://api.kittycad.io"
16+
const DefaultServerURL = "https://api.zoo.dev"
1717

1818
// TokenEnvVar is the environment variable that contains the token.
19-
const TokenEnvVar = "KITTYCAD_API_TOKEN"
19+
const TokenEnvVar = "ZOO_API_TOKEN"
2020

2121
type service struct {
2222
client *Client
@@ -26,7 +26,7 @@ type service struct {
2626
// You need to pass in your API token to create the client.
2727
func NewClient(token, userAgent string) (*Client, error) {
2828
if token == "" {
29-
return nil, fmt.Errorf("you need to pass in an API token to create the client. Create a token at https://kittycad.io/account")
29+
return nil, fmt.Errorf("you need to pass in an API token to create the client. Create a token at https://zoo.dev/account")
3030
}
3131

3232
client := &Client{
@@ -75,14 +75,31 @@ func NewClient(token, userAgent string) (*Client, error) {
7575
}
7676

7777
// NewClientFromEnv creates a new client for the KittyCad API, using the token
78-
// stored in the environment variable `KITTYCAD_API_TOKEN`.
78+
// stored in the environment variable `KITTYCAD_API_TOKEN` or `ZOO_API_TOKEN`.
79+
// Optionally, you can pass in a different base url from the default with `ZOO_HOST`. But that
80+
// is not recommended, unless you know what you are doing or you are hosting
81+
// your own instance of the KittyCAD API.
7982
func NewClientFromEnv(userAgent string) (*Client, error) {
8083
token := os.Getenv(TokenEnvVar)
8184
if token == "" {
82-
return nil, fmt.Errorf("the environment variable %s must be set with your API token. Create a token at https://kittycad.io/account", TokenEnvVar)
85+
// Try the old environment variable name.
86+
token = os.Getenv("KITTYCAD_API_TOKEN")
87+
if token == "" {
88+
return nil, fmt.Errorf("the environment variable %s must be set with your API token. Create a token at https://zoo.dev/account", TokenEnvVar)
89+
}
90+
}
91+
92+
host := os.Getenv("ZOO_HOST")
93+
if host == "" {
94+
host = DefaultServerURL
8395
}
8496

85-
return NewClient(token, userAgent)
97+
c, err := NewClient(token, userAgent)
98+
if err != nil {
99+
return nil, err
100+
}
101+
c.WithBaseURL(host)
102+
return c, nil
86103
}
87104

88105
// WithBaseURL overrides the baseURL.

0 commit comments

Comments
 (0)