Debian Codegraph @

api/v1/lib/master/calls/calls_generated.go

raw symbols SCIP
1 package calls
2
3 // go generate -import github.com/mesos/mesos-go/api/v1/lib/master -type C:master.Call
4 // GENERATED CODE FOLLOWS; DO NOT EDIT.
5
6 import (
7 "context"
8
9 "github.com/mesos/mesos-go/api/v1/lib"
10 "github.com/mesos/mesos-go/api/v1/lib/encoding"
11
12 "github.com/mesos/mesos-go/api/v1/lib/master"
13 )
14
15 type (
16 // Request generates a Call that's sent to a Mesos agent. Subsequent invocations are expected to
17 // yield equivalent calls. Intended for use w/ non-streaming requests to an agent.
18 Request interface {
19 Call() *master.Call
20 }
21
22 // RequestFunc is the functional adaptation of Request.
23 RequestFunc func() *master.Call
24
25 // RequestStreaming generates a Call that's send to a Mesos agent. Subsequent invocations MAY generate
26 // different Call objects. No more Call objects are expected once a nil is returned to signal the end of
27 // of the request stream.
28 RequestStreaming interface {
29 Request
30 IsStreaming()
31 }
32
33 // RequestStreamingFunc is the functional adaptation of RequestStreaming.
34 RequestStreamingFunc func() *master.Call
35
36 // Send issues a Request to a Mesos agent and properly manages Call-specific mechanics.
37 Sender interface {
38 Send(context.Context, Request) (mesos.Response, error)
39 }
40
41 // SenderFunc is the functional adaptation of the Sender interface
42 SenderFunc func(context.Context, Request) (mesos.Response, error)
43 )
44
45 func (f RequestFunc) Call() *master.Call { return f() }
46
47 func (f RequestFunc) Marshaler() encoding.Marshaler {
48 // avoid returning (*master.Call)(nil) for interface type
49 if call := f(); call != nil {
50 return call
51 }
52 return nil
53 }
54
55 func (f RequestStreamingFunc) Push(c ...*master.Call) RequestStreamingFunc { return Push(f, c...) }
56
57 func (f RequestStreamingFunc) Marshaler() encoding.Marshaler {
58 // avoid returning (*master.Call)(nil) for interface type
59 if call := f(); call != nil {
60 return call
61 }
62 return nil
63 }
64
65 func (f RequestStreamingFunc) IsStreaming() {}
66
67 func (f RequestStreamingFunc) Call() *master.Call { return f() }
68
69 // Push prepends one or more calls onto a request stream. If no calls are given then the original stream is returned.
70 func Push(r RequestStreaming, c ...*master.Call) RequestStreamingFunc {
71 return func() *master.Call {
72 if len(c) == 0 {
73 return r.Call()
74 }
75 head := c[0]
76 c = c[1:]
77 return head
78 }
79 }
80
81 // Empty generates a stream that always returns nil.
82 func Empty() RequestStreamingFunc { return func() *master.Call { return nil } }
83
84 var (
85 _ = Request(RequestFunc(nil))
86 _ = RequestStreaming(RequestStreamingFunc(nil))
87 _ = Sender(SenderFunc(nil))
88 )
89
90 // NonStreaming returns a RequestFunc that always generates the same Call.
91 func NonStreaming(c *master.Call) RequestFunc { return func() *master.Call { return c } }
92
93 // FromChan returns a streaming request that fetches calls from the given channel until it closes.
94 // If a nil chan is specified then the returned func will always generate nil.
95 func FromChan(ch <-chan *master.Call) RequestStreamingFunc {
96 if ch == nil {
97 // avoid blocking forever if we're handed a nil chan
98 return func() *master.Call { return nil }
99 }
100 return func() *master.Call {
101 if m, ok := <-ch; ok {
102 return m
103 }
104 return nil
105 }
106 }
107
108 // Send implements the Sender interface for SenderFunc
109 func (f SenderFunc) Send(ctx context.Context, r Request) (mesos.Response, error) {
110 return f(ctx, r)
111 }
112
113 // IgnoreResponse generates a sender that closes any non-nil response received by Mesos.
114 func IgnoreResponse(s Sender) SenderFunc {
115 return func(ctx context.Context, r Request) (mesos.Response, error) {
116 resp, err := s.Send(ctx, r)
117 if resp != nil {
118 resp.Close()
119 }
120 return nil, err
121 }
122 }
123
124 // SendNoData is a convenience func that executes the given Call using the provided Sender
125 // and always drops the response data.
126 func SendNoData(ctx context.Context, sender Sender, r Request) (err error) {
127 _, err = IgnoreResponse(sender).Send(ctx, r)
128 return
129 }