utils

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultProtobufHTTPClient = CreateProtobufHTTPClient(nil, nil, nil)

DefaultProtobufHTTPClient uses default http Client, error mapper and marshaller

Functions

func MarshalMessageBody

func MarshalMessageBody(body interface{}) ([]byte, error)

MarshalMessageBody convenience method to marshal different interfaces into JSON

func Obfuscate

func Obfuscate(input string, edgesLength int) string

Obfuscate is a helper function to obfuscate a string, used mostly to hide passwords, etc

func SplitMethodAndPackage

func SplitMethodAndPackage(fullMethodName string) (packageAndService string, methodName string)

SplitMethodAndPackage is a helper method to split gRPC `package.service/method`

Types

type ErrorMapper added in v1.0.2

type ErrorMapper func(statusCode int) *status.Status

ErrorMapper is a map function that maps HTTP Status Code into its gRPC counter part.

type MDTraceCarrier

type MDTraceCarrier metadata.MD

MDTraceCarrier is an implementation for Tracing carrier, it will hold traceID, etc

func (MDTraceCarrier) ForeachKey

func (md MDTraceCarrier) ForeachKey(handler func(key, value string) error) error

ForeachKey part of the Carrier interface

func (MDTraceCarrier) Set

func (md MDTraceCarrier) Set(key, value string)

Set part of the Carrier interface

type ProtobufHTTPClient added in v1.0.2

type ProtobufHTTPClient interface {
	// Example:
	//	var response *pbpkg.ResponseMessage
	//	var request = &pbpkg.RequestMessage{Name: "test"}
	//	err := Do(ctx, http.MethodPost, "http://host/path", request, &response)
	//
	// Error returned will be of type `(*status.Status).Err()` meaning it will be a gRPC type error.
	//
	// Note:
	// you can pass `nil` as the last parameter if you don't want to unmarshal HTTP response body.
	// or you know it's going to be empty == EOF
	//	err := Do(ctx, http.MethodPost, "http://host/path", request, nil)
	Do(ctx context.Context, method, url string, in proto.Message, out interface{}) error
}

ProtobufHTTPClient is a helper util in situations where you want to call a REST API, but you have all the definitions as Protobuf.

func CreateProtobufHTTPClient added in v1.0.2

func CreateProtobufHTTPClient(client *http.Client, errorMapper ErrorMapper, marshaller runtime.Marshaler) ProtobufHTTPClient

CreateProtobufHTTPClient Creates a custom Protobuf aware HTTP client

Jump to

Keyboard shortcuts

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