Documentation
¶
Overview ¶
Package functions is the deep module for named function apply and invoke.
Index ¶
- Constants
- func AuthenticateCall(meta *Metadata, headerToken, queryToken, hmacSig string, body []byte) bool
- func LoadDir(path string) (metadataYAML, entrypoint, source string, err error)
- func ParseStdoutJSON(stdout string) (any, error)
- func SetActiveService(svc *Service)
- func ValidateMetadata(meta *Metadata) error
- func ValidateName(name string) error
- func VerifyHMACSHA256(secret string, body []byte, signature string) bool
- type ApplyResult
- type Catalog
- type DraftView
- type ExecProvider
- type ExportBundle
- type HTTPAuth
- type HTTPConfig
- type InvokeRequest
- type InvokeResult
- type ListAllInfo
- type ListInfo
- type Metadata
- type Service
- func (s *Service) ApplyBundle(ctx context.Context, metadata, entrypoint, source, createdBy string) (*ApplyResult, error)
- func (s *Service) ApplyDir(ctx context.Context, dir, createdBy string) (*ApplyResult, error)
- func (s *Service) Create(ctx context.Context, name, entrypoint, createdBy string) (*DraftView, error)
- func (s *Service) Delete(ctx context.Context, name string) error
- func (s *Service) Export(ctx context.Context, name string) (*ExportBundle, error)
- func (s *Service) ExportVersion(ctx context.Context, name string, version int) (*ExportBundle, error)
- func (s *Service) Get(ctx context.Context, name string) (map[string]any, error)
- func (s *Service) GetDraft(ctx context.Context, name string) (*DraftView, error)
- func (s *Service) GetPublic(ctx context.Context, name string, version *int) (map[string]any, error)
- func (s *Service) Invoke(ctx context.Context, req InvokeRequest) (*InvokeResult, error)
- func (s *Service) LatestPublishedVersion(ctx context.Context, name string) (int, error)
- func (s *Service) List(ctx context.Context) ([]ListInfo, error)
- func (s *Service) ListAll(ctx context.Context) ([]ListAllInfo, error)
- func (s *Service) ListRuns(ctx context.Context, name string) ([]*model.FunctionRun, error)
- func (s *Service) Publish(ctx context.Context, name string, expectedVersion int) (*ApplyResult, error)
- func (s *Service) PublishedMetadata(ctx context.Context, name string, version *int) (*Metadata, error)
- func (s *Service) Ready() bool
- func (s *Service) SaveDraft(ctx context.Context, name, metadata, entrypoint, source string, ...) (*DraftView, error)
- func (s *Service) SetChecker(c dcg.Checker)
Constants ¶
const ( // MaxSourceBytes rejects function source above this size (256KiB). MaxSourceBytes = 256 << 10 // MaxJSONBytes is the function JSON in/out limit (64KiB). MaxJSONBytes = 64 << 10 // DefaultTimeout limits a single function invocation. DefaultTimeout = 60 * time.Second // DefaultMaxConcurrency is the global in-flight invoke limit. DefaultMaxConcurrency = 4 )
Variables ¶
This section is empty.
Functions ¶
func AuthenticateCall ¶
AuthenticateCall validates a function HTTP call using metadata token and/or HMAC. Token auth accepts headerToken (X-Webhook-Token) or queryToken. HMAC uses X-Hub-Signature-256 style "sha256=<hex>" signatures over the raw body.
func LoadDir ¶
LoadDir loads a function directory artifact (metadata.yaml + exactly one entrypoint).
func ParseStdoutJSON ¶
ParseStdoutJSON trims stdout and decodes exactly one JSON value (≤ MaxJSONBytes).
func SetActiveService ¶
func SetActiveService(svc *Service)
SetActiveService wires the package-level Service used by HTTP modules.
func ValidateMetadata ¶
ValidateMetadata requires a valid name and token and/or hmac_secret.
func ValidateName ¶
ValidateName reports whether name is a valid function identifier.
Types ¶
type ApplyResult ¶
type ApplyResult struct {
Name string `json:"name"`
ID int64 `json:"id"`
Version int `json:"version"`
Status string `json:"status"`
}
ApplyResult is returned after applying a function directory or bundle.
type Catalog ¶
type Catalog interface {
Create(ctx context.Context, name, metadata, entrypoint, source, createdBy string) error
GetByName(ctx context.Context, name string) (*model.FunctionDefinition, error)
UpdateDraft(ctx context.Context, name, metadata, entrypoint, source string, version int) (*model.FunctionDefinition, error)
Publish(ctx context.Context, name string, version int) (*model.FunctionDefinition, error)
Delete(ctx context.Context, name string) (int64, error)
ListPublished(ctx context.Context) ([]*model.FunctionDefinition, error)
ListAll(ctx context.Context) ([]*model.FunctionDefinition, error)
GetVersion(ctx context.Context, name string, version int) (*model.FunctionDefinitionVersion, error)
GetLatestPublished(ctx context.Context, name string) (*model.FunctionDefinitionVersion, error)
CreateRun(ctx context.Context, name string, version int, idempotencyKey *string) (*model.FunctionRun, error)
GetRunByIdempotency(ctx context.Context, name, key string) (*model.FunctionRun, error)
CompleteRun(ctx context.Context, id int64, status string, durationMs int64, exitCode *int, errMsg string, resultJSON *string) (*model.FunctionRun, error)
ListRuns(ctx context.Context, name string) ([]*model.FunctionRun, error)
}
Catalog loads and mutates named function definitions and runs.
type DraftView ¶
type DraftView struct {
Name string `json:"name"`
Status string `json:"status"`
Version int `json:"version"`
Entrypoint string `json:"entrypoint"`
Source string `json:"source"`
Env map[string]string `json:"env,omitempty"`
Token string `json:"token"`
TokenSet bool `json:"token_set"`
HMACSecret string `json:"hmac_secret"`
HMACSet bool `json:"hmac_set"`
PublishedVersion *int `json:"published_version,omitempty"`
HasUnpublishedChanges bool `json:"has_unpublished_changes"`
}
DraftView is a redacted draft snapshot for the management editor.
type ExecProvider ¶
ExecProvider supplies an execution Config for ephemeral function runs.
type ExportBundle ¶
type ExportBundle struct {
Metadata string `json:"metadata"`
Entrypoint string `json:"entrypoint"`
Source string `json:"source"`
Version int `json:"version"`
Name string `json:"name"`
}
ExportBundle is a published function snapshot including secrets.
type HTTPAuth ¶
type HTTPAuth struct {
Token string `yaml:"token" json:"token,omitempty"`
HMACSecret string `yaml:"hmac_secret" json:"hmac_secret,omitempty"`
}
HTTPAuth holds function HTTP authentication secrets.
type HTTPConfig ¶
type HTTPConfig struct {
Auth HTTPAuth `yaml:"auth" json:"auth"`
}
HTTPConfig holds function HTTP settings.
type InvokeRequest ¶
type InvokeRequest struct {
Name string
Version *int
Event any
IdempotencyKey string
// RequireVersion rejects calls that omit Version (pipeline / capability path).
RequireVersion bool
}
InvokeRequest configures one function invocation.
type InvokeResult ¶
type InvokeResult struct {
Name string `json:"name"`
Version int `json:"version"`
RunID int64 `json:"run_id"`
Status string `json:"status"`
Result any `json:"result,omitempty"`
Error string `json:"error,omitempty"`
ExitCode *int `json:"exit_code,omitempty"`
Replayed bool `json:"replayed,omitempty"`
}
InvokeResult is the outcome of a successful or replayed invoke.
type ListAllInfo ¶
type ListAllInfo struct {
Name string `json:"name"`
Status string `json:"status"`
Version int `json:"version"`
PublishedVersion *int `json:"published_version,omitempty"`
HasUnpublishedChanges bool `json:"has_unpublished_changes"`
}
ListAllInfo is a function summary for management list UIs (draft + published).
type ListInfo ¶
type ListInfo struct {
Name string `json:"name"`
Version int `json:"version"`
Status string `json:"status"`
}
ListInfo is a published function summary for list APIs.
type Metadata ¶
type Metadata struct {
Name string `yaml:"name" json:"name"`
HTTP HTTPConfig `yaml:"http" json:"http"`
Env map[string]string `yaml:"env" json:"env,omitempty"`
}
Metadata is the function directory metadata.yaml document.
func ParseMetadataYAML ¶
ParseMetadataYAML unmarshals and validates function metadata YAML.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service orchestrates DB-backed function apply/invoke.
func ActiveService ¶
func ActiveService() *Service
ActiveService returns the wired Service, or nil if not set.
func NewService ¶
func NewService(catalog Catalog, execProvider ExecProvider) *Service
NewService creates a function Service with default concurrency.
func NewServiceWithLimits ¶
func NewServiceWithLimits(catalog Catalog, execProvider ExecProvider, maxConcurrent int) *Service
NewServiceWithLimits creates a function Service with a custom global concurrency limit.
func (*Service) ApplyBundle ¶
func (s *Service) ApplyBundle(ctx context.Context, metadata, entrypoint, source, createdBy string) (*ApplyResult, error)
ApplyBundle validates metadata + entrypoint source, writes draft, and publishes.
func (*Service) ApplyDir ¶
ApplyDir loads a function directory, writes draft, and publishes immediately.
func (*Service) Create ¶
func (s *Service) Create(ctx context.Context, name, entrypoint, createdBy string) (*DraftView, error)
Create creates a draft-only function with a generated HTTP token and stub source.
func (*Service) ExportVersion ¶
func (s *Service) ExportVersion(ctx context.Context, name string, version int) (*ExportBundle, error)
ExportVersion returns a specific published version snapshot including secrets.
func (*Service) Get ¶
Get returns published function metadata (including secrets) for management APIs.
func (*Service) GetPublic ¶
GetPublic returns published function metadata without auth secrets or source.
func (*Service) Invoke ¶
func (s *Service) Invoke(ctx context.Context, req InvokeRequest) (*InvokeResult, error)
Invoke runs a published function version with concurrency and idempotency controls.
func (*Service) LatestPublishedVersion ¶
LatestPublishedVersion returns the version number of the latest published snapshot.
func (*Service) ListAll ¶
func (s *Service) ListAll(ctx context.Context) ([]ListAllInfo, error)
ListAll returns draft and published function summaries for management UIs.
func (*Service) Publish ¶
func (s *Service) Publish(ctx context.Context, name string, expectedVersion int) (*ApplyResult, error)
Publish publishes the current draft with optimistic locking.
func (*Service) PublishedMetadata ¶
func (s *Service) PublishedMetadata(ctx context.Context, name string, version *int) (*Metadata, error)
PublishedMetadata loads published function metadata for HTTP call authentication.
func (*Service) Ready ¶
Ready reports whether the service has a catalog and exec provider configured.
func (*Service) SaveDraft ¶
func (s *Service) SaveDraft(ctx context.Context, name, metadata, entrypoint, source string, expectedVersion int) (*DraftView, error)
SaveDraft merges secrets, validates, and updates draft with optimistic locking.
func (*Service) SetChecker ¶
SetChecker overrides the dcg checker (nil uses dcg.DefaultChecker).