Skip to content

Commit

Permalink
Redo constructor for compatibility with Fern docs snippets (#44)
Browse files Browse the repository at this point in the history
* SDK regeneration

* Redo initialization options

---------

Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
Co-authored-by: Ben Papillon <[email protected]>
  • Loading branch information
fern-api[bot] and bpapillon authored Oct 25, 2024
1 parent 1d59569 commit 97296e7
Show file tree
Hide file tree
Showing 17 changed files with 941 additions and 278 deletions.
4 changes: 3 additions & 1 deletion .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
README.md
buffer/buffer.go
cache/cache.go
core/request_option.go
core/custom_options.go
custom_types.go
client/opts.go
client/schematic_client.go
client/schematic_client_test.go
flags/flags.go
Expand All @@ -14,3 +15,4 @@ generate.sh
http/offline.go
logger/logger.go
mocks/http_mock.go
option/custom_options.go
89 changes: 67 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ go get github.com/schematichq/schematic-go
import (
"os"

option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
)

func main() {
apiKey := os.Getenv("SCHEMATIC_API_KEY")
client := schematicclient.SchematicClient(apiKey)
client := schematicclient.NewSchematicClient(option.WithAPIKey(apiKey))
defer client.Close()
}
```
Expand All @@ -33,16 +34,17 @@ import (
"os"
"time"

option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
)

func main() {
apiKey := os.Getenv("SCHEMATIC_API_KEY")
cacheSize := 100
cacheTTL := 1 * time.Millisecond
client := schematicclient.SchematicClient(
apiKey,
schematicclient.WithLocalFlagCheckCache(cacheSize, cacheTTL),
client := schematicclient.NewSchematicClient(
option.WithAPIKey(apiKey),
option.WithLocalFlagCheckCache(cacheSize, cacheTTL),
)
defer client.Close()
}
Expand All @@ -54,12 +56,13 @@ You can also disable local caching entirely with an initialization option; bear
import (
"os"

option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
)

func main() {
apiKey := os.Getenv("SCHEMATIC_API_KEY")
client := schematicclient.SchematicClient(apiKey, schematicclient.WithDisabledFlagCheckCache())
client := schematicclient.NewSchematicClient(option.WithAPIKey(apiKey), option.WithDisabledFlagCheckCache())
defer client.Close()
}
```
Expand All @@ -70,12 +73,13 @@ You may want to specify default flag values for your application, which will be
import (
"os"

option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
)

func main() {
apiKey := os.Getenv("SCHEMATIC_API_KEY")
client := schematicclient.SchematicClient(apiKey, schematicclient.WithDefaultFlagValues(map[string]bool{
client := schematicclient.NewSchematicClient(option.WithAPIKey(apiKey), option.WithDefaultFlagValues(map[string]bool{
"some-flag-key": true,
}))
defer client.Close()
Expand All @@ -93,12 +97,14 @@ import (
"context"
"os"

option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
schematicgo "github.com/schematichq/schematic-go/"
schematicgo "github.com/schematichq/schematic-go"
)

func main() {
client := schematicclient.NewSchematicClient(os.Getenv("SCHEMATIC_API_KEY"))
apiKey := os.Getenv("SCHEMATIC_API_KEY")
client := schematicclient.NewSchematicClient(option.WithAPIKey(apiKey))
defer client.Close()

client.Identify(context.Background(), &schematicgo.EventBodyIdentify{
Expand Down Expand Up @@ -131,12 +137,14 @@ import (
"context"
"os"

option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
schematicgo "github.com/schematichq/schematic-go/"
schematicgo "github.com/schematichq/schematic-go"
)

func main() {
client := schematicclient.SchematicClient(os.Getenv("SCHEMATIC_API_KEY"))
apiKey := os.Getenv("SCHEMATIC_API_KEY")
client := schematicclient.NewSchematicClient(option.WithAPIKey(apiKey))
defer client.Close()

client.Track(context.Background(), &schematicgo.EventBodyTrack{
Expand All @@ -163,12 +171,14 @@ import (
"context"
"os"

option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
schematicgo "github.com/schematichq/schematic-go/"
schematicgo "github.com/schematichq/schematic-go"
)

func main() {
client := schematicclient.SchematicClient(os.Getenv("SCHEMATIC_API_KEY"))
apiKey := os.Getenv("SCHEMATIC_API_KEY")
client := schematicclient.NewSchematicClient(option.WithAPIKey(apiKey))
defer client.Close()

body := &schematicgo.UpsertCompanyRequestBody{
Expand Down Expand Up @@ -198,12 +208,14 @@ import (
"context"
"os"

option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/SchematicHQ/schematic-go/client"
schematicgo "github.com/SchematicHQ/schematic-go/"
schematicgo "github.com/SchematicHQ/schematic-go"
)

func main() {
client := schematicclient.NewSchematicClient(os.Getenv("SCHEMATIC_API_KEY"))
apiKey := os.Getenv("SCHEMATIC_API_KEY")
client := schematicclient.NewSchematicClient(option.WithAPIKey(apiKey))
defer client.Close()

body := &schematicgo.UpsertUserRequestBody{
Expand Down Expand Up @@ -237,13 +249,15 @@ When checking a flag, you'll provide keys for a company and/or keys for a user.
import (
"context"
"os"


option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
schematicgo "github.com/schematichq/schematic-go/"
schematicgo "github.com/schematichq/schematic-go"
)

func main() {
client := schematicclient.NewSchematicClient(os.Getenv("SCHEMATIC_API_KEY"))
apiKey := os.Getenv("SCHEMATIC_API_KEY")
client := schematicclient.NewSchematicClient(option.WithAPIKey(apiKey))
defer client.Close()

evaluationCtx := schematicgo.CheckFlagRequestBody{
Expand Down Expand Up @@ -272,28 +286,58 @@ The Schematic API supports many operations beyond these, accessible via `client.

### Offline Mode

In development or testing environments, you may want to avoid making network requests to the Schematic API. You can run Schematic in offline mode by providing an empty API key to the client:
In development or testing environments, you may want to avoid making network requests to the Schematic API. You can run Schematic in offline mode by not providing an API key to the client:

```go
import (
schematicclient "github.com/schematichq/schematic-go/client"
)

func main() {
client := schematicclient.NewSchematicClient()
defer client.Close()
}
```

You can also enable offline mode by providing an empty API key:

```go
import (
option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
)

func main() {
client := schematicclient.NewSchematicClient("")
client := schematicclient.NewSchematicClient(option.WithAPIKey(""))
defer client.Close()
}
```

Or, by using the offline mode option:

```go
import (
option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
)

func main() {
client := schematicclient.NewSchematicClient(option.WithOfflineMode())
defer client.Close()
}
```


Offline mode works well with flag defaults:

```go
import (
option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
)

func main() {
client := schematicclient.NewSchematicClient("", schematicclient.WithDefaultFlagValues(map[string]bool{
client := schematicclient.NewSchematicClient(option.WithOfflineMode(), option.WithDefaultFlagValues(map[string]bool{
"some-flag-key": true,
}))
defer client.Close()
Expand All @@ -304,15 +348,16 @@ In an automated testing context, you may also want to use offline mode and speci

```go
import (
option "github.com/schematichq/schematic-go/option"
schematicclient "github.com/schematichq/schematic-go/client"
)

func TestSomeFunctionality(t *testing.T) {
client := schematicclient.NewSchematicClient("")
client := schematicclient.NewSchematicClient(option.WithOfflineMode())
defer client.Close()

client.SetFlagDefault("some-flag-key", true)

// test code that expects the flag to be on
}
```
```
Loading

0 comments on commit 97296e7

Please sign in to comment.