Files
2026-11-27 06:03:56 +00:00

44 lines
1.6 KiB
Plaintext

package main
import (
"context"
_ "embed"
"fmt"
"os"
component "dever/component"
)
//go:embed manifest.json
var manifest []byte
func echo(ctx context.Context, value, setting any) (any, error) {
input := value.(map[string]any)
return map[string]any{"out":input["value"],"name":input["label"]}, nil
}
func fail(ctx context.Context, value, setting any) (any, error) {
return nil, component.BusinessError{Identity:"demo.service.port.Error.Rejected", Payload:map[string]any{"message":"business rejection"}}
}
func invalid(ctx context.Context, value, setting any) (any, error) {
return map[string]any{"out":int64(200)}, nil
}
func hang(ctx context.Context, value, setting any) (any, error) {
marker := setting.(map[string]any)["marker"].(string)
if err := os.WriteFile(marker, nil, 0600); err != nil { return nil, err }
<-ctx.Done()
return nil, os.WriteFile(marker+".stopped",nil,0600)
}
func raw(ctx context.Context, value, setting any) (any, error) {
return map[string]any{"out":value.(map[string]any)["value"]}, nil
}
func floating(ctx context.Context, value, setting any) (any, error) {
return map[string]any{"out":value.(map[string]any)["value"].(float64)+0.25}, nil
}
func tool(ctx context.Context, value, setting any) (any, error) {
return map[string]any{"out":value.(map[string]any)["value"]}, nil
}
func main() {
worker, err := component.New(manifest,map[string]component.Handler{"echo":echo,"fail":fail,"invalid":invalid,"hang":hang,"raw":raw,"floating":floating,"tool":tool})
if err == nil { err = worker.Serve(os.Stdin,os.Stdout) }
if err != nil { fmt.Fprintln(os.Stderr,err); os.Exit(1) }
}