converter 包

converter 包提供了一个 Converter 实现,帮助用户快速构建名为 converter 的 Operator:

  1. // OperatorKind means opeartor kind. All operators generated in this package
  2. // are has kind `converter`.
  3. const OperatorKind = "converter"
  4. // Converter describes a converter.
  5. type Converter interface {
  6. definition.Operator
  7. }
  8. // For creates converter for a converter func.
  9. //
  10. // A converter func should has signature:
  11. // func f(context.Context, string, AnyType) (AnyType, error)
  12. // The second parameter is a string that is used to generate error.
  13. // AnyType can be any type in go. But struct type and
  14. // built-in data type is recommended.
  15. func For(f interface{}) Converter {
  16. return definition.OperatorFunc(OperatorKind, f)
  17. }

这个包非常简单,只是提供了一个方法帮助用户将转换函数生成为 Operator。