Documentation ¶
Overview ¶
Package funcframework is a Functions Framework implementation for Go. It allows you to register HTTP and event functions, then start an HTTP server serving those functions.
Index ¶
- func ExecutionIDFromContext(ctx context.Context) string
- func LogWriter(ctx context.Context) io.WriteCloser
- func RegisterCloudEventFunctionContext(ctx context.Context, path string, ...) error
- func RegisterEventFunction(path string, fn interface{})
- func RegisterEventFunctionContext(ctx context.Context, path string, fn interface{}) error
- func RegisterHTTPFunction(path string, fn interface{})
- func RegisterHTTPFunctionContext(ctx context.Context, path string, fn func(http.ResponseWriter, *http.Request)) error
- func SpanIDFromContext(ctx context.Context) string
- func Start(port string) error
- func StartHostPort(hostname, port string) error
- func TraceIDFromContext(ctx context.Context) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecutionIDFromContext ¶ added in v1.9.0
func LogWriter ¶ added in v1.9.0
func LogWriter(ctx context.Context) io.WriteCloser
LogWriter returns an io.Writer as a log sink for the request context. One log event is generated for each new line terminated byte sequence written to the io.Writer.
This can be used with common logging frameworks, for example:
import ( "log" "github.com/GoogleCloudPlatform/functions-framework-go/funcframework" ) ... func helloWorld(w http.ResponseWriter, r *http.Request) { l := logger.New(funcframework.LogWriter(r.Context())) l.Println("hello world!") }
func RegisterCloudEventFunctionContext ¶ added in v1.1.0
func RegisterCloudEventFunctionContext(ctx context.Context, path string, fn func(context.Context, cloudevents.Event) error) error
RegisterCloudEventFunctionContext registers fn as an cloudevent function.
func RegisterEventFunction ¶
func RegisterEventFunction(path string, fn interface{})
RegisterEventFunction registers fn as an event function. Maintained for backward compatibility. Please use RegisterEventFunctionContext instead.
func RegisterEventFunctionContext ¶ added in v1.1.0
RegisterEventFunctionContext registers fn as an event function. The function must have two arguments, a context.Context and a struct type depending on the event, and return an error. If fn has the wrong signature, RegisterEventFunction returns an error.
func RegisterHTTPFunction ¶
func RegisterHTTPFunction(path string, fn interface{})
RegisterHTTPFunction registers fn as an HTTP function. Maintained for backward compatibility. Please use RegisterHTTPFunctionContext instead.
func RegisterHTTPFunctionContext ¶ added in v1.1.0
func RegisterHTTPFunctionContext(ctx context.Context, path string, fn func(http.ResponseWriter, *http.Request)) error
RegisterHTTPFunctionContext registers fn as an HTTP function.
func SpanIDFromContext ¶ added in v1.9.0
func StartHostPort ¶ added in v1.8.0
StartHostPort serves an HTTP server with registered function(s) on the given host and port.
func TraceIDFromContext ¶ added in v1.9.0
Types ¶
This section is empty.