github.com/go-graphite/carbonapi@v0.17.0/expr/functions/example/function.go (about) 1 package example 2 3 // THIS PACKAGE SHOULD NOT BE IMPORTED 4 // USE IT AS AN EXAMPLE OF HOW TO WRITE NEW FUNCTION 5 6 import ( 7 "context" 8 9 "github.com/go-graphite/carbonapi/expr/helper" 10 "github.com/go-graphite/carbonapi/expr/interfaces" 11 "github.com/go-graphite/carbonapi/expr/types" 12 "github.com/go-graphite/carbonapi/pkg/parser" 13 ) 14 15 type example struct{} 16 17 func GetOrder() interfaces.Order { 18 return interfaces.Any 19 } 20 21 func New(configFile string) []interfaces.FunctionMetadata { 22 res := make([]interfaces.FunctionMetadata, 0) 23 f := &example{} 24 functions := []string{"example", "examples"} 25 for _, n := range functions { 26 res = append(res, interfaces.FunctionMetadata{Name: n, F: f}) 27 } 28 return res 29 } 30 31 func (f *example) Do(ctx context.Context, eval interfaces.Evaluator, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error) { 32 _ = helper.Backref 33 return nil, nil 34 } 35 36 func (f *example) Description() map[string]types.FunctionDescription { 37 return map[string]types.FunctionDescription{ 38 "example": { 39 Description: "This is just an example of function", 40 Function: "example(seriesList, func, xFilesFactor=None)", 41 Group: "Example", 42 Module: "graphite.render.functions", 43 Name: "example", 44 Params: []types.FunctionParam{ 45 { 46 Name: "seriesList", 47 Required: true, 48 Type: types.SeriesList, 49 }, 50 }, 51 SeriesChange: false, // function aggregate metrics or change series items count 52 NameChange: false, // name changed 53 TagsChange: false, // name tag changed 54 ValuesChange: false, // values changed 55 }, 56 } 57 }