From 6017d949f4a9dfac37ed6539e00469c8e841f4a8 Mon Sep 17 00:00:00 2001 From: Scott Nichols <32305648+n3wscott@users.noreply.github.com> Date: Mon, 16 Mar 2020 12:01:27 -0700 Subject: [PATCH] rename transport to protocol. (#389) Signed-off-by: Scott Nichols --- alias.go | 6 +-- cmd/samples/amqp/receiver/main.go | 4 +- cmd/samples/amqp/sender/main.go | 4 +- cmd/samples/httpb/responder/main.go | 4 +- cmd/samples/httptonats/main.go | 6 +-- cmd/samples/kafka/receiver/main.go | 2 +- cmd/samples/kafka/sender/main.go | 2 +- cmd/samples/kafka/sender_and_receiver/main.go | 2 +- cmd/samples/nats/receiver/main.go | 4 +- cmd/samples/nats/sender/main.go | 4 +- pkg/client/client.go | 49 ++++++++++--------- pkg/client/client_default.go | 2 +- pkg/client/client_test.go | 6 +-- pkg/client/http_receiver.go | 3 +- pkg/client/invoker.go | 7 +-- pkg/client/receiver.go | 14 +++--- pkg/client/receiver_test.go | 20 ++++---- pkg/client/test/test.go | 9 ++-- pkg/{transport => protocol}/amqp/doc.go | 0 pkg/{transport => protocol}/amqp/message.go | 0 pkg/{transport => protocol}/amqp/options.go | 0 pkg/{transport => protocol}/amqp/protocol.go | 6 +-- pkg/{transport => protocol}/amqp/receiver.go | 4 +- pkg/{transport => protocol}/amqp/sender.go | 4 +- pkg/{transport => protocol}/amqp/types.go | 0 .../amqp/write_message.go | 0 pkg/{transport => protocol}/doc.go | 2 +- pkg/{transport => protocol}/error.go | 2 +- pkg/{transport => protocol}/http/doc.go | 0 pkg/{transport => protocol}/http/engine.go | 4 +- pkg/{transport => protocol}/http/message.go | 0 .../http/message_test.go | 0 pkg/{transport => protocol}/http/options.go | 0 pkg/{transport => protocol}/http/protocol.go | 10 ++-- pkg/{transport => protocol}/http/response.go | 4 +- .../http/write_request.go | 0 .../http/write_responsewriter.go | 0 .../http/write_responsewriter_test.go | 0 pkg/{transport => protocol}/inbound.go | 2 +- .../kafka_sarama/doc.go | 0 .../kafka_sarama/message.go | 0 .../kafka_sarama/message_benchmark_test.go | 2 +- .../kafka_sarama/option.go | 0 .../kafka_sarama/protocol.go | 8 +-- .../kafka_sarama/receiver.go | 6 +-- .../kafka_sarama/sender.go | 0 .../kafka_sarama/write_producer_message.go | 0 .../write_producer_message_benchmark_test.go | 2 +- .../write_producer_message_test.go | 0 pkg/{transport => protocol}/lifecycle.go | 2 +- pkg/{transport => protocol}/nats/doc.go | 0 pkg/{transport => protocol}/nats/message.go | 0 pkg/{transport => protocol}/nats/options.go | 0 .../nats/options_test.go | 0 pkg/{transport => protocol}/nats/protocol.go | 3 +- .../nats/write_message.go | 0 pkg/{transport => protocol}/outbound.go | 2 +- pkg/{transport => protocol}/result.go | 2 +- pkg/{transport => protocol}/test/benchmark.go | 5 +- pkg/{transport => protocol}/test/doc.go | 0 pkg/{transport => protocol}/test/test.go | 4 +- pkg/{transport => protocol}/test/test_test.go | 2 +- .../http_transformers_benchmark_test.go | 2 +- test/benchmark/e2e/http/http_mock.go | 6 +-- test/benchmark/e2e/http/main.go | 2 +- .../benchmark_test.go | 4 +- .../benchmark_test.go | 4 +- test/integration/amqp_binding/amqp_test.go | 6 +-- test/integration/http/direct.go | 5 +- test/integration/http/loopback.go | 2 +- test/integration/http/middleware.go | 5 +- test/integration/http_binding/http_test.go | 6 +-- test/integration/kafka_sarama/kafka_test.go | 2 +- .../kafka_sarama_binding/kafka_test.go | 6 +-- 74 files changed, 140 insertions(+), 134 deletions(-) rename pkg/{transport => protocol}/amqp/doc.go (100%) rename pkg/{transport => protocol}/amqp/message.go (100%) rename pkg/{transport => protocol}/amqp/options.go (100%) rename pkg/{transport => protocol}/amqp/protocol.go (95%) rename pkg/{transport => protocol}/amqp/receiver.go (84%) rename pkg/{transport => protocol}/amqp/sender.go (93%) rename pkg/{transport => protocol}/amqp/types.go (100%) rename pkg/{transport => protocol}/amqp/write_message.go (100%) rename pkg/{transport => protocol}/doc.go (97%) rename pkg/{transport => protocol}/error.go (98%) rename pkg/{transport => protocol}/http/doc.go (100%) rename pkg/{transport => protocol}/http/engine.go (97%) rename pkg/{transport => protocol}/http/message.go (100%) rename pkg/{transport => protocol}/http/message_test.go (100%) rename pkg/{transport => protocol}/http/options.go (100%) rename pkg/{transport => protocol}/http/protocol.go (95%) rename pkg/{transport => protocol}/http/response.go (93%) rename pkg/{transport => protocol}/http/write_request.go (100%) rename pkg/{transport => protocol}/http/write_responsewriter.go (100%) rename pkg/{transport => protocol}/http/write_responsewriter_test.go (100%) rename pkg/{transport => protocol}/inbound.go (98%) rename pkg/{transport => protocol}/kafka_sarama/doc.go (100%) rename pkg/{transport => protocol}/kafka_sarama/message.go (100%) rename pkg/{transport => protocol}/kafka_sarama/message_benchmark_test.go (97%) rename pkg/{transport => protocol}/kafka_sarama/option.go (100%) rename pkg/{transport => protocol}/kafka_sarama/protocol.go (94%) rename pkg/{transport => protocol}/kafka_sarama/receiver.go (95%) rename pkg/{transport => protocol}/kafka_sarama/sender.go (100%) rename pkg/{transport => protocol}/kafka_sarama/write_producer_message.go (100%) rename pkg/{transport => protocol}/kafka_sarama/write_producer_message_benchmark_test.go (94%) rename pkg/{transport => protocol}/kafka_sarama/write_producer_message_test.go (100%) rename pkg/{transport => protocol}/lifecycle.go (94%) rename pkg/{transport => protocol}/nats/doc.go (100%) rename pkg/{transport => protocol}/nats/message.go (100%) rename pkg/{transport => protocol}/nats/options.go (100%) rename pkg/{transport => protocol}/nats/options_test.go (100%) rename pkg/{transport => protocol}/nats/protocol.go (99%) rename pkg/{transport => protocol}/nats/write_message.go (100%) rename pkg/{transport => protocol}/outbound.go (98%) rename pkg/{transport => protocol}/result.go (98%) rename pkg/{transport => protocol}/test/benchmark.go (86%) rename pkg/{transport => protocol}/test/doc.go (100%) rename pkg/{transport => protocol}/test/test.go (86%) rename pkg/{transport => protocol}/test/test_test.go (95%) diff --git a/alias.go b/alias.go index b4a4837a2..3604f9f6b 100644 --- a/alias.go +++ b/alias.go @@ -9,8 +9,8 @@ import ( "github.com/cloudevents/sdk-go/pkg/context" "github.com/cloudevents/sdk-go/pkg/event" "github.com/cloudevents/sdk-go/pkg/observability" - "github.com/cloudevents/sdk-go/pkg/transport" - "github.com/cloudevents/sdk-go/pkg/transport/http" + "github.com/cloudevents/sdk-go/pkg/protocol" + "github.com/cloudevents/sdk-go/pkg/protocol/http" "github.com/cloudevents/sdk-go/pkg/types" ) @@ -93,7 +93,7 @@ var ( // Event Creation NewEvent = event.New - NewResult = transport.NewResult + NewResult = protocol.NewResult NewHTTPResponse = http.NewResult diff --git a/cmd/samples/amqp/receiver/main.go b/cmd/samples/amqp/receiver/main.go index 4520c0bbc..b275792d7 100644 --- a/cmd/samples/amqp/receiver/main.go +++ b/cmd/samples/amqp/receiver/main.go @@ -10,7 +10,7 @@ import ( ce "github.com/cloudevents/sdk-go" "github.com/cloudevents/sdk-go/pkg/client" - ceamqp "github.com/cloudevents/sdk-go/pkg/transport/amqp" + ceamqp "github.com/cloudevents/sdk-go/pkg/protocol/amqp" amqp "pack.ag/amqp" ) @@ -37,7 +37,7 @@ func main() { host, node, opts := sampleConfig() t, err := ceamqp.New(host, node, opts...) if err != nil { - log.Fatalf("Failed to create AMQP transport: %v", err) + log.Fatalf("Failed to create AMQP protocol: %v", err) } c, err := client.New(t) if err != nil { diff --git a/cmd/samples/amqp/sender/main.go b/cmd/samples/amqp/sender/main.go index f783f05fb..b050a9ceb 100644 --- a/cmd/samples/amqp/sender/main.go +++ b/cmd/samples/amqp/sender/main.go @@ -12,7 +12,7 @@ import ( cloudevents "github.com/cloudevents/sdk-go" "github.com/cloudevents/sdk-go/pkg/client" "github.com/cloudevents/sdk-go/pkg/event" - ceamqp "github.com/cloudevents/sdk-go/pkg/transport/amqp" + ceamqp "github.com/cloudevents/sdk-go/pkg/protocol/amqp" "github.com/cloudevents/sdk-go/pkg/types" "github.com/google/uuid" "pack.ag/amqp" @@ -72,7 +72,7 @@ func main() { host, node, opts := sampleConfig() t, err := ceamqp.New(host, node, opts...) if err != nil { - log.Fatalf("Failed to create amqp transport: %v", err) + log.Fatalf("Failed to create amqp protocol: %v", err) } c, err := client.New(t) if err != nil { diff --git a/cmd/samples/httpb/responder/main.go b/cmd/samples/httpb/responder/main.go index bfbd256b8..c5e3282c4 100644 --- a/cmd/samples/httpb/responder/main.go +++ b/cmd/samples/httpb/responder/main.go @@ -7,7 +7,7 @@ import ( "net/http" "os" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" cloudevents "github.com/cloudevents/sdk-go" "github.com/cloudevents/sdk-go/pkg/event" @@ -47,7 +47,7 @@ func main() { } } -func gotEvent(ctx context.Context, event cloudevents.Event) (*event.Event, transport.Result) { +func gotEvent(ctx context.Context, event cloudevents.Event) (*event.Event, protocol.Result) { fmt.Printf("Got Event: %+v\n", event) return &event, cloudevents.NewHTTPResponse(http.StatusAccepted, "accept") diff --git a/cmd/samples/httptonats/main.go b/cmd/samples/httptonats/main.go index f771c80ab..ead432d49 100644 --- a/cmd/samples/httptonats/main.go +++ b/cmd/samples/httptonats/main.go @@ -8,8 +8,8 @@ import ( "github.com/cloudevents/sdk-go/pkg/client" "github.com/cloudevents/sdk-go/pkg/event" - cloudeventshttp "github.com/cloudevents/sdk-go/pkg/transport/http" - cloudeventsnats "github.com/cloudevents/sdk-go/pkg/transport/nats" + cloudeventshttp "github.com/cloudevents/sdk-go/pkg/protocol/http" + cloudeventsnats "github.com/cloudevents/sdk-go/pkg/protocol/nats" "github.com/kelseyhightower/envconfig" ) @@ -66,7 +66,7 @@ func _main(args []string, env envConfig) int { np, err := cloudeventsnats.New(env.NATSServer, env.Subject) if err != nil { - log.Fatalf("failed to create nats transport, %s", err.Error()) + log.Fatalf("failed to create nats protcol, %s", err.Error()) } nc, err := client.New(np) if err != nil { diff --git a/cmd/samples/kafka/receiver/main.go b/cmd/samples/kafka/receiver/main.go index 30cdf0bf2..def811251 100644 --- a/cmd/samples/kafka/receiver/main.go +++ b/cmd/samples/kafka/receiver/main.go @@ -8,7 +8,7 @@ import ( "github.com/Shopify/sarama" cloudevents "github.com/cloudevents/sdk-go" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" ) func main() { diff --git a/cmd/samples/kafka/sender/main.go b/cmd/samples/kafka/sender/main.go index c35cd5b8a..1cc6e3aa4 100644 --- a/cmd/samples/kafka/sender/main.go +++ b/cmd/samples/kafka/sender/main.go @@ -7,7 +7,7 @@ import ( "github.com/Shopify/sarama" cloudevents "github.com/cloudevents/sdk-go" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" ) func main() { diff --git a/cmd/samples/kafka/sender_and_receiver/main.go b/cmd/samples/kafka/sender_and_receiver/main.go index b8d48f676..e34b6da8b 100644 --- a/cmd/samples/kafka/sender_and_receiver/main.go +++ b/cmd/samples/kafka/sender_and_receiver/main.go @@ -8,7 +8,7 @@ import ( "github.com/Shopify/sarama" cloudevents "github.com/cloudevents/sdk-go" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" ) func main() { diff --git a/cmd/samples/nats/receiver/main.go b/cmd/samples/nats/receiver/main.go index f28277e3f..7053e3d7e 100644 --- a/cmd/samples/nats/receiver/main.go +++ b/cmd/samples/nats/receiver/main.go @@ -8,7 +8,7 @@ import ( "github.com/cloudevents/sdk-go/pkg/client" "github.com/cloudevents/sdk-go/pkg/event" - cloudeventsnats "github.com/cloudevents/sdk-go/pkg/transport/nats" + cloudeventsnats "github.com/cloudevents/sdk-go/pkg/protocol/nats" "github.com/kelseyhightower/envconfig" ) @@ -30,7 +30,7 @@ func main() { p, err := cloudeventsnats.New(env.NATSServer, env.Subject) if err != nil { - log.Fatalf("failed to create nats transport, %s", err.Error()) + log.Fatalf("failed to create nats protocol, %s", err.Error()) } c, err := client.New(p) if err != nil { diff --git a/cmd/samples/nats/sender/main.go b/cmd/samples/nats/sender/main.go index 041509459..352e238e7 100644 --- a/cmd/samples/nats/sender/main.go +++ b/cmd/samples/nats/sender/main.go @@ -9,7 +9,7 @@ import ( "github.com/cloudevents/sdk-go/pkg/client" "github.com/cloudevents/sdk-go/pkg/event" - cloudeventsnats "github.com/cloudevents/sdk-go/pkg/transport/nats" + cloudeventsnats "github.com/cloudevents/sdk-go/pkg/protocol/nats" "github.com/google/uuid" "github.com/kelseyhightower/envconfig" ) @@ -41,7 +41,7 @@ func main() { for _, contentType := range []string{"application/json", "application/xml"} { p, err := cloudeventsnats.New(env.NATSServer, env.Subject) if err != nil { - log.Printf("failed to create nats transport, %s", err.Error()) + log.Printf("failed to create nats protocol, %s", err.Error()) os.Exit(1) } c, err := client.New(p) diff --git a/pkg/client/client.go b/pkg/client/client.go index 5735d5b70..035af63c2 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -4,14 +4,15 @@ import ( "context" "errors" "fmt" - "github.com/cloudevents/sdk-go/pkg/binding" - cecontext "github.com/cloudevents/sdk-go/pkg/context" - "go.uber.org/zap" "io" "sync" + "go.uber.org/zap" + + "github.com/cloudevents/sdk-go/pkg/binding" + cecontext "github.com/cloudevents/sdk-go/pkg/context" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) // Client interface defines the runtime contract the CloudEvents client supports. @@ -24,43 +25,43 @@ type Client interface { Request(ctx context.Context, event event.Event) (*event.Event, error) // StartReceiver will register the provided function for callback on receipt - // of a cloudevent. It will also start the underlying transport as it has + // of a cloudevent. It will also start the underlying protocol as it has // been configured. // This call is blocking. // Valid fn signatures are: // * func() // * func() error // * func(context.Context) - // * func(context.Context) transport.Result + // * func(context.Context) protocol.Result // * func(event.Event) - // * func(event.Event) transport.Result + // * func(event.Event) protocol.Result // * func(context.Context, event.Event) - // * func(context.Context, event.Event) transport.Result + // * func(context.Context, event.Event) protocol.Result // * func(event.Event) *event.Event - // * func(event.Event) (*event.Event, transport.Result) + // * func(event.Event) (*event.Event, protocol.Result) // * func(context.Context, event.Event) *event.Event - // * func(context.Context, event.Event) (*event.Event, transport.Result) + // * func(context.Context, event.Event) (*event.Event, protocol.Result) StartReceiver(ctx context.Context, fn interface{}) error } // New produces a new client with the provided transport object and applied // client options. -func New(protocol interface{}, opts ...Option) (Client, error) { +func New(obj interface{}, opts ...Option) (Client, error) { c := &ceClient{} - if p, ok := protocol.(transport.Sender); ok { + if p, ok := obj.(protocol.Sender); ok { c.sender = p } - if p, ok := protocol.(transport.Requester); ok { + if p, ok := obj.(protocol.Requester); ok { c.requester = p } - if p, ok := protocol.(transport.Responder); ok { + if p, ok := obj.(protocol.Responder); ok { c.responder = p } - if p, ok := protocol.(transport.Receiver); ok { + if p, ok := obj.(protocol.Receiver); ok { c.receiver = p } - if p, ok := protocol.(transport.Opener); ok { + if p, ok := obj.(protocol.Opener); ok { c.opener = p } @@ -71,12 +72,12 @@ func New(protocol interface{}, opts ...Option) (Client, error) { } type ceClient struct { - sender transport.Sender - requester transport.Requester - receiver transport.Receiver - responder transport.Responder + sender protocol.Sender + requester protocol.Requester + receiver protocol.Receiver + responder protocol.Responder // Optional. - opener transport.Opener + opener protocol.Opener outboundContextDecorators []func(context.Context) context.Context invoker Invoker @@ -167,10 +168,10 @@ func (c *ceClient) StartReceiver(ctx context.Context, fn interface{}) error { return err } if invoker.IsReceiver() && c.receiver == nil { - return fmt.Errorf("mismatched receiver callback without transport.Receiver supported by protocol") + return fmt.Errorf("mismatched receiver callback without protocol.Receiver supported by protocol") } if invoker.IsResponder() && c.responder == nil { - return fmt.Errorf("mismatched receiver callback without transport.Responder supported by protocol") + return fmt.Errorf("mismatched receiver callback without protocol.Responder supported by protocol") } c.invoker = invoker @@ -189,7 +190,7 @@ func (c *ceClient) StartReceiver(ctx context.Context, fn interface{}) error { } var msg binding.Message - var respFn transport.ResponseFn + var respFn protocol.ResponseFn // Start Polling. for { if c.responder != nil { diff --git a/pkg/client/client_default.go b/pkg/client/client_default.go index fbd9bbecb..ff448eec2 100644 --- a/pkg/client/client_default.go +++ b/pkg/client/client_default.go @@ -1,7 +1,7 @@ package client import ( - "github.com/cloudevents/sdk-go/pkg/transport/http" + "github.com/cloudevents/sdk-go/pkg/protocol/http" ) // NewDefault provides the good defaults for the common case using an HTTP diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 80ec5992d..bdf280416 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -19,8 +19,8 @@ import ( "github.com/cloudevents/sdk-go/pkg/client" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport" - cehttp "github.com/cloudevents/sdk-go/pkg/transport/http" + "github.com/cloudevents/sdk-go/pkg/protocol" + cehttp "github.com/cloudevents/sdk-go/pkg/protocol/http" "github.com/cloudevents/sdk-go/pkg/types" ) @@ -514,7 +514,7 @@ func TestTracedClientReceive(t *testing.T) { ctx, cancel := context.WithCancel(context.TODO()) go func() { - err = c.StartReceiver(ctx, func(ctx context.Context, e event.Event) (*event.Event, transport.Result) { + err = c.StartReceiver(ctx, func(ctx context.Context, e event.Event) (*event.Event, protocol.Result) { go func() { _, span := client.TraceSpan(ctx, e) defer span.End() diff --git a/pkg/client/http_receiver.go b/pkg/client/http_receiver.go index 7e69c7f70..75b916bf8 100644 --- a/pkg/client/http_receiver.go +++ b/pkg/client/http_receiver.go @@ -2,8 +2,9 @@ package client import ( "context" - thttp "github.com/cloudevents/sdk-go/pkg/transport/http" "net/http" + + thttp "github.com/cloudevents/sdk-go/pkg/protocol/http" ) func NewHTTPReceiveHandler(ctx context.Context, p *thttp.Protocol, fn interface{}) (*EventReceiver, error) { diff --git a/pkg/client/invoker.go b/pkg/client/invoker.go index 542e8742c..034c3df06 100644 --- a/pkg/client/invoker.go +++ b/pkg/client/invoker.go @@ -3,12 +3,13 @@ package client import ( "context" "fmt" + "github.com/cloudevents/sdk-go/pkg/binding" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) type Invoker interface { - Invoke(context.Context, binding.Message, transport.ResponseFn) error + Invoke(context.Context, binding.Message, protocol.ResponseFn) error IsReceiver() bool IsResponder() bool } @@ -34,7 +35,7 @@ type receiveInvoker struct { eventDefaulterFns []EventDefaulter } -func (r *receiveInvoker) Invoke(ctx context.Context, m binding.Message, respFn transport.ResponseFn) (err error) { +func (r *receiveInvoker) Invoke(ctx context.Context, m binding.Message, respFn protocol.ResponseFn) (err error) { defer func() { if err2 := m.Finish(err); err2 == nil { err = err2 diff --git a/pkg/client/receiver.go b/pkg/client/receiver.go index fe5cafbab..83ce968cb 100644 --- a/pkg/client/receiver.go +++ b/pkg/client/receiver.go @@ -7,11 +7,11 @@ import ( "reflect" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) // Receive is the signature of a fn to be invoked for incoming cloudevents. -type ReceiveFull func(context.Context, event.Event) transport.Result +type ReceiveFull func(context.Context, event.Event) protocol.Result type receiverFn struct { numIn int @@ -27,14 +27,14 @@ type receiverFn struct { const ( inParamUsage = "expected a function taking either no parameters, one or more of (context.Context, event.Event) ordered" - outParamUsage = "expected a function returning one or mode of (*event.Event, transport.Result) ordered" + outParamUsage = "expected a function returning one or mode of (*event.Event, protocol.Result) ordered" ) var ( contextType = reflect.TypeOf((*context.Context)(nil)).Elem() eventType = reflect.TypeOf((*event.Event)(nil)).Elem() eventPtrType = reflect.TypeOf((*event.Event)(nil)) // want the ptr type - resultType = reflect.TypeOf((*transport.Result)(nil)).Elem() + resultType = reflect.TypeOf((*protocol.Result)(nil)).Elem() ) // receiver creates a receiverFn wrapper class that is used by the client to @@ -72,7 +72,7 @@ func receiver(fn interface{}) (*receiverFn, error) { return r, nil } -func (r *receiverFn) invoke(ctx context.Context, e event.Event) (*event.Event, transport.Result) { +func (r *receiverFn) invoke(ctx context.Context, e event.Event) (*event.Event, protocol.Result) { args := make([]reflect.Value, 0, r.numIn) if r.numIn > 0 { @@ -84,7 +84,7 @@ func (r *receiverFn) invoke(ctx context.Context, e event.Event) (*event.Event, t } } v := r.fnValue.Call(args) - var respOut transport.Result + var respOut protocol.Result var eOut *event.Event if r.numOut > 0 { i := 0 @@ -95,7 +95,7 @@ func (r *receiverFn) invoke(ctx context.Context, e event.Event) (*event.Event, t i++ // <-- note, need to inc i. } if r.hasResultOut { - if resp, ok := v[i].Interface().(transport.Result); ok { + if resp, ok := v[i].Interface().(protocol.Result); ok { respOut = resp } } diff --git a/pkg/client/receiver_test.go b/pkg/client/receiver_test.go index 5e358005b..32b609d38 100644 --- a/pkg/client/receiver_test.go +++ b/pkg/client/receiver_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" "github.com/google/go-cmp/cmp" ) @@ -20,7 +20,7 @@ func TestReceiverFnValidTypes(t *testing.T) { "ctx+Event in, no out": func(context.Context, event.Event) {}, "no in, error out": func() error { return nil }, - "no in, Result out": func() transport.Result { return nil }, + "no in, Result out": func() protocol.Result { return nil }, "no in, Event+error out": func() (*event.Event, error) { return nil, nil }, "ctx in, error out": func(context.Context) error { return nil }, @@ -35,9 +35,9 @@ func TestReceiverFnValidTypes(t *testing.T) { "Event in, Event+error out": func(event.Event) (*event.Event, error) { return nil, nil }, "ctx+Event in, Event+error out": func(context.Context, event.Event) (*event.Event, error) { return nil, nil }, - "ctx in, Event+Result out": func(context.Context) (*event.Event, transport.Result) { return nil, nil }, - "Event in, Event+Result out": func(event.Event) (*event.Event, transport.Result) { return nil, nil }, - "ctx+Event in, Event+Result out": func(context.Context, event.Event) (*event.Event, transport.Result) { return nil, nil }, + "ctx in, Event+Result out": func(context.Context) (*event.Event, protocol.Result) { return nil, nil }, + "Event in, Event+Result out": func(event.Event) (*event.Event, protocol.Result) { return nil, nil }, + "ctx+Event in, Event+Result out": func(context.Context, event.Event) (*event.Event, protocol.Result) { return nil, nil }, } { t.Run(name, func(t *testing.T) { if _, err := receiver(fn); err != nil { @@ -53,7 +53,7 @@ func TestReceiverFnInvalidTypes(t *testing.T) { "wrong type out": func() string { return "" }, "extra in": func(context.Context, event.Event, map[string]string) {}, "extra out": func(context.Context) (error, int) { return nil, 0 }, - "dup error out": func(context.Context) (transport.Result, error) { return nil, nil }, + "dup error out": func(context.Context) (protocol.Result, error) { return nil, nil }, "context dup Event out": func(context.Context) (*event.Event, *event.Event) { return nil, nil }, "context dup Event in": func(context.Context, event.Event, event.Event) {}, "dup Event in": func(event.Event, event.Event) {}, @@ -85,7 +85,7 @@ func TestReceiverFnInvoke_1(t *testing.T) { } wantResult := errors.New("UNIT TEST") - fn, err := receiver(func(ctx context.Context, event event.Event) (*event.Event, transport.Result) { + fn, err := receiver(func(ctx context.Context, event event.Event) (*event.Event, protocol.Result) { if diff := cmp.Diff(wantCtx.Value(key), ctx.Value(key)); diff != "" { t.Errorf("unexpected context (-want, +got) = %v", diff) } @@ -124,7 +124,7 @@ func TestReceiverFnInvoke_2(t *testing.T) { } wantResult := errors.New("UNIT TEST") - fn, err := receiver(func(event event.Event) (*event.Event, transport.Result) { + fn, err := receiver(func(event event.Event) (*event.Event, protocol.Result) { if diff := cmp.Diff(wantEvent, event); diff != "" { t.Errorf("unexpected event (-want, +got) = %v", diff) } @@ -187,7 +187,7 @@ func TestReceiverFnInvoke_4(t *testing.T) { } wantResult := errors.New("UNIT TEST") - fn, err := receiver(func() (*event.Event, transport.Result) { + fn, err := receiver(func() (*event.Event, protocol.Result) { return wantResp, wantResult }) if err != nil { @@ -212,7 +212,7 @@ func TestReceiverFnInvoke_5(t *testing.T) { var wantResp *event.Event wantResult := errors.New("UNIT TEST") - fn, err := receiver(func() transport.Result { + fn, err := receiver(func() protocol.Result { return wantResult }) if err != nil { diff --git a/pkg/client/test/test.go b/pkg/client/test/test.go index d8b3b4dbe..739e846d1 100644 --- a/pkg/client/test/test.go +++ b/pkg/client/test/test.go @@ -5,19 +5,20 @@ import ( "sync" "testing" + "github.com/cloudevents/sdk-go/pkg/protocol" + "github.com/stretchr/testify/require" "github.com/cloudevents/sdk-go/pkg/client" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport" ) // SendReceive does client.Send(in), then it receives the message using client.StartReceiver() and executes outAssert // Halt test on error. func SendReceive(t *testing.T, protocolFactory func() interface{}, in event.Event, outAssert func(e event.Event), opts ...client.Option) { t.Helper() - protocol := protocolFactory() - c, err := client.New(protocol, opts...) + pf := protocolFactory() + c, err := client.New(pf, opts...) require.NoError(t, err) wg := sync.WaitGroup{} wg.Add(2) @@ -50,7 +51,7 @@ func SendReceive(t *testing.T, protocolFactory func() interface{}, in event.Even wg.Wait() - if closer, ok := protocol.(transport.Closer); ok { + if closer, ok := pf.(protocol.Closer); ok { require.NoError(t, closer.Close(context.TODO())) } } diff --git a/pkg/transport/amqp/doc.go b/pkg/protocol/amqp/doc.go similarity index 100% rename from pkg/transport/amqp/doc.go rename to pkg/protocol/amqp/doc.go diff --git a/pkg/transport/amqp/message.go b/pkg/protocol/amqp/message.go similarity index 100% rename from pkg/transport/amqp/message.go rename to pkg/protocol/amqp/message.go diff --git a/pkg/transport/amqp/options.go b/pkg/protocol/amqp/options.go similarity index 100% rename from pkg/transport/amqp/options.go rename to pkg/protocol/amqp/options.go diff --git a/pkg/transport/amqp/protocol.go b/pkg/protocol/amqp/protocol.go similarity index 95% rename from pkg/transport/amqp/protocol.go rename to pkg/protocol/amqp/protocol.go index 40b604359..a543b8291 100644 --- a/pkg/transport/amqp/protocol.go +++ b/pkg/protocol/amqp/protocol.go @@ -7,7 +7,7 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding" cecontext "github.com/cloudevents/sdk-go/pkg/context" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) type Protocol struct { @@ -22,11 +22,11 @@ type Protocol struct { Node string // Sender - Sender transport.Sender + Sender protocol.Sender SenderContextDecorators []func(context.Context) context.Context // Receiver - Receiver transport.Receiver + Receiver protocol.Receiver } // New creates a new amqp transport. diff --git a/pkg/transport/amqp/receiver.go b/pkg/protocol/amqp/receiver.go similarity index 84% rename from pkg/transport/amqp/receiver.go rename to pkg/protocol/amqp/receiver.go index a28dabfd1..5366cb589 100644 --- a/pkg/transport/amqp/receiver.go +++ b/pkg/protocol/amqp/receiver.go @@ -4,7 +4,7 @@ import ( "context" "github.com/cloudevents/sdk-go/pkg/binding" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" "pack.ag/amqp" ) @@ -23,6 +23,6 @@ func (r *receiver) Receive(ctx context.Context) (binding.Message, error) { func (r *receiver) Close(ctx context.Context) error { return r.amqp.Close(ctx) } // Create a new Receiver which wraps an amqp.Receiver in a binding.Receiver -func NewReceiver(amqp *amqp.Receiver) transport.Receiver { +func NewReceiver(amqp *amqp.Receiver) protocol.Receiver { return &receiver{amqp: amqp} } diff --git a/pkg/transport/amqp/sender.go b/pkg/protocol/amqp/sender.go similarity index 93% rename from pkg/transport/amqp/sender.go rename to pkg/protocol/amqp/sender.go index f12dacc1b..beec578ce 100644 --- a/pkg/transport/amqp/sender.go +++ b/pkg/protocol/amqp/sender.go @@ -6,7 +6,7 @@ import ( "pack.ag/amqp" "github.com/cloudevents/sdk-go/pkg/binding" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) // sender wraps an amqp.Sender as a binding.Sender @@ -34,7 +34,7 @@ func (s *sender) Send(ctx context.Context, in binding.Message) error { func (s *sender) Close(ctx context.Context) error { return s.amqp.Close(ctx) } // Create a new Sender which wraps an amqp.Sender in a binding.Sender -func NewSender(amqpSender *amqp.Sender, options ...SenderOptionFunc) transport.Sender { +func NewSender(amqpSender *amqp.Sender, options ...SenderOptionFunc) protocol.Sender { s := &sender{amqp: amqpSender, transformers: make(binding.TransformerFactories, 0)} for _, o := range options { o(s) diff --git a/pkg/transport/amqp/types.go b/pkg/protocol/amqp/types.go similarity index 100% rename from pkg/transport/amqp/types.go rename to pkg/protocol/amqp/types.go diff --git a/pkg/transport/amqp/write_message.go b/pkg/protocol/amqp/write_message.go similarity index 100% rename from pkg/transport/amqp/write_message.go rename to pkg/protocol/amqp/write_message.go diff --git a/pkg/transport/doc.go b/pkg/protocol/doc.go similarity index 97% rename from pkg/transport/doc.go rename to pkg/protocol/doc.go index 2f86f50dc..ac31166fc 100644 --- a/pkg/transport/doc.go +++ b/pkg/protocol/doc.go @@ -23,4 +23,4 @@ Available bindings: */ -package transport +package protocol diff --git a/pkg/transport/error.go b/pkg/protocol/error.go similarity index 98% rename from pkg/transport/error.go rename to pkg/protocol/error.go index bb4e8ec9f..894cbbf3b 100644 --- a/pkg/transport/error.go +++ b/pkg/protocol/error.go @@ -1,4 +1,4 @@ -package transport +package protocol import "fmt" diff --git a/pkg/transport/http/doc.go b/pkg/protocol/http/doc.go similarity index 100% rename from pkg/transport/http/doc.go rename to pkg/protocol/http/doc.go diff --git a/pkg/transport/http/engine.go b/pkg/protocol/http/engine.go similarity index 97% rename from pkg/transport/http/engine.go rename to pkg/protocol/http/engine.go index fdc151b8f..900ce77a2 100644 --- a/pkg/transport/http/engine.go +++ b/pkg/protocol/http/engine.go @@ -7,12 +7,12 @@ import ( "net/http" "strings" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" "go.opencensus.io/plugin/ochttp" "go.opencensus.io/plugin/ochttp/propagation/tracecontext" ) -var _ transport.Opener = (*Protocol)(nil) +var _ protocol.Opener = (*Protocol)(nil) func (e *Protocol) OpenInbound(ctx context.Context) error { e.reMu.Lock() diff --git a/pkg/transport/http/message.go b/pkg/protocol/http/message.go similarity index 100% rename from pkg/transport/http/message.go rename to pkg/protocol/http/message.go diff --git a/pkg/transport/http/message_test.go b/pkg/protocol/http/message_test.go similarity index 100% rename from pkg/transport/http/message_test.go rename to pkg/protocol/http/message_test.go diff --git a/pkg/transport/http/options.go b/pkg/protocol/http/options.go similarity index 100% rename from pkg/transport/http/options.go rename to pkg/protocol/http/options.go diff --git a/pkg/transport/http/protocol.go b/pkg/protocol/http/protocol.go similarity index 95% rename from pkg/transport/http/protocol.go rename to pkg/protocol/http/protocol.go index 557f341a0..ebf76bc5f 100644 --- a/pkg/transport/http/protocol.go +++ b/pkg/protocol/http/protocol.go @@ -10,7 +10,7 @@ import ( "sync" "time" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" "github.com/cloudevents/sdk-go/pkg/binding" cecontext "github.com/cloudevents/sdk-go/pkg/context" @@ -178,7 +178,7 @@ func (p *Protocol) Receive(ctx context.Context) (binding.Message, error) { // for the response callback to invoked before continuing. // Returns non-nil error if the incoming HTTP request fails to parse as a CloudEvent // Returns io.EOF if the receiver is closed. -func (p *Protocol) Respond(ctx context.Context) (binding.Message, transport.ResponseFn, error) { +func (p *Protocol) Respond(ctx context.Context) (binding.Message, protocol.ResponseFn, error) { in, ok := <-p.incoming if !ok { return nil, nil, io.EOF @@ -188,7 +188,7 @@ func (p *Protocol) Respond(ctx context.Context) (binding.Message, transport.Resp type msgErr struct { msg *Message - respFn transport.ResponseFn + respFn protocol.ResponseFn err error } @@ -207,12 +207,12 @@ func (p *Protocol) ServeHTTP(rw http.ResponseWriter, req *http.Request) { return nil } - var fn transport.ResponseFn = func(ctx context.Context, resp binding.Message, er transport.Result) error { + var fn protocol.ResponseFn = func(ctx context.Context, resp binding.Message, er protocol.Result) error { if resp != nil { status := http.StatusOK if er != nil { var result *Result - if transport.ResultAs(er, &result) { + if protocol.ResultAs(er, &result) { if result.Status > 100 && result.Status < 600 { status = result.Status } diff --git a/pkg/transport/http/response.go b/pkg/protocol/http/response.go similarity index 93% rename from pkg/transport/http/response.go rename to pkg/protocol/http/response.go index aaef7cd83..1c092743f 100644 --- a/pkg/transport/http/response.go +++ b/pkg/protocol/http/response.go @@ -4,12 +4,12 @@ import ( "errors" "fmt" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) // NewResult returns a fully populated http Result that should be used as // a transport.Result. -func NewResult(status int, messageFmt string, args ...interface{}) transport.Result { +func NewResult(status int, messageFmt string, args ...interface{}) protocol.Result { return &Result{ Status: status, Format: messageFmt, diff --git a/pkg/transport/http/write_request.go b/pkg/protocol/http/write_request.go similarity index 100% rename from pkg/transport/http/write_request.go rename to pkg/protocol/http/write_request.go diff --git a/pkg/transport/http/write_responsewriter.go b/pkg/protocol/http/write_responsewriter.go similarity index 100% rename from pkg/transport/http/write_responsewriter.go rename to pkg/protocol/http/write_responsewriter.go diff --git a/pkg/transport/http/write_responsewriter_test.go b/pkg/protocol/http/write_responsewriter_test.go similarity index 100% rename from pkg/transport/http/write_responsewriter_test.go rename to pkg/protocol/http/write_responsewriter_test.go diff --git a/pkg/transport/inbound.go b/pkg/protocol/inbound.go similarity index 98% rename from pkg/transport/inbound.go rename to pkg/protocol/inbound.go index 0b1366b14..d6397cbbd 100644 --- a/pkg/transport/inbound.go +++ b/pkg/protocol/inbound.go @@ -1,4 +1,4 @@ -package transport +package protocol import ( "context" diff --git a/pkg/transport/kafka_sarama/doc.go b/pkg/protocol/kafka_sarama/doc.go similarity index 100% rename from pkg/transport/kafka_sarama/doc.go rename to pkg/protocol/kafka_sarama/doc.go diff --git a/pkg/transport/kafka_sarama/message.go b/pkg/protocol/kafka_sarama/message.go similarity index 100% rename from pkg/transport/kafka_sarama/message.go rename to pkg/protocol/kafka_sarama/message.go diff --git a/pkg/transport/kafka_sarama/message_benchmark_test.go b/pkg/protocol/kafka_sarama/message_benchmark_test.go similarity index 97% rename from pkg/transport/kafka_sarama/message_benchmark_test.go rename to pkg/protocol/kafka_sarama/message_benchmark_test.go index 9435cc1d4..dc759229a 100644 --- a/pkg/transport/kafka_sarama/message_benchmark_test.go +++ b/pkg/protocol/kafka_sarama/message_benchmark_test.go @@ -10,7 +10,7 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding" "github.com/cloudevents/sdk-go/pkg/binding/test" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" ) // Avoid DCE diff --git a/pkg/transport/kafka_sarama/option.go b/pkg/protocol/kafka_sarama/option.go similarity index 100% rename from pkg/transport/kafka_sarama/option.go rename to pkg/protocol/kafka_sarama/option.go diff --git a/pkg/transport/kafka_sarama/protocol.go b/pkg/protocol/kafka_sarama/protocol.go similarity index 94% rename from pkg/transport/kafka_sarama/protocol.go rename to pkg/protocol/kafka_sarama/protocol.go index 6975df80e..16cfdc3ff 100644 --- a/pkg/transport/kafka_sarama/protocol.go +++ b/pkg/protocol/kafka_sarama/protocol.go @@ -9,7 +9,7 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding" cecontext "github.com/cloudevents/sdk-go/pkg/context" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) const ( @@ -121,6 +121,6 @@ func (p *Protocol) Close(ctx context.Context) error { } // Kafka protocol implements Sender, Receiver -var _ transport.Sender = (*Protocol)(nil) -var _ transport.Receiver = (*Protocol)(nil) -var _ transport.Closer = (*Protocol)(nil) +var _ protocol.Sender = (*Protocol)(nil) +var _ protocol.Receiver = (*Protocol)(nil) +var _ protocol.Closer = (*Protocol)(nil) diff --git a/pkg/transport/kafka_sarama/receiver.go b/pkg/protocol/kafka_sarama/receiver.go similarity index 95% rename from pkg/transport/kafka_sarama/receiver.go rename to pkg/protocol/kafka_sarama/receiver.go index f8f8fd457..b1ce919e5 100644 --- a/pkg/transport/kafka_sarama/receiver.go +++ b/pkg/protocol/kafka_sarama/receiver.go @@ -8,7 +8,7 @@ import ( "github.com/Shopify/sarama" "github.com/cloudevents/sdk-go/pkg/binding" - "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) type msgErr struct { @@ -62,7 +62,7 @@ func (r *Receiver) Receive(ctx context.Context) (binding.Message, error) { return msgErr.msg, msgErr.err } -var _ transport.Receiver = (*Receiver)(nil) +var _ protocol.Receiver = (*Receiver)(nil) type Consumer struct { Receiver @@ -126,4 +126,4 @@ func (c *Consumer) Close(ctx context.Context) error { return nil } -var _ transport.Opener = (*Consumer)(nil) +var _ protocol.Opener = (*Consumer)(nil) diff --git a/pkg/transport/kafka_sarama/sender.go b/pkg/protocol/kafka_sarama/sender.go similarity index 100% rename from pkg/transport/kafka_sarama/sender.go rename to pkg/protocol/kafka_sarama/sender.go diff --git a/pkg/transport/kafka_sarama/write_producer_message.go b/pkg/protocol/kafka_sarama/write_producer_message.go similarity index 100% rename from pkg/transport/kafka_sarama/write_producer_message.go rename to pkg/protocol/kafka_sarama/write_producer_message.go diff --git a/pkg/transport/kafka_sarama/write_producer_message_benchmark_test.go b/pkg/protocol/kafka_sarama/write_producer_message_benchmark_test.go similarity index 94% rename from pkg/transport/kafka_sarama/write_producer_message_benchmark_test.go rename to pkg/protocol/kafka_sarama/write_producer_message_benchmark_test.go index eaac7aba1..6465f64ea 100644 --- a/pkg/transport/kafka_sarama/write_producer_message_benchmark_test.go +++ b/pkg/protocol/kafka_sarama/write_producer_message_benchmark_test.go @@ -9,7 +9,7 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding" "github.com/cloudevents/sdk-go/pkg/binding/test" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" ) // Avoid DCE diff --git a/pkg/transport/kafka_sarama/write_producer_message_test.go b/pkg/protocol/kafka_sarama/write_producer_message_test.go similarity index 100% rename from pkg/transport/kafka_sarama/write_producer_message_test.go rename to pkg/protocol/kafka_sarama/write_producer_message_test.go diff --git a/pkg/transport/lifecycle.go b/pkg/protocol/lifecycle.go similarity index 94% rename from pkg/transport/lifecycle.go rename to pkg/protocol/lifecycle.go index fc44c8473..bb4de5e89 100644 --- a/pkg/transport/lifecycle.go +++ b/pkg/protocol/lifecycle.go @@ -1,4 +1,4 @@ -package transport +package protocol import ( "context" diff --git a/pkg/transport/nats/doc.go b/pkg/protocol/nats/doc.go similarity index 100% rename from pkg/transport/nats/doc.go rename to pkg/protocol/nats/doc.go diff --git a/pkg/transport/nats/message.go b/pkg/protocol/nats/message.go similarity index 100% rename from pkg/transport/nats/message.go rename to pkg/protocol/nats/message.go diff --git a/pkg/transport/nats/options.go b/pkg/protocol/nats/options.go similarity index 100% rename from pkg/transport/nats/options.go rename to pkg/protocol/nats/options.go diff --git a/pkg/transport/nats/options_test.go b/pkg/protocol/nats/options_test.go similarity index 100% rename from pkg/transport/nats/options_test.go rename to pkg/protocol/nats/options_test.go diff --git a/pkg/transport/nats/protocol.go b/pkg/protocol/nats/protocol.go similarity index 99% rename from pkg/transport/nats/protocol.go rename to pkg/protocol/nats/protocol.go index a882a3a98..d57982a6b 100644 --- a/pkg/transport/nats/protocol.go +++ b/pkg/protocol/nats/protocol.go @@ -2,9 +2,10 @@ package nats import ( "context" - "github.com/cloudevents/sdk-go/pkg/binding" "time" + "github.com/cloudevents/sdk-go/pkg/binding" + "github.com/nats-io/nats.go" ) diff --git a/pkg/transport/nats/write_message.go b/pkg/protocol/nats/write_message.go similarity index 100% rename from pkg/transport/nats/write_message.go rename to pkg/protocol/nats/write_message.go diff --git a/pkg/transport/outbound.go b/pkg/protocol/outbound.go similarity index 98% rename from pkg/transport/outbound.go rename to pkg/protocol/outbound.go index 2f890b3cb..8bb2a7536 100644 --- a/pkg/transport/outbound.go +++ b/pkg/protocol/outbound.go @@ -1,4 +1,4 @@ -package transport +package protocol import ( "context" diff --git a/pkg/transport/result.go b/pkg/protocol/result.go similarity index 98% rename from pkg/transport/result.go rename to pkg/protocol/result.go index 7f926fee0..b47bae2fb 100644 --- a/pkg/transport/result.go +++ b/pkg/protocol/result.go @@ -1,4 +1,4 @@ -package transport +package protocol import ( "errors" diff --git a/pkg/transport/test/benchmark.go b/pkg/protocol/test/benchmark.go similarity index 86% rename from pkg/transport/test/benchmark.go rename to pkg/protocol/test/benchmark.go index 5667fb41e..b92051828 100644 --- a/pkg/transport/test/benchmark.go +++ b/pkg/protocol/test/benchmark.go @@ -4,18 +4,17 @@ import ( "context" "testing" - bindings "github.com/cloudevents/sdk-go/pkg/transport" - "github.com/stretchr/testify/assert" "golang.org/x/sync/errgroup" "github.com/cloudevents/sdk-go/pkg/binding" . "github.com/cloudevents/sdk-go/pkg/binding/test" + "github.com/cloudevents/sdk-go/pkg/protocol" ) // Simple send/receive benchmark. // Requires a sender and receiver that are connected to each other. -func BenchmarkSendReceive(b *testing.B, s bindings.Sender, r bindings.Receiver) { +func BenchmarkSendReceive(b *testing.B, s protocol.Sender, r protocol.Receiver) { e := FullEvent() m := (*binding.EventMessage)(&e) ctx := context.Background() diff --git a/pkg/transport/test/doc.go b/pkg/protocol/test/doc.go similarity index 100% rename from pkg/transport/test/doc.go rename to pkg/protocol/test/doc.go diff --git a/pkg/transport/test/test.go b/pkg/protocol/test/test.go similarity index 86% rename from pkg/transport/test/test.go rename to pkg/protocol/test/test.go index 938e41cdd..66c11ddd8 100644 --- a/pkg/transport/test/test.go +++ b/pkg/protocol/test/test.go @@ -9,12 +9,12 @@ import ( "github.com/stretchr/testify/require" "github.com/cloudevents/sdk-go/pkg/binding" - bindings "github.com/cloudevents/sdk-go/pkg/transport" + "github.com/cloudevents/sdk-go/pkg/protocol" ) // SendReceive does s.Send(in), then it receives the message in r.Receive() and executes outAssert // Halt test on error. -func SendReceive(t *testing.T, ctx context.Context, in binding.Message, s bindings.Sender, r bindings.Receiver, outAssert func(binding.Message)) { +func SendReceive(t *testing.T, ctx context.Context, in binding.Message, s protocol.Sender, r protocol.Receiver, outAssert func(binding.Message)) { t.Helper() wg := sync.WaitGroup{} wg.Add(2) diff --git a/pkg/transport/test/test_test.go b/pkg/protocol/test/test_test.go similarity index 95% rename from pkg/transport/test/test_test.go rename to pkg/protocol/test/test_test.go index 682585ffc..7ed597e6d 100644 --- a/pkg/transport/test/test_test.go +++ b/pkg/protocol/test/test_test.go @@ -8,7 +8,7 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding" . "github.com/cloudevents/sdk-go/pkg/binding/test" - . "github.com/cloudevents/sdk-go/pkg/transport/test" + . "github.com/cloudevents/sdk-go/pkg/protocol/test" ) func TestEvent(t *testing.T) { diff --git a/test/benchmark/buffering_vs_to_event/http_transformers_benchmark_test.go b/test/benchmark/buffering_vs_to_event/http_transformers_benchmark_test.go index fc70ad096..b5aeb9f23 100644 --- a/test/benchmark/buffering_vs_to_event/http_transformers_benchmark_test.go +++ b/test/benchmark/buffering_vs_to_event/http_transformers_benchmark_test.go @@ -12,7 +12,7 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding/test" "github.com/cloudevents/sdk-go/pkg/binding/transformer" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport/http" + "github.com/cloudevents/sdk-go/pkg/protocol/http" "github.com/cloudevents/sdk-go/pkg/types" ) diff --git a/test/benchmark/e2e/http/http_mock.go b/test/benchmark/e2e/http/http_mock.go index a9445c17b..945f950c5 100644 --- a/test/benchmark/e2e/http/http_mock.go +++ b/test/benchmark/e2e/http/http_mock.go @@ -8,11 +8,11 @@ import ( "net/http/httptest" "net/url" - bindings "github.com/cloudevents/sdk-go/pkg/transport" - http "github.com/cloudevents/sdk-go/pkg/transport/http" + bindings "github.com/cloudevents/sdk-go/pkg/protocol" + http "github.com/cloudevents/sdk-go/pkg/protocol/http" cloudevents "github.com/cloudevents/sdk-go" - cehttp "github.com/cloudevents/sdk-go/pkg/transport/http" + cehttp "github.com/cloudevents/sdk-go/pkg/protocol/http" ) type RoundTripFunc func(req *nethttp.Request) *nethttp.Response diff --git a/test/benchmark/e2e/http/main.go b/test/benchmark/e2e/http/main.go index ad3022b43..904b64e3d 100644 --- a/test/benchmark/e2e/http/main.go +++ b/test/benchmark/e2e/http/main.go @@ -18,7 +18,7 @@ import ( cloudevents "github.com/cloudevents/sdk-go" "github.com/cloudevents/sdk-go/pkg/binding" "github.com/cloudevents/sdk-go/pkg/binding/buffering" - http "github.com/cloudevents/sdk-go/pkg/transport/http" + http "github.com/cloudevents/sdk-go/pkg/protocol/http" "github.com/cloudevents/sdk-go/test/benchmark/e2e" ) diff --git a/test/benchmark/http_request_to_kafka_sarama_encode/benchmark_test.go b/test/benchmark/http_request_to_kafka_sarama_encode/benchmark_test.go index 97f0268f4..56c940777 100644 --- a/test/benchmark/http_request_to_kafka_sarama_encode/benchmark_test.go +++ b/test/benchmark/http_request_to_kafka_sarama_encode/benchmark_test.go @@ -10,8 +10,8 @@ import ( cloudevents "github.com/cloudevents/sdk-go" "github.com/cloudevents/sdk-go/pkg/binding" "github.com/cloudevents/sdk-go/pkg/binding/test" - "github.com/cloudevents/sdk-go/pkg/transport/http" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/http" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" ) var ( diff --git a/test/benchmark/kafka_sarama_to_http_request_encode/benchmark_test.go b/test/benchmark/kafka_sarama_to_http_request_encode/benchmark_test.go index 772cbb177..ecc1432b1 100644 --- a/test/benchmark/kafka_sarama_to_http_request_encode/benchmark_test.go +++ b/test/benchmark/kafka_sarama_to_http_request_encode/benchmark_test.go @@ -12,8 +12,8 @@ import ( cloudevents "github.com/cloudevents/sdk-go" "github.com/cloudevents/sdk-go/pkg/binding" "github.com/cloudevents/sdk-go/pkg/binding/test" - "github.com/cloudevents/sdk-go/pkg/transport/http" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/http" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" ) var ( diff --git a/test/integration/amqp_binding/amqp_test.go b/test/integration/amqp_binding/amqp_test.go index 25807d55e..5d90446ff 100644 --- a/test/integration/amqp_binding/amqp_test.go +++ b/test/integration/amqp_binding/amqp_test.go @@ -7,7 +7,7 @@ import ( "os" "testing" - amqp2 "github.com/cloudevents/sdk-go/pkg/transport/amqp" + amqp2 "github.com/cloudevents/sdk-go/pkg/protocol/amqp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -16,8 +16,8 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding" . "github.com/cloudevents/sdk-go/pkg/binding/test" "github.com/cloudevents/sdk-go/pkg/event" - bindings "github.com/cloudevents/sdk-go/pkg/transport" - "github.com/cloudevents/sdk-go/pkg/transport/test" + bindings "github.com/cloudevents/sdk-go/pkg/protocol" + "github.com/cloudevents/sdk-go/pkg/protocol/test" ) func TestSendSkipBinary(t *testing.T) { diff --git a/test/integration/http/direct.go b/test/integration/http/direct.go index 55ce22bf7..d4b13d58a 100644 --- a/test/integration/http/direct.go +++ b/test/integration/http/direct.go @@ -2,15 +2,16 @@ package http import ( "context" - "github.com/cloudevents/sdk-go/pkg/client" "net/http/httptest" "testing" "time" + "github.com/cloudevents/sdk-go/pkg/client" + "github.com/google/uuid" cloudevents "github.com/cloudevents/sdk-go" - cehttp "github.com/cloudevents/sdk-go/pkg/transport/http" + cehttp "github.com/cloudevents/sdk-go/pkg/protocol/http" ) // Direct Test: diff --git a/test/integration/http/loopback.go b/test/integration/http/loopback.go index 0c8a1a2a6..9a6d4bcfa 100644 --- a/test/integration/http/loopback.go +++ b/test/integration/http/loopback.go @@ -11,7 +11,7 @@ import ( cloudevents "github.com/cloudevents/sdk-go" "github.com/cloudevents/sdk-go/pkg/client" - cehttp "github.com/cloudevents/sdk-go/pkg/transport/http" + cehttp "github.com/cloudevents/sdk-go/pkg/protocol/http" ) // Loopback Test: diff --git a/test/integration/http/middleware.go b/test/integration/http/middleware.go index 4bcbc063f..2a5d1a31e 100644 --- a/test/integration/http/middleware.go +++ b/test/integration/http/middleware.go @@ -2,14 +2,15 @@ package http import ( "context" - "github.com/cloudevents/sdk-go/pkg/client" "net/http/httptest" "testing" + "github.com/cloudevents/sdk-go/pkg/client" + "github.com/google/uuid" cloudevents "github.com/cloudevents/sdk-go" - cehttp "github.com/cloudevents/sdk-go/pkg/transport/http" + cehttp "github.com/cloudevents/sdk-go/pkg/protocol/http" ) func ClientMiddleware(t *testing.T, tc TapTest, copts ...client.Option) { diff --git a/test/integration/http_binding/http_test.go b/test/integration/http_binding/http_test.go index d46289b20..e52591b03 100644 --- a/test/integration/http_binding/http_test.go +++ b/test/integration/http_binding/http_test.go @@ -11,9 +11,9 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding" "github.com/cloudevents/sdk-go/pkg/event" - bindings "github.com/cloudevents/sdk-go/pkg/transport" - http "github.com/cloudevents/sdk-go/pkg/transport/http" - test "github.com/cloudevents/sdk-go/pkg/transport/test" + bindings "github.com/cloudevents/sdk-go/pkg/protocol" + http "github.com/cloudevents/sdk-go/pkg/protocol/http" + test "github.com/cloudevents/sdk-go/pkg/protocol/test" . "github.com/cloudevents/sdk-go/pkg/binding/test" ) diff --git a/test/integration/kafka_sarama/kafka_test.go b/test/integration/kafka_sarama/kafka_test.go index 4565673b6..06a1e1bba 100644 --- a/test/integration/kafka_sarama/kafka_test.go +++ b/test/integration/kafka_sarama/kafka_test.go @@ -12,7 +12,7 @@ import ( bindingtest "github.com/cloudevents/sdk-go/pkg/binding/test" clienttest "github.com/cloudevents/sdk-go/pkg/client/test" "github.com/cloudevents/sdk-go/pkg/event" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" ) const ( diff --git a/test/integration/kafka_sarama_binding/kafka_test.go b/test/integration/kafka_sarama_binding/kafka_test.go index 2ef37de4b..cf16efe80 100644 --- a/test/integration/kafka_sarama_binding/kafka_test.go +++ b/test/integration/kafka_sarama_binding/kafka_test.go @@ -14,9 +14,9 @@ import ( "github.com/cloudevents/sdk-go/pkg/binding" . "github.com/cloudevents/sdk-go/pkg/binding/test" "github.com/cloudevents/sdk-go/pkg/event" - bindings "github.com/cloudevents/sdk-go/pkg/transport" - "github.com/cloudevents/sdk-go/pkg/transport/kafka_sarama" - "github.com/cloudevents/sdk-go/pkg/transport/test" + bindings "github.com/cloudevents/sdk-go/pkg/protocol" + "github.com/cloudevents/sdk-go/pkg/protocol/kafka_sarama" + "github.com/cloudevents/sdk-go/pkg/protocol/test" ) const (