All Projects → cloudevents → Sdk Go

cloudevents / Sdk Go

Licence: apache-2.0
Go SDK for CloudEvents

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to Sdk Go

pixie
Instant Kubernetes-Native Application Observability
Stars: ✭ 3,238 (+905.59%)
Mutual labels:  cncf
coredns
CoreDNS is a DNS server that chains plugins
Stars: ✭ 8,962 (+2683.23%)
Mutual labels:  cncf
Operator Kit
A library for creating a Kubernetes Operator
Stars: ✭ 275 (-14.6%)
Mutual labels:  cncf
servicedesk
💁‍♀️💁‍♂️📥Get project related help from the CNCF
Stars: ✭ 46 (-85.71%)
Mutual labels:  cncf
siddhi-operator
Operator allows you to run stream processing logic directly on a Kubernetes cluster
Stars: ✭ 16 (-95.03%)
Mutual labels:  cncf
website
🌐 Source code for OpenGitOps website
Stars: ✭ 15 (-95.34%)
Mutual labels:  cncf
sdk-go
Go SDK for Serverless Workflow
Stars: ✭ 57 (-82.3%)
Mutual labels:  cncf
Envoy
Cloud-native high-performance edge/middle/service proxy
Stars: ✭ 18,561 (+5664.29%)
Mutual labels:  cncf
enduser-public
🔚👩🏾‍💻👨🏽‍💻👩🏼‍💻CNCF End User Community
Stars: ✭ 75 (-76.71%)
Mutual labels:  cncf
K8s Tew
Kubernetes - The Easier Way
Stars: ✭ 269 (-16.46%)
Mutual labels:  cncf
katacoda-scenarios
Katacoda Scenarios for Envoy Proxy
Stars: ✭ 26 (-91.93%)
Mutual labels:  cncf
LFCS-official
Linux Foundation Certified System Administrator(LFCS) learning materials
Stars: ✭ 63 (-80.43%)
Mutual labels:  cncf
acceptance-testing
Acceptance test suite for the Helm client
Stars: ✭ 22 (-93.17%)
Mutual labels:  cncf
fury-distribution
Kubernetes Fury Distribution (Core Modules) - A battle-tested open-source Kubernetes distribution
Stars: ✭ 50 (-84.47%)
Mutual labels:  cncf
Kubernetes Certified Administrator
Online resources that will help you prepare for taking the CNCF CKA 2020 "Kubernetes Certified Administrator" Certification exam. with time, This is not likely the comprehensive up to date list - please make a pull request if there something that should be added here.
Stars: ✭ 3,438 (+967.7%)
Mutual labels:  cncf
pixie-demos
Demos for Pixie: github.com/pixie-io/pixie
Stars: ✭ 106 (-67.08%)
Mutual labels:  cncf
saltstack-kubernetes
Deploy the lowest-cost production ready Kubernetes cluster using terraform and saltstack.
Stars: ✭ 47 (-85.4%)
Mutual labels:  cncf
Devstats
📈CNCF-created tool for analyzing and graphing developer contributions
Stars: ✭ 308 (-4.35%)
Mutual labels:  cncf
Virtual Kubelet
Virtual Kubelet is an open source Kubernetes kubelet implementation.
Stars: ✭ 3,324 (+932.3%)
Mutual labels:  cncf
landscape
🌄The Cloud Native Interactive Landscape filters and sorts hundreds of projects and products, and shows details including GitHub stars, funding or market cap, first and last commits, contributor counts, headquarters location, and recent tweets.
Stars: ✭ 8,067 (+2405.28%)
Mutual labels:  cncf

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: Supported go version: 1.14+

Get started

Add the module as dependency using go mod:

% go get github.com/cloudevents/sdk-go/[email protected]

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)
	}
}

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)
	}
	log.Fatal(c.StartReceiver(context.Background(), receive));
}

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

Community

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].