octopush/internal/actions/action.go

35 lines
708 B
Go
Raw Normal View History

2022-09-13 22:54:49 +02:00
package actions
import (
"context"
2022-09-14 23:29:54 +02:00
"errors"
2022-09-13 22:54:49 +02:00
2022-09-14 23:29:54 +02:00
"git.front.kjuulh.io/kjuulh/kraken/internal/actions/builders"
2022-09-13 22:54:49 +02:00
"git.front.kjuulh.io/kjuulh/kraken/internal/schema"
"git.front.kjuulh.io/kjuulh/kraken/internal/services/storage"
2022-09-14 23:29:54 +02:00
"go.uber.org/zap"
2022-09-13 22:54:49 +02:00
)
type Action struct {
2022-09-14 23:29:54 +02:00
Schema *schema.KrakenSchema
SchemaPath string
2022-09-13 22:54:49 +02:00
}
func (a *Action) Execute(ctx context.Context, area *storage.Area) error {
2022-09-14 23:29:54 +02:00
for _, action := range a.Schema.Actions {
switch action.Type {
case "go":
exe, err := builders.NewGo(zap.L()).Build(ctx, a.SchemaPath, action.Entry)
if err != nil {
return err
}
exe(ctx, area.Path)
default:
return errors.New("could not determine action type")
}
}
2022-09-13 22:54:49 +02:00
return nil
}