Skip to content

Commit

Permalink
Refactor and rename variables and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Mar 1, 2024
1 parent bbda501 commit a5126a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
18 changes: 14 additions & 4 deletions act/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ import (
)

const (
LogDefaultFieldCount = 3
TerminateDefaultFieldCount = 2
// TerminateDefaultParamCount is the default parameter count for the terminate action.
TerminateDefaultParamCount = 2

// LogDefaultKeyCount is the default key count in the metadata for the log action.
LogDefaultKeyCount = 3

// These are the keys used to pass the logger and the result to the built-in actions.
LoggerKey = "__logger__"
ResultKey = "__result__"
)

// BuiltinSignals returns a map of built-in signals.
func BuiltinSignals() map[string]*sdkAct.Signal {
return map[string]*sdkAct.Signal{
"passthrough": sdkAct.Passthrough(),
Expand All @@ -23,6 +31,7 @@ func BuiltinSignals() map[string]*sdkAct.Signal {
}
}

// BuiltinPolicies returns a map of built-in policies.
func BuiltinPolicies() map[string]*sdkAct.Policy {
return map[string]*sdkAct.Policy{
"passthrough": sdkAct.MustNewPolicy("passthrough", "true", nil),
Expand All @@ -39,6 +48,7 @@ func BuiltinPolicies() map[string]*sdkAct.Policy {
}
}

// BuiltinActions returns a map of built-in actions.
func BuiltinActions() map[string]*sdkAct.Action {
return map[string]*sdkAct.Action{
"passthrough": {
Expand Down Expand Up @@ -85,7 +95,7 @@ func Terminate(_ map[string]any, params ...sdkAct.Parameter) (any, error) {
return nil, gerr.ErrLoggerRequired
}

if len(params) < TerminateDefaultFieldCount || params[1].Key != ResultKey {
if len(params) < TerminateDefaultParamCount || params[1].Key != ResultKey {
logger.Debug().Msg(
"terminate action can optionally receive a result parameter")
return true, nil
Expand Down Expand Up @@ -130,7 +140,7 @@ func Log(data map[string]any, params ...sdkAct.Parameter) (any, error) {
}

fields := map[string]any{}
if len(data) > LogDefaultFieldCount {
if len(data) > LogDefaultKeyCount {
for k, v := range data {

Check failure on line 144 in act/builtins.go

View workflow job for this annotation

GitHub Actions / Test GatewayD

variable name 'v' is too short for the scope of its usage (varnamelen)
// Skip these necessary fields, as they are already used by the logger.
// level: The log level.
Expand Down
5 changes: 0 additions & 5 deletions act/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import (
"github.com/rs/zerolog"
)

const (
LoggerKey = "__logger__"
ResultKey = "__result__"
)

type IRegistry interface {
Add(policy *sdkAct.Policy)
Apply(signals []sdkAct.Signal) []*sdkAct.Output
Expand Down

0 comments on commit a5126a0

Please sign in to comment.