Giter Club home page Giter Club logo

Comments (4)

pengsrc avatar pengsrc commented on July 30, 2024

https://www.iana.org/assignments/media-types/application/octet-stream

The "octet-stream" subtype is used to indicate that a body contains
arbitrary binary data.

from sdk-javascript.

pengsrc avatar pengsrc commented on July 30, 2024

Code to send the CloudEvent message.

package cloudevents_test

import (
	"context"
	"testing"
	"time"

	"github.com/cloudevents/sdk-go"
	"github.com/cloudevents/sdk-go/pkg/cloudevents/client"
	cehttp "github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http"
	"github.com/cloudevents/sdk-go/pkg/cloudevents/types"
	"github.com/google/uuid"
	"github.com/stretchr/testify/assert"
)

func TestTransportHTTP(t *testing.T) {
	encodeType := "application/octet-stream"
	event := cloudevents.Event{
		Context: cloudevents.EventContextV02{
			ID:          uuid.New().String(),
			Type:        "example",
			Source:      *types.ParseURLRef("/test"),
			Time:        &types.Timestamp{Time: time.Now()},
			ContentType: &encodeType,
			Extensions:  map[string]interface{}{"a": 1, "b": 2, "c": 3},
		}.AsV02(),
		Data:        []byte("Hello text."),
		DataEncoded: true,
	}

	c, err := newEventClient("http://127.0.0.1:3000")
	assert.NoError(t, err)

	resp, err := c.Send(context.Background(), event)
	assert.NoError(t, err)
	t.Log(resp)
}

func newEventClient(target string) (client.Client, error) {
	t, err := cehttp.New([]cehttp.Option{
		cehttp.WithBinaryEncoding(), cehttp.WithTarget(target),
	}...)
	if err != nil {
		return nil, err
	}
	c, err := client.New(t, client.WithUUIDs(), client.WithTimeNow())
	if err != nil {
		return nil, err
	}
	return c, nil
}

from sdk-javascript.

fabiojose avatar fabiojose commented on July 30, 2024

@pengsrc,
Nice PR!

from sdk-javascript.

fabiojose avatar fabiojose commented on July 30, 2024

@pengsrc
Released: https://www.npmjs.com/package/cloudevents-sdk/v/0.2.6

from sdk-javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.