Skip to content

Commit

Permalink
add new function: registered to retrive all registered operators or f…
Browse files Browse the repository at this point in the history
…unctions
  • Loading branch information
nullne committed Dec 7, 2017
1 parent 96d0e04 commit d1070d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions function/function.go
Expand Up @@ -58,6 +58,15 @@ func Regist(name string, fn Func) error {
return nil
}

// Registered returns all registered functions or operators
func Registered() []string {
ss := make([]string, 0, len(functions))
for k, _ := range functions {
ss = append(ss, k)
}
return ss
}

// MustRegist is same as Regist but may overide if function with name existed
func MustRegist(name string, fn Func) {
functions[name] = fn
Expand Down
6 changes: 4 additions & 2 deletions function/function_test.go
@@ -1,6 +1,8 @@
package function

import "testing"
import (
"testing"
)

func TestGet(t *testing.T) {
if err := Regist("foo", foo); err != nil {
Expand All @@ -23,7 +25,7 @@ func TestGet(t *testing.T) {
if _, err := Get("fooooo"); err != ErrNotFound {
t.Error("should not found")
}

_ = Registered()
}

var foo = func(params ...interface{}) (interface{}, error) {
Expand Down

0 comments on commit d1070d7

Please sign in to comment.