pb

package module
v0.0.0-...-7716d98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2019 License: MIT Imports: 6 Imported by: 0

README

pb - Marshaling and Unmarshaling Protocol Buffers

GoDoc

err := hx.Post(ctx, "https://api.example.com/contents",
	pb.Proto(&in),
	hx.WhenSuccess(pb.AsProto(&out)),
	hx.WhenFailure(hx.AsError()),
)

Documentation

Overview

A plugin for marshaling and umarshaling protocol buffers.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultJSONConfig = &JSONConfig{}
)
View Source
var DefaultProtoConfig = &ProtoConfig{}

Functions

func AsJSON

func AsJSON(pb proto.Message) hx.ResponseHandler

AsJSON is hx.ResponseHandler for unmarshaling response bodies as JSON. This will unmarshal a received data with jsonpb.Unmarshaler in default.

func AsProto

func AsProto(pb proto.Message) hx.ResponseHandler

AsProto is hx.ResponseHandler for unmarshaling response bodies as Proto. This will unmarshal a received data with proto.Unmarshal marshaler in default.

func JSON

func JSON(pb proto.Message) hx.Option

JSON sets proto.Message to request body as json. This will marshal a given data with jsonpb.Marshaler in default.

func Proto

func Proto(pb proto.Message) hx.Option

Proto sets proto.Message to request body as protocol buffers. This will marshal a given data with proto.Marshal in default.

Types

type JSONConfig

type JSONConfig struct {
	jsonpb.Marshaler
	jsonpb.Unmarshaler
	EncodeFunc func(proto.Message) (io.Reader, error)
	DecodeFunc func(io.Reader, proto.Message) error
}

func (*JSONConfig) AsJSON

func (c *JSONConfig) AsJSON(pb proto.Message) hx.ResponseHandler

func (*JSONConfig) JSON

func (c *JSONConfig) JSON(pb proto.Message) hx.Option

type ProtoConfig

type ProtoConfig struct {
	EncodeFunc func(proto.Message) (io.Reader, error)
	DecodeFunc func(io.Reader, proto.Message) error
}

func (*ProtoConfig) AsProto

func (c *ProtoConfig) AsProto(pb proto.Message) hx.ResponseHandler

func (*ProtoConfig) Proto

func (c *ProtoConfig) Proto(pb proto.Message) hx.Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL