Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Go code samples #369

Merged
merged 14 commits into from
Oct 11, 2024
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT}

RUN apt-get update

RUN apt-get install -y php ruby ruby-dev
RUN apt-get install -y php ruby ruby-dev golang-go
RUN gem install standard -v 1.31.0

RUN wget https://github.com/mvdan/sh/releases/download/v3.9.0/shfmt_v3.9.0_linux_amd64 -O shfmt \
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '^1.23.2'
- name: Install standardrb
run: gem install standard -v 1.31.0
- name: Normalize package-lock.json
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ GitHub actions will automatically ensure the formatting is applied for all pull

- [shfmt](https://github.com/mvdan/sh)
- [ruff](https://github.com/astral-sh/ruff)
- [gofmt](https://go.dev/blog/gofmt)
- [standardrb](https://github.com/standardrb/standard)

## GitHub Actions
Expand Down
21 changes: 21 additions & 0 deletions docs/api/acs/systems/get.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ seam acs systems get --acs_system_id "8d7e0b3a-b889-49a7-9164-4b71a0506a33"
```
{% endtab %}

{% tab title="Go" %}
#### Request

```go
package main

import api "github.com/seamapi/go"
import systems "github.com/seamapi/go/systems"

func main() {
client.Acs.Systems.Get(context.Background(), systems.SystemsGetRequest{AcsSystemId: api.String("8d7e0b3a-b889-49a7-9164-4b71a0506a33")})
}
```

#### Response

```go
[]api.AcsSystem{api.AcsSystem{AcsSystemId: "8d7e0b3a-b889-49a7-9164-4b71a0506a33"}}
```
{% endtab %}

{% endtabs %}

## Request Parameters
Expand Down
21 changes: 21 additions & 0 deletions docs/api/acs/systems/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ seam acs systems list --connected_account_id "123e4567-e89b-12d3-a456-4266141740
```
{% endtab %}

{% tab title="Go" %}
#### Request

```go
package main

import api "github.com/seamapi/go"
import systems "github.com/seamapi/go/systems"

func main() {
client.Acs.Systems.List(context.Background(), systems.SystemsListRequest{ConnectedAccountId: api.String("123e4567-e89b-12d3-a456-426614174000")})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrii-balitskyi I was hoping gomft would break this long line. I wonder if we can force it to work if we add newlines after each argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I tested locally and it still doesn't seem to work with additional newlines:

func main() {
	client.Acs.Systems.List(
		context.Background(),
		systems.SystemsListRequest{
			ConnectedAccountId: api.String("123e4567-e89b-12d3-a456-426614174000")})
}

For example, the closing parenthesis of the List method and the closing curly brace of SystemsListRequest look off. However, it seems that's how gofmt works. If these closing characters were on a new line, gofmt would align them with their opening counterparts.

Copy link
Contributor

@andrii-balitskyi andrii-balitskyi Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, with changes in this PR the final formatting looks good

func main() {
	client.Acs.Systems.List(
		context.Background(),
		systems.SystemsListRequest{
			ConnectedAccountId: api.String("123e4567-e89b-12d3-a456-426614174000"),
		},
	)
}

}
```

#### Response

```go
[]api.AcsSystem{api.AcsSystem{AcsSystemId: "8d7e0b3a-b889-49a7-9164-4b71a0506a33"}}
```
{% endtab %}

{% endtabs %}

## Request Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ seam acs systems list-compatible-credential-manager-acs-systems --acs_system_id
```
{% endtab %}

{% tab title="Go" %}
#### Request

```go
package main

import api "github.com/seamapi/go"
import systems "github.com/seamapi/go/systems"

func main() {
client.Acs.Systems.ListCompatibleCredentialManagerAcsSystems(context.Background(), systems.SystemsListCompatibleCredentialManagerAcsSystemsRequest{AcsSystemId: api.String("8d7e0b3a-b889-49a7-9164-4b71a0506a33")})
}
```

#### Response

```go
[]api.AcsSystem{api.AcsSystem{AcsSystemId: "aczp0sgx-gl9f-nygd-r11e-7pc1zufn55z4"}}
```
{% endtab %}

{% endtabs %}

## Request Parameters
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@metalsmith/layouts": "^2.7.0",
"@metalsmith/metadata": "^0.3.0",
"@prettier/plugin-php": "^0.22.2",
"@seamapi/blueprint": "^0.28.0",
"@seamapi/blueprint": "^0.28.1",
"@seamapi/types": "1.263.1",
"change-case": "^5.4.4",
"command-exists": "^1.2.9",
Expand Down
14 changes: 14 additions & 0 deletions src/lib/format-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const formatCodeForSyntax = async (
return await formatRuby(content)
case 'php':
return await formatPhp(content)
case 'go':
return await formatGo(content)
case 'bash':
return await formatBash(content)
case 'json':
Expand Down Expand Up @@ -62,6 +64,18 @@ const formatRuby = async (content: string): Promise<string> => {
return result.stdout.split('\n').slice(1).join('\n')
}

const formatGo = async (content: string): Promise<string> => {
try {
await commandExists('gofmt')
} catch (err) {
// eslint-disable-next-line no-console
console.warn('Skipping go formatting: gofmt is not installed')
return content
}
const result = await execa({ input: content })`gofmt`
return result.stdout
}

const formatBash = async (content: string): Promise<string> => {
try {
await commandExists('shfmt')
Expand Down
1 change: 1 addition & 0 deletions src/lib/layout-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const supportedSdks: CodeSampleSdk[] = [
'python',
'php',
'ruby',
'go',
'seam_cli',
]

Expand Down
Loading