MCPcopy Index your code
hub / github.com/cloudevents/sdk-go

github.com/cloudevents/sdk-go @v2.16.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.16.2 ↗ · + Follow
2,665 symbols 9,888 edges 426 files 923 documented · 35% 14 cross-repo links updated 1d agov2.16.2 · 2025-09-22★ 958122 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Go SDK for CloudEvents

go-doc Go Report Card Releases LICENSE

Official CloudEvents SDK to integrate your application with CloudEvents.

This library will help you to:

Note: Supported CloudEvents specification: 0.3, 1.0

Note: Minimum Go version required: 1.23 (tested with 1.24+)

Get started

Add the module as dependency to your project:

go get github.com/cloudevents/sdk-go/v2

And import the module in your code

import cloudevents "github.com/cloudevents/sdk-go/v2"

Send your first CloudEvent

To send a CloudEvent using HTTP:

func main() {
    c, err := cloudevents.NewClientHTTP()
    if err != nil {
        log.Fatalf("failed to create client, %v", err)
    }

    // Create an Event.
    event :=  cloudevents.NewEvent()
    event.SetSource("example/uri")
    event.SetType("example.type")
    event.SetData(cloudevents.ApplicationJSON, map[string]string{"hello": "world"})

    // Set a target.
    ctx := cloudevents.ContextWithTarget(context.Background(), "http://localhost:8080/")

    // Send that Event.
    if result := c.Send(ctx, event); cloudevents.IsUndelivered(result) {
        log.Fatalf("failed to send, %v", result)
    } else {
        log.Printf("sent: %v", event)
        log.Printf("result: %v", result)
    }
}

Receive your first CloudEvent

To start receiving CloudEvents using HTTP:

func receive(event cloudevents.Event) {
    // do something with event.
    fmt.Printf("%s", event)
}

func main() {
    // The default client is HTTP.
    c, err := cloudevents.NewClientHTTP()
    if err != nil {
        log.Fatalf("failed to create client, %v", err)
    }
    if err = c.StartReceiver(context.Background(), receive); err != nil {
        log.Fatalf("failed to start receiver: %v", err)
    }
}

Create a CloudEvent from an HTTP Request

func handler(w http.ResponseWriter, r *http.Request) {
    event, err := cloudevents.NewEventFromHTTPRequest(r)
    if err != nil {
        log.Printf("failed to parse CloudEvent from request: %v", err)
        http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
    }
    w.Write([]byte(event.String()))
    log.Println(event.String())
}

Serialize/Deserialize a CloudEvent

To marshal a CloudEvent into JSON:

event := cloudevents.NewEvent()
event.SetID("example-uuid-32943bac6fea")
event.SetSource("example/uri")
event.SetType("example.type")
event.SetData(cloudevents.ApplicationJSON, map[string]string{"hello": "world"})

bytes, err := json.Marshal(event)

To unmarshal JSON back into a CloudEvent:

event :=  cloudevents.NewEvent()

err := json.Unmarshal(bytes, &event)

Go further

  • Look at the complete documentation: https://cloudevents.github.io/sdk-go/
  • Dig into the godoc: https://godoc.org/github.com/cloudevents/sdk-go/v2
  • Check out the samples directory for an extended list of examples showing the different SDK features

Community

  • There are bi-weekly calls immediately following the Serverless/CloudEvents call at 9am PT (US Pacific). Which means they will typically start at 10am PT, but if the other call ends early then the SDK call will start early as well. See the CloudEvents meeting minutes to determine which week will have the call.
  • Slack: #cloudeventssdk channel under CNCF's Slack workspace.
  • Email: https://lists.cncf.io/g/cncf-cloudevents-sdk

Each SDK may have its own unique processes, tooling and guidelines, common governance related material can be found in the CloudEvents community directory. In particular, in there you will find information concerning how SDK projects are managed, guidelines for how PR reviews and approval, and our Code of Conduct information.

If there is a security concern with one of the CloudEvents specifications, or with one of the project's SDKs, please send an email to cncf-cloudevents-security@lists.cncf.io.

Additional SDK Resources

Extension points exported contracts — how you extend this code

Expression (Interface)
Expression represents a parsed CloudEvents SQL Expression. [11 implementers]
sql/v2/expression.go
Subscriber (Interface)
The Subscriber interface allows us to configure how the subscription is created [6 implementers]
protocol/nats_jetstream/v2/subscriber.go
Subscriber (Interface)
The Subscriber interface allows us to configure how the subscription is created [6 implementers]
protocol/nats/v2/subscriber.go
Subscriber (Interface)
The Subscriber interface allows us to configure how the subscription is created [6 implementers]
protocol/stan/v2/subscriber.go
Opener (Interface)
Opener is the common interface for things that need to be opened. [13 implementers]
v2/protocol/lifecycle.go
MessageReader (Interface)
MessageReader defines the read-related portion of the Message interface. The ReadStructured and ReadBinary methods allo [17 …
v2/binding/message.go
ObservabilityService (Interface)
ObservabilityService is an interface users can implement to record metrics, create tracing spans, and plug other observa [4 …
v2/client/observability.go
EventContext (Interface)
EventContext is conical interface for a CloudEvents Context. [3 implementers]
v2/event/eventcontext.go

Core symbols most depended-on inside this repo

Error
called by 254
observability/opencensus/v2/client/reporter.go
Run
called by 225
sql/v2/function.go
String
called by 125
v2/binding/spec/spec.go
Close
called by 121
v2/protocol/lifecycle.go
AsV1
called by 94
v2/event/eventcontext.go
Clone
called by 89
v2/event/eventcontext.go
Parse
called by 79
sql/v2/parser/parser.go
SetExtension
called by 77
v2/event/event_interface.go

Shape

Function 1,157
Method 1,073
Struct 308
Interface 54
TypeAlias 39
FuncType 34

Languages

Go100%

Modules by API surface

sql/v2/gen/cesqlparser_parser.go261 symbols
binding/format/protobuf/v2/pb/cloudevent.pb.go57 symbols
sql/v2/parser/expression_visitor.go34 symbols
v2/binding/spec/spec.go33 symbols
v2/event/eventcontext.go31 symbols
v2/test/event_matchers.go29 symbols
v2/event/event_interface.go27 symbols
v2/binding/spec/attributes.go26 symbols
sql/v2/gen/cesqlparser_visitor.go25 symbols
sql/v2/gen/cesqlparser_base_visitor.go25 symbols
v2/protocol/http/options_test.go24 symbols
v2/protocol/http/options.go24 symbols

For agents

$ claude mcp add sdk-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact