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

[Go] Updating a few guidelines and clarifying others #6903

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/golang/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ type WidgetClient struct {
}
```

{% include requirement/SHOULD id="golang-client-naming-onlyclient" %} name the client `Client` if the package name provides enough context.
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved

#### Service Client Constructors

{% include requirement/MUST id="golang-client-constructors" %} provide one or more constructors in the following format that return a new instance of a service client type. The "simple named" constructor MUST use an `azcore.TokenCredential`, assuming the service supports AAD authentication. If not, then the preferred credential type is used instead. Constructors MUST return the client instance by reference.
{% include requirement/MUST id="golang-client-constructors" %} provide one or more constructors in the following format that return a new instance of a service client type. The "simple named" constructor (eg: `NewClient`) MUST use an `azcore.TokenCredential`, assuming the service supports AAD authentication. If not, then the preferred credential type is used instead. Constructors MUST return the client instance by reference.
RickWinter marked this conversation as resolved.
Show resolved Hide resolved

```go
// NewWidgetClient creates a new instance of WidgetClient with the specified values.
Expand Down Expand Up @@ -443,6 +445,14 @@ TODO

{% include requirement/MUST id="golang-errors" %} return an error if a method fails to perform its intended functionality. For methods that return multiple items, the error object is always the last item in the return signature.

{% include requirement/MUST id="golang-errors-pointer" %} return custom errors (such as `azcore.ResponseError`) as a pointer. For instance:

```go
func example() error {
return &azcore.ResponseError{}
}
```

{% include requirement/SHOULD id="golang-errors-wrapping" %} wrap an error with another error if it would help in the diagnosis of the underlying failure. Expect consumers to use [error helper functions](https://blog.golang.org/go1.13-errors) like `errors.As()` and `errors.Is()`.

```go
Expand Down