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

Proposal: Update Go template to include an example that works out-of-the-box #839

Closed
salaboy opened this issue Feb 17, 2022 · 7 comments · Fixed by #840
Closed

Proposal: Update Go template to include an example that works out-of-the-box #839

salaboy opened this issue Feb 17, 2022 · 7 comments · Fixed by #840

Comments

@salaboy
Copy link
Member

salaboy commented Feb 17, 2022

Following the Spring Boot template, which includes a working function and cloud events routing based on CE-Type or an expression, it will be great if the Go template includes some working examples following the same lines. We can apply the same example to other languages too.

The Go Template just include an empty Handle function, that by default uses a signature that doesn't return a CloudEvent after processing the request.

I will create a PR with a simple example following the Spring Boot template example.

@zroubalik
Copy link
Contributor

I think this is being tracked here: #572

@salaboy
Copy link
Member Author

salaboy commented Feb 17, 2022

@zroubalik Is it ok to keep this as a sub-issue from #572 so we can use it to discuss the proposed example for Go only?

@salaboy
Copy link
Member Author

salaboy commented Feb 17, 2022

Added a PR with a simple example.. follows the same approach as the spring-boot template.. it helps to quickly have a runnable function to test and demonstrate

@lkingland
Copy link
Member

lkingland commented Feb 21, 2022

The builtin Functions are not examples, per se, but it should probably be updated to echo the event received.

The builtin Functions are intentionally not actual app examples, as they are intended to showcase the minimum necessary code to execute in order to verify functionality (an echo; such as for integration testing). They are also intended to pre-populate the user's new Function with a default function signature, in the language chosen, without leaving the user with a lot of code to delete before they can start on their own Function.

For Example Functions, perhaps see the Function Examples templates repository, where any examples would be greatly appreciated. Given an example Function in the subdirectory go/example, A Function can be created from this example as a template thus:

func create --language go --template example --repository https://github.com/boson-project/templates

Other builtin templates for other languages which currently do more than the minimum echo were likely developed before Extensible Repositories was implemented (the command above), and they should now be moved to the Function Examples repository, leaving a simple echo with a test in this repository.

@lkingland
Copy link
Member

lkingland commented Feb 21, 2022

The Go Template just include an empty Handle function, that by default uses a signature that doesn't return a CloudEvent after processing the request.

The discussion in #606 has some background on the reasoning behind this decision that might help.

The default Function should have no actual implementation other than to echo back the event received, so perhaps we can keep the more complex function signature which returns an even that you added in the referenced PR, but simply return the inbound event, with the example "uppercasing" Function as an example in the examples repo!

All Function Templates, in all languages, should already work "out of the box" including compiling (where appropriate), test, deploy and echo when invoked (see func invoke for a shortcut to try). However, the Go CloudEvents template an example of one where it is not there yet.

@salaboy
Copy link
Member Author

salaboy commented Feb 24, 2022

@lkingland ok this is cool.. so I've created this repo to test:

https://github.com/salaboy/func-templates

Do you think if we create a repo func-templates or func-examples into the knative-sandbox org we can document the examples in the official docs?

@lkingland
Copy link
Member

lkingland commented Mar 1, 2022

@lkingland ok this is cool.. so I've created this repo to test:

https://github.com/salaboy/func-templates

Do you think if we create a repo func-templates or func-examples into the knative-sandbox org we can document the examples in the official docs?

@salaboy That looks good! And I think using an official set of examples to support docs is a good idea, yes. In fact that is exactly one of the use-cases in mind when adding the "extensible template repositories" feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants