mirror of
https://github.com/openfaas/faas.git
synced 2025-06-23 15:23:29 +00:00
Support streaming responses from functions
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
This commit is contained in:
committed by
Alex Ellis
parent
02205b8b19
commit
4679f27804
16
gateway/vendor/github.com/openfaas/faas-provider/httputil/write_interceptor.go
generated
vendored
16
gateway/vendor/github.com/openfaas/faas-provider/httputil/write_interceptor.go
generated
vendored
@ -7,12 +7,17 @@ import (
|
||||
)
|
||||
|
||||
func NewHttpWriteInterceptor(w http.ResponseWriter) *HttpWriteInterceptor {
|
||||
return &HttpWriteInterceptor{w, 0}
|
||||
return &HttpWriteInterceptor{
|
||||
ResponseWriter: w,
|
||||
statusCode: 0,
|
||||
bytesWritten: 0,
|
||||
}
|
||||
}
|
||||
|
||||
type HttpWriteInterceptor struct {
|
||||
http.ResponseWriter
|
||||
statusCode int
|
||||
statusCode int
|
||||
bytesWritten int64
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Status() int {
|
||||
@ -22,6 +27,10 @@ func (c *HttpWriteInterceptor) Status() int {
|
||||
return c.statusCode
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) BytesWritten() int64 {
|
||||
return c.bytesWritten
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Header() http.Header {
|
||||
return c.ResponseWriter.Header()
|
||||
}
|
||||
@ -30,6 +39,9 @@ func (c *HttpWriteInterceptor) Write(data []byte) (int, error) {
|
||||
if c.statusCode == 0 {
|
||||
c.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
c.bytesWritten += int64(len(data))
|
||||
|
||||
return c.ResponseWriter.Write(data)
|
||||
}
|
||||
|
||||
|
52
gateway/vendor/github.com/openfaas/faas-provider/types/system_events.go
generated
vendored
Normal file
52
gateway/vendor/github.com/openfaas/faas-provider/types/system_events.go
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
TypeFunctionUsage = "function_usage"
|
||||
TypeAPIAccess = "api_access"
|
||||
)
|
||||
|
||||
type Event interface {
|
||||
EventType() string
|
||||
}
|
||||
|
||||
type FunctionUsageEvent struct {
|
||||
Namespace string `json:"namespace"`
|
||||
FunctionName string `json:"function_name"`
|
||||
Started time.Time `json:"started"`
|
||||
Duration time.Duration `json:"duration"`
|
||||
MemoryBytes int64 `json:"memory_bytes"`
|
||||
}
|
||||
|
||||
func (e FunctionUsageEvent) EventType() string {
|
||||
return TypeFunctionUsage
|
||||
}
|
||||
|
||||
type APIAccessEvent struct {
|
||||
Actor *Actor `json:"actor,omitempty"`
|
||||
Path string `json:"path"`
|
||||
Method string `json:"method"`
|
||||
Actions []string `json:"actions"`
|
||||
ResponseCode int `json:"response_code"`
|
||||
CustomMessage string `json:"custom_message,omitempty"`
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
Time time.Time `json:"time"`
|
||||
}
|
||||
|
||||
func (e APIAccessEvent) EventType() string {
|
||||
return TypeAPIAccess
|
||||
}
|
||||
|
||||
// Actor is the user that triggered an event.
|
||||
// Get from OIDC claims, we can add any of the default OIDC profile or email claim fields if desired.
|
||||
type Actor struct {
|
||||
// OIDC subject, a unique identifier of the user.
|
||||
Sub string `json:"sub"`
|
||||
// Full name of the subject, can be the name of a user of OpenFaaS component.
|
||||
Name string `json:"name,omitempty"`
|
||||
// OpenFaaS issuer
|
||||
Issuer string `json:"issuer,omitempty"`
|
||||
// Federated issuer
|
||||
FedIssuer string `json:"fed_issuer,omitempty"`
|
||||
}
|
Reference in New Issue
Block a user