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

Codegen custom helpers for builtins #1632

Closed
alecthomas opened this issue Jun 3, 2024 · 0 comments · Fixed by #2622
Closed

Codegen custom helpers for builtins #1632

alecthomas opened this issue Jun 3, 2024 · 0 comments · Fixed by #2622
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@alecthomas
Copy link
Collaborator

alecthomas commented Jun 3, 2024

It is very tedious dealing with builtin.HttpRequest/HttpResponse. Let's update the external module template with some custom helpers for that module. Something like:

func HttpSuccess[E any, B any](code int, body B) HttpResponse[B, E] {
  return HttpResponse{Status: code, Body: ftl.Some(body)}
}

func HttpError[B any, E any](code int, e E) HttpResponse[B, E] {
  return HttpResponse{Status: code, Error: ftl.Some(e)}
}

Which would replace:

return builtin.HttpResponse[MyBody, MyError]{Status: 200, Body: ftl.Some(MyBody{Field: "something"})}

With:

return builtin.HttpSuccess[MyError](200, MyBody{Field: "something"})

etc.

@alecthomas alecthomas added enhancement New feature or request good first issue Good for newcomers labels Jun 3, 2024
@github-actions github-actions bot added the triage Issue needs triaging label Jun 3, 2024
@ftl-robot ftl-robot mentioned this issue Jun 3, 2024
@alecthomas alecthomas self-assigned this Jun 3, 2024
@github-actions github-actions bot removed the triage Issue needs triaging label Jun 3, 2024
@alecthomas alecthomas removed their assignment Jun 3, 2024
@alecthomas alecthomas added triage Issue needs triaging and removed triage Issue needs triaging labels Jun 3, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 6, 2024
`builtin/external_module.go` will have a couple of helper functions
added:
```
// A helper for successful HttpResponse
//
func HttpSuccess[E any, B any](code int, body B) HttpResponse[B, E] {
  return HttpResponse[B, E]{Status: code, Body: ftl.Some(body)}
}

// A helper for HttpResponse with error
//
func HttpError[B any, E any](code int, e E) HttpResponse[B, E] {
  return HttpResponse[B, E]{Status: code, Error: ftl.Some(e)}
}
```

Fixes: #1632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants