Skip to content

Commit

Permalink
feat(go): Add support for User-Agent header
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney committed Dec 12, 2024
1 parent 0e1afdc commit 50e46b9
Show file tree
Hide file tree
Showing 68 changed files with 97 additions and 29 deletions.
29 changes: 0 additions & 29 deletions generators/browser-compatible-base/src/utils/getSdkVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,3 @@ export function getSdkVersion(config: FernGeneratorExec.GeneratorConfig): string
}
});
}

export function getPackageName(config: FernGeneratorExec.GeneratorConfig): string | undefined {
return config.output.mode._visit<string | undefined>({
publish: (gpc: FernGeneratorExec.GeneratorPublishConfig) =>
gpc.publishTarget?._visit({
maven: (mrc: FernGeneratorExec.MavenRegistryConfigV2) => mrc.coordinate,
npm: (nrc: FernGeneratorExec.NpmRegistryConfigV2) => nrc.packageName,
pypi: (prc: FernGeneratorExec.PypiRegistryConfig) => prc.packageName,
rubygems: (rgrc: FernGeneratorExec.RubyGemsRegistryConfig) => rgrc.packageName,
nuget: (nrc: FernGeneratorExec.NugetRegistryConfig) => nrc.packageName,
postman: () => undefined,
_other: () => undefined
}),
downloadFiles: () => undefined,
github: (gom: FernGeneratorExec.GithubOutputMode) =>
gom.publishInfo?._visit({
maven: (mrc: FernGeneratorExec.MavenGithubPublishInfo) => mrc.coordinate,
npm: (nrc: FernGeneratorExec.NpmGithubPublishInfo) => nrc.packageName,
pypi: (prc: FernGeneratorExec.PypiGithubPublishInfo) => prc.packageName,
rubygems: (rgrc: FernGeneratorExec.RubyGemsGithubPublishInfo) => rgrc.packageName,
nuget: (nrc: FernGeneratorExec.NugetGithubPublishInfo) => nrc.packageName,
postman: () => undefined,
_other: () => undefined
}),
_other: () => {
throw new Error("Unrecognized output mode.");
}
});
}
3 changes: 3 additions & 0 deletions generators/go/internal/generator/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ func (f *fileWriter) writePlatformHeaders(
f.P(fmt.Sprintf("headers.Set(%q, %q)", sdkConfig.PlatformHeaders.Language, goLanguageHeader))
f.P(fmt.Sprintf("headers.Set(%q, %q)", sdkConfig.PlatformHeaders.SdkName, moduleConfig.Path))
f.P(fmt.Sprintf("headers.Set(%q, %q)", sdkConfig.PlatformHeaders.SdkVersion, sdkVersion))
if sdkConfig.PlatformHeaders.UserAgent != nil {
f.P(fmt.Sprintf("headers.Set(%q, %q)", sdkConfig.PlatformHeaders.UserAgent.Header(), sdkConfig.PlatformHeaders.UserAgent.Value))
}
f.P("return headers")
f.P("}")
}
Expand Down
12 changes: 12 additions & 0 deletions generators/go/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
- version: 0.34.0
changelogEntry:
- type: feat
summary: >-
Add support for sending the `User-Agent` header on every request. Go packages
are uniquely identified by their full module path, so the `User-Agent` header
is generated in the `<module>/<version>` format, e.g.
```
User-Agent: github.com/acme/acme-go/1.0.0
```
irVersion: 53
- version: 0.33.0
changelogEntry:
- type: feat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ async function getGithubLicense({
});
}

// TODO: This is where we should add support for Go and PHP.
function getGithubPublishInfo(
output: generatorsYml.GeneratorOutputSchema,
maybeGroupLevelMetadata: OutputMetadata | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ export function getPackageName({
}: {
generatorInvocation: GeneratorInvocation;
}): string | undefined {
if (generatorInvocation.language === "go") {
return getGoPackageName(generatorInvocation);
}
return generatorInvocation.outputMode._visit<string | undefined>({
downloadFiles: () => undefined,
github: (val) =>
Expand Down Expand Up @@ -164,3 +167,18 @@ export function getPackageName({
_other: () => undefined
});
}

/**
* Go doesn't use a central package manager; the Go Module Proxy simply uses the name
* of the GitHub repository.
*/
function getGoPackageName(generatorInvocation: GeneratorInvocation): string | undefined {
return generatorInvocation.outputMode._visit<string | undefined>({
downloadFiles: () => undefined,
github: (val) => `github.com/${val.owner}/${val.repo}`,
githubV2: (val) => `github.com/${val.owner}/${val.repo}`,
publish: () => undefined,
publishV2: () => undefined,
_other: () => undefined
});
}
1 change: 1 addition & 0 deletions seed/go-sdk/alias/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/any-auth/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/api-wide-base-path/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/audiences/core/request_option.go

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

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

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

1 change: 1 addition & 0 deletions seed/go-sdk/basic-auth/core/request_option.go

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

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

1 change: 1 addition & 0 deletions seed/go-sdk/bytes/core/request_option.go

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

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

1 change: 1 addition & 0 deletions seed/go-sdk/circular-references/core/request_option.go

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

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

1 change: 1 addition & 0 deletions seed/go-sdk/custom-auth/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/enum/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/error-property/core/request_option.go

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

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

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

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

1 change: 1 addition & 0 deletions seed/go-sdk/extends/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/extra-properties/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/file-download/core/request_option.go

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

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

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

1 change: 1 addition & 0 deletions seed/go-sdk/folders/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/go-content-type/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/idempotency-headers/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/imdb/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/license/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/literal/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/mixed-case/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/mixed-file-directory/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/multi-line-docs/core/request_option.go

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

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

1 change: 1 addition & 0 deletions seed/go-sdk/multi-url-environment/core/request_option.go

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

1 change: 1 addition & 0 deletions seed/go-sdk/no-environment/core/request_option.go

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

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

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

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

Loading

0 comments on commit 50e46b9

Please sign in to comment.