How can knative functions react to multiple URL paths?

169 Views Asked by At

I have created a simple hello-world function via func create -l go and can successfully run it locally and have it deployed in k8s.

The function is not invoked if I call http://localhost:8080/some-random-path.

I suspect there is an option to configure this in the func.yml? I have not yet found any reference or documentation about this topic on the knative documentation page.

2

There are 2 best solutions below

2
E. Anderson On

Looking at the documentation generated alongside the func's go template, it looks like a Go HTTP function has access to a standard http.Request as the second or third parameter, which includes a URL field. You could use this to implement your own mux.

1
E. Anderson On

The current implementation in https://github.com/boson-project/buildpacks/blob/main/buildpacks/go/faas/main.go#L82 appears to use gorilla/mux's Router.Handle, which defines an exact match on /.

Different function implementations may define different HTTP serving semantics (some might only allow POST, others might allow only specific URLs); you could also file an issue at http://GitHub.com/knative/func/issues/new requesting a change in the behavior along with your use case.