21 lines
569 B
Go
21 lines
569 B
Go
package demo
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"example.com/managed/internal/types"
|
|
omnierrors "git.yuntuo.hk/k2safe/go-omni/errors"
|
|
)
|
|
|
|
func (l *Logic) Check(ctx context.Context, req *types.CheckReq) (*types.Receipt, error) {
|
|
switch req.Kind {
|
|
case "fixed":
|
|
return nil, omnierrors.ByCode("INVALID")
|
|
case "params":
|
|
return nil, omnierrors.ByCode("TOO_LONG").WithParams(map[string]any{"label": "企业名称", "max": 100})
|
|
case "unknown":
|
|
return nil, omnierrors.ByCode("UNKNOWN").WithCause(errors.New("private cause"))
|
|
}
|
|
return &types.Receipt{Bytes: 42}, nil
|
|
}
|