countPlusOne.go 572 B

123456789101112131415161718192021222324252627
  1. package main
  2. import "fmt"
  3. type countPlusOneFunc struct {
  4. }
  5. func (f *countPlusOneFunc) Validate(args []interface{}) error{
  6. if len(args) != 1{
  7. return fmt.Errorf("countPlusOne function only supports 1 parameter but got %d", len(args))
  8. }
  9. return nil
  10. }
  11. func (f *countPlusOneFunc) Exec(args []interface{}) (interface{}, bool) {
  12. arg, ok := args[0].([]interface{})
  13. if !ok{
  14. return fmt.Errorf("arg is not a slice, got %v", args[0]), false
  15. }
  16. return len(arg) + 1, true
  17. }
  18. func (f *countPlusOneFunc) IsAggregate() bool {
  19. return true
  20. }
  21. var CountPlusOne countPlusOneFunc