1

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.

FabianTe
  • 516
  • 4
  • 22

2 Answers2

1

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.

E. Anderson
  • 3,405
  • 1
  • 16
  • 19
0

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.

E. Anderson
  • 3,405
  • 1
  • 16
  • 19
  • To me it seems that any requests with a path != "" do not really reach the knative function. That is the first thing that would have to work. I do not mind creating / using a simple muxer. The 404 i receive does not seem to come from my function but the knative routing instead. – FabianTe Mar 25 '23 at 13:15
  • Your observations are correct. I'd missed that the framework uses `gorilla/mux`, which (unlike `http.ServeMux`) defines an exact path match semantic, which is used here: https://github.com/boson-project/buildpacks/blob/main/buildpacks/go/faas/main.go#L82 – E. Anderson Mar 26 '23 at 14:10