1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
package httpexec
// go generate -import github.com/mesos/mesos-go/api/v1/lib/executor -import github.com/mesos/mesos-go/api/v1/lib/executor/calls -type C:executor.Call:executor.Call{Type:executor.Call_MESSAGE}
// GENERATED CODE FOLLOWS; DO NOT EDIT.
import (
"context"
"github.com/mesos/mesos-go/api/v1/lib"
"github.com/mesos/mesos-go/api/v1/lib/client"
"github.com/mesos/mesos-go/api/v1/lib/httpcli"
"github.com/mesos/mesos-go/api/v1/lib/executor"
"github.com/mesos/mesos-go/api/v1/lib/executor/calls"
)
// ResponseClassifier determines the appropriate response class for the given call.
type ResponseClassifier func(*executor.Call) (client.ResponseClass, error)
// ClientFunc sends a Request to Mesos and returns the generated Response.
type ClientFunc func(client.Request, client.ResponseClass, ...httpcli.RequestOpt) (mesos.Response, error)
// DefaultResponseClassifier is a pluggable classifier.
var DefaultResponseClassifier = ResponseClassifier(classifyResponse)
// NewSender generates a sender that uses the Mesos v1 HTTP API for encoding/decoding requests/responses.
// The ResponseClass is inferred from the first object generated by the given Request.
func NewSender(cf ClientFunc, ro ...httpcli.RequestOpt) calls.Sender {
return calls.SenderFunc(func(ctx context.Context, r calls.Request) (mesos.Response, error) {
var (
obj = r.Call()
rc, err = DefaultResponseClassifier(obj)
)
if err != nil {
return nil, err
}
var req client.Request
switch r := r.(type) {
case calls.RequestStreaming:
req = calls.Push(r, obj)
default:
req = calls.NonStreaming(obj)
}
return cf(req, rc, append(ro, httpcli.Context(ctx))...)
})
}
|