fnproject/fdk-go

fdk-go does not pass protocol info into context of handler function

sothawo opened this issue · 7 comments

in order to be able to find the http method which was used to invocate a function of format json, the context passed into a handler method in fdk-go should contain the protocol part of the JSON payload (https://github.com/fnproject/fn/blob/master/docs/developers/function-format.md).

Using the following code for a json-format function shows that this information is not passed into the handler:

func main() {
	fdk.Handle(fdk.HandlerFunc(testHandler))
}

func testHandler(ctx context.Context, in io.Reader, out io.Writer) {
	fnctx := fdk.Context(ctx)

	log.Println(fmt.Sprintf("%v", ctx))
	log.Println(fmt.Sprintf("%v", fnctx.Config))
	log.Println(fmt.Sprintf("%v", fnctx.Header))

}

Thanks @sothawo - considering how to rejig our context to expose this better, i'm not sure if we want top level fields for every json field, there's a mismatch now between http and json where if we have top level fields for json we have to yank these out of http headers and put them in there (maybe this is the right thing to do). open to ideas here

we need at least REQUEST_URL as in fdk-node (ctx.protocol.payload.request_url) in order to support GET with query_string parameters

Yeah, faced with the same need. All other FDKs provide an access to request URL, so we need to set that as well.
The justification is simple - i want to get the Fn API URL to call another function from the current one.

my use case: be able to detect an OPTION request as a CORS preflight

@sothawo @postak PR created, please review and try it out. Thanks.

sorry for the late answer, it works - I have my method info and can create a correct cors preflight answer 👍

Good to know. Awesome!