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

Expand on when context needed or not in Go docs. Examples to reflect. #7179

Open
jpadams opened this issue Apr 24, 2024 · 0 comments
Open

Expand on when context needed or not in Go docs. Examples to reflect. #7179

jpadams opened this issue Apr 24, 2024 · 0 comments
Labels
area/documentation Improvements or additions to documentation

Comments

@jpadams
Copy link
Contributor

jpadams commented Apr 24, 2024

What is the issue?

Today we have a note box in the docs that says

https://docs.dagger.io/manuals/developer/go/264203/functions/

NOTE
The context and error return are optional in the module's function signature; remove them if you don't need them.

but not all developers will know when they need them or not.

In fact we have a Hello function that uses context, but doesn't need it, which is confusing.

We should expand to say something like

NOTE
The context and error return are optional in the module's function signature. Remove `context` in arguments if you don't need to use it in a leaf/terminal function like Stdout(ctx), Export(ctx, ...), Publish(ctx, ...). Remove `error` in return values if you handle all errors within the module and don't need to propogate them.

We should simplify the Hello function to remove context since it doesn't need it.

func (m *MyModule) Hello(
    // +optional
    name string,
) (string, error) {
    if name != "" {
        return fmt.Sprintf("Hello, %s", name), nil
    } else {
        return "Hello, world", nil
    }
}
@jpadams jpadams added the area/documentation Improvements or additions to documentation label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant