Debian Codegraph @

api/v1/lib/extras/gen/rule_callers.go

raw symbols SCIP
1 // +build ignore
2
3 package main
4
5 import (
6 "os"
7 "text/template"
8 )
9
10 func main() {
11 Run(handlersTemplate, nil, os.Args...)
12 }
13
14 var handlersTemplate = template.Must(template.New("").Parse(`package {{.Package}}
15
16 // go generate {{.Args}}
17 // GENERATED CODE FOLLOWS; DO NOT EDIT.
18
19 import (
20 "context"
21
22 "github.com/mesos/mesos-go/api/v1/lib"
23 {{range .Imports}}
24 {{ printf "%q" . -}}
25 {{end}}
26 )
27
28 {{.RequireType "E" -}}
29 {{.RequireType "C" -}}
30 {{.RequireType "CF" -}}
31 // Call returns a Rule that invokes the given Caller
32 func Call(caller {{.Type "C"}}) Rule {
33 if caller == nil {
34 return nil
35 }
36 return func(ctx context.Context, c {{.Type "E"}}, _ mesos.Response, _ error, ch Chain) (context.Context, {{.Type "E"}}, mesos.Response, error) {
37 resp, err := caller.Call(ctx, c)
38 return ch(ctx, c, resp, err)
39 }
40 }
41
42 // CallF returns a Rule that invokes the given CallerFunc
43 func CallF(cf {{.Type "CF"}}) Rule {
44 return Call({{.Type "C"}}(cf))
45 }
46
47 // Caller returns a Rule that invokes the receiver and then calls the given Caller
48 func (r Rule) Caller(caller {{.Type "C"}}) Rule {
49 return Rules{r, Call(caller)}.Eval
50 }
51
52 // CallerF returns a Rule that invokes the receiver and then calls the given CallerFunc
53 func (r Rule) CallerF(cf {{.Type "CF"}}) Rule {
54 return r.Caller({{.Type "C"}}(cf))
55 }
56
57 // Call implements the Caller interface for Rule
58 func (r Rule) Call(ctx context.Context, c {{.Type "E"}}) (mesos.Response, error) {
59 if r == nil {
60 return nil, nil
61 }
62 _, _, resp, err := r(ctx, c, nil, nil, ChainIdentity)
63 return resp, err
64 }
65
66 // Call implements the Caller interface for Rules
67 func (rs Rules) Call(ctx context.Context, c {{.Type "E"}}) (mesos.Response, error) {
68 return Rule(rs.Eval).Call(ctx, c)
69 }
70
71 var (
72 _ = {{.Type "C"}}(Rule(nil))
73 _ = {{.Type "C"}}(Rules(nil))
74 )
75 `))