From 89ecdce571d5354449e265f494100e317b1b914a Mon Sep 17 00:00:00 2001 From: Alex McKinney Date: Mon, 4 Sep 2023 14:07:16 -0400 Subject: [PATCH] :herb: Add local generation configuration (#14) * Add local generation configuration * Add demo application in local/ * Add local executable to .gitignore * Revise local generation setup --- .gitignore | 3 +++ README.md | 10 ++++++++++ fern/api/generators.yml | 10 ++++++++++ local/go/go.mod | 7 +++++++ local/go/go.sum | 4 ++++ local/go/go.work | 6 ++++++ local/go/main.go | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 73 insertions(+) create mode 100644 local/go/go.mod create mode 100644 local/go/go.sum create mode 100644 local/go/go.work create mode 100644 local/go/main.go diff --git a/.gitignore b/.gitignore index e43b0f9..58502e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .DS_Store + +local/go/generated/hookdeck-go-sdk/ +local/go/go diff --git a/README.md b/README.md index d6522df..f1b6014 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,16 @@ fern check # Checks if the definition is valid Generators read in your API Definition and output files or code (i.e. the TypeScript SDK Generator) and are tracked in [generators.yml](./fern/api/generators.yml). +### Local preview + +You can preview the generated code in the `./local/go/generated/hookdeck-go-sdk` directory by running the following command: + +```sh +fern generate --group local +``` + +### Publishing + To trigger the generators run: ```bash diff --git a/fern/api/generators.yml b/fern/api/generators.yml index 63412ba..4d13c7f 100644 --- a/fern/api/generators.yml +++ b/fern/api/generators.yml @@ -1,4 +1,14 @@ groups: + local: + generators: + - name: fernapi/fern-go-sdk + version: 0.3.0 + config: + module: + path: github.com/hookdeck/hookdeck-go-sdk + output: + location: local-file-system + path: ../../local/go/generated/hookdeck-go-sdk publish: generators: - name: fernapi/fern-go-sdk diff --git a/local/go/go.mod b/local/go/go.mod new file mode 100644 index 0000000..b502424 --- /dev/null +++ b/local/go/go.mod @@ -0,0 +1,7 @@ +module github.com/hookdeck/hookdeck-api-schema/local/go + +go 1.19 + +require github.com/hookdeck/hookdeck-go-sdk v0.0.0 + +replace github.com/hookdeck/hookdeck-go-sdk v0.0.0 => ./generated/hookdeck-go-sdk diff --git a/local/go/go.sum b/local/go/go.sum new file mode 100644 index 0000000..7032873 --- /dev/null +++ b/local/go/go.sum @@ -0,0 +1,4 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/local/go/go.work b/local/go/go.work new file mode 100644 index 0000000..97dee8a --- /dev/null +++ b/local/go/go.work @@ -0,0 +1,6 @@ +go 1.19 + +use ( + . + ./generated/hookdeck-go-sdk +) diff --git a/local/go/main.go b/local/go/main.go new file mode 100644 index 0000000..670b38a --- /dev/null +++ b/local/go/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "context" + "fmt" + "os" + + hookdeck "github.com/hookdeck/hookdeck-go-sdk" + hookdeckclient "github.com/hookdeck/hookdeck-go-sdk/client" +) + +func main() { + if err := run(); err != nil { + os.Stderr.WriteString(err.Error()) + os.Exit(1) + } +} + +func run() error { + client := hookdeckclient.NewClient( + hookdeckclient.ClientWithBaseURL("http://localhost:9000/2023-07-01"), + hookdeckclient.ClientWithAuthToken(os.Getenv("HOOKDECK_AUTH_TOKEN")), + ) + issueTriggersResponse, err := client.IssueTrigger.List( + context.TODO(), + new(hookdeck.IssueTriggerListRequest), + ) + if err != nil { + return err + } + fmt.Printf("Got %d issue triggers\n", len(issueTriggersResponse.Models)) + return nil +}