Documentation ¶
Index ¶
- Variables
- func FalconClientOpts() (out struct{ ... })
- func JSON(v any) json.Marshaler
- func RegisterConfigLoader(loaderType string, cr ConfigLoader)
- func RegisterRunner(runnerType string, r Runner)
- func Run[T Cfg](ctx context.Context, ...)
- type APIError
- type Cfg
- type ConfigLoader
- type File
- type Handler
- func ErrHandler(errs ...APIError) Handler
- func HandleFnOf[T any](fn func(ctx context.Context, r RequestOf[T]) Response) Handler
- func HandleWorkflow(fn func(ctx context.Context, r Request, wrkCtx WorkflowCtx) Response) Handler
- func HandleWorkflowOf[T any](fn func(ctx context.Context, r RequestOf[T], wrkCtx WorkflowCtx) Response) Handler
- func HandlerFnOfOK[T interface{ ... }](fn func(ctx context.Context, r RequestOf[T]) Response) Handler
- type HandlerFn
- type Mux
- type Request
- type RequestOf
- type Response
- type Runner
- type SkipCfg
- type WorkflowCtx
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCfgNotFound defines the inability to find a config at the expected location. ErrCfgNotFound = errors.New("no config provided") )
Functions ¶
func FalconClientOpts ¶ added in v0.9.0
FalconClientOpts provides the cloud for use with the falcon client. To setup the falcon Client you can follow the following example.
func newFalconClient(ctx context.Context, token string) (*client.CrowdStrikeAPISpecification, error) { opts := fdk.FalconClientOpts() return falcon.NewClient(&falcon.ApiConfig{ AccessToken: token, Cloud: falcon.Cloud(opts.Cloud), Context: ctx, UserAgentOverride: out.UserAgent, }) }
func RegisterConfigLoader ¶ added in v0.4.0
func RegisterConfigLoader(loaderType string, cr ConfigLoader)
RegisterConfigLoader will register a config loader at the specified type. Similar to registering a database with the database/sql, you're able to provide a config for use at runtime. During Run, the config loader defined by the env var, CS_CONFIG_LOADER_TYPE, is used. If one is not provided, then the fs config loader will be used.
func RegisterRunner ¶ added in v0.4.0
RegisterRunner registers a runner.
Types ¶
type Cfg ¶ added in v0.4.0
type Cfg interface {
OK() error
}
Cfg marks the configuration type parameter. Any config type must have a validation method, OK, defined on it.
type ConfigLoader ¶ added in v0.4.0
ConfigLoader defines the behavior for loading config.
type File ¶ added in v0.11.0
type File struct { ContentType string `json:"content_type"` Encoding string `json:"encoding"` Filename string `json:"filename"` Contents io.ReadCloser `json:"-"` }
File represents a response that is a response body. The runner is in charge of getting the contents to the destination. The metadata will be received. One note, we call NormalizeFile on the File's in the Runner's that execute the handler. Testing through the Run function will illustrate this.
func CompressGzip ¶ added in v0.12.0
CompressGzip compresses a files contents with gzip compression.
func NormalizeFile ¶ added in v0.13.0
NormalizeFile normalizes a file so that all fields are set with sane defaults.
func (File) MarshalJSON ¶ added in v0.11.0
MarshalJSON marshals the file metadata.
type Handler ¶
Handler provides a handler for our incoming request.
func ErrHandler ¶ added in v0.4.0
ErrHandler creates a new handler to respond with only errors.
func HandleFnOf ¶ added in v0.4.0
HandleFnOf provides a means to translate the incoming requests to the destination body type. This normalizes the sad path and provides the caller with a zero fuss request to work with. Reducing json boilerplate for what is essentially the same operation on different types.
func HandleWorkflow ¶ added in v0.6.0
HandleWorkflow provides a means to create a handler with workflow integration. This function does not have an opinion on the request body but does expect a workflow integration. Typically, this is useful for DELETE/GET handlers.
func HandleWorkflowOf ¶ added in v0.6.0
func HandleWorkflowOf[T any](fn func(ctx context.Context, r RequestOf[T], wrkCtx WorkflowCtx) Response) Handler
HandleWorkflowOf provides a means to create a handler with Workflow integration. This function is useful when you expect a request body and have workflow integrations. Typically, this is with PATCH/POST/PUT handlers.
func HandlerFnOfOK ¶ added in v0.19.0
func HandlerFnOfOK[T interface{ OK() []APIError }](fn func(ctx context.Context, r RequestOf[T]) Response) Handler
HandlerFnOfOK provides a means to translate the incoming requests to the destination body type and execute validation on that type. This normalizes the sad path for both the unmarshalling of the request body and the validation of that request type using its OK() method.
type HandlerFn ¶ added in v0.4.0
HandlerFn wraps a function to return a handler. Similar to the http.HandlerFunc.
type Mux ¶ added in v0.4.0
type Mux struct {
// contains filtered or unexported fields
}
Mux defines a handler that will dispatch to a matching route/method combination. Much like the std lib http.ServeMux, but with slightly more opinionated route setting. We only support the DELETE, GET, POST, and PUT.
func NewMux ¶ added in v0.4.0
func NewMux() *Mux
NewMux creates a new Mux that is ready for assignment.
func (*Mux) Handle ¶ added in v0.4.0
Handle enacts the handler to process the request/response lifecycle. The mux fulfills the Handler interface and can dispatch to any number of sub routes.
type Request ¶
Request defines a request structure that is given to the runner. The Body is set to io.Reader, to enable decoration/middleware.
type RequestOf ¶ added in v0.4.0
type RequestOf[T any] struct { FnID string FnVersion int Body T Context json.RawMessage Params struct { Header http.Header Query url.Values } URL string Method string AccessToken string TraceID string }
RequestOf provides a generic body we can target our unmarshaling into.
type Response ¶
Response is the domain type for the response.
func ErrResp ¶ added in v0.10.0
ErrResp creates a sad path errors only response.
Note: the highest status code from the errors will be used for the response status if no status code is set on the response.
func (Response) StatusCode ¶ added in v0.4.0
StatusCode returns the response status code. When a Response.Code is not set and errors exist, then the highest code on the errors is returned.
type Runner ¶ added in v0.4.0
Runner defines the runtime that executes the request/response handler lifecycle.
type SkipCfg ¶ added in v0.4.0
type SkipCfg struct{}
SkipCfg indicates the config is not needed and will skip the config loading procedure.
type WorkflowCtx ¶ added in v0.6.0
type WorkflowCtx struct { ActivityExecID string `json:"activity_execution_id"` AppID string `json:"app_id"` CID string `json:"cid"` OwnerCID string `json:"owner_cid"` DefinitionID string `json:"definition_id,omitempty"` DefinitionVersion int `json:"definition_version,omitempty"` ExecutionID string `json:"execution_id,omitempty"` Activity struct { ID string `json:"id"` Name string `json:"name"` NodeID string `json:"node_id"` } `json:"activity"` Trigger struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` } `json:"trigger"` }
WorkflowCtx is the Request.Context field when integrating a function with Falcon Fusion workflow.