grpcer

package module
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: Apache-2.0 Imports: 30 Imported by: 2

README

gRPCer is a library with some helper functions for calling a gRPC endpoint in Go, and a protoc plugin for generating a helper lib for easier calling those endpoints: ./protoc-gen-grpcer

Documentation

Overview

Package grpcer provide helpers for calling UNO-SOFT gRPC server.

Index

Constants

View Source
const BasicAuthKey = contextKey("authorization-basic")

BasicAuthKey is the context key for the Basic Auth.

Variables

View Source
var (
	DefaultTimeout = 5 * time.Minute
	MaxLogWidth    = 1 << 10

	ErrNotFound = errors.New("not found")
)

Functions

func CamelCase

func CamelCase(text string) string

func Connect

func Connect(endpoint, CAFile, serverHostOverride string) (*grpc.ClientConn, error)

Connect to the given endpoint, with the Certificate Authority and hostOverride.

func DialOpts

func DialOpts(conf DialConfig) ([]grpc.DialOption, error)

DialOpts renders the dial options for calling a gRPC server.

* prefix is inserted before the standard request path - if your server serves on different path. * caFile is the PEM file with the server's CA. * serverHostOverride is to override the CA's host.

func NewBasicAuth

func NewBasicAuth(username, password string) credentials.PerRPCCredentials

NewBasicAuth returns a PerRPCCredentials with the username and password.

func NewInsecureBasicAuth added in v0.3.0

func NewInsecureBasicAuth(username, password string) credentials.PerRPCCredentials

NewInsecureBasicAuth returns an INSECURE (not requiring secure transport) PerRPCCredentials with the username and password.

func ReadHeadTail added in v0.10.9

func ReadHeadTail(sr *io.SectionReader, maxSize int64) ([]byte, error)

func SnakeCase

func SnakeCase(text string) string

func WithBasicAuth

func WithBasicAuth(ctx context.Context, username, password string) context.Context

WithBasicAuth returns a context prepared with the given username and password.

Types

type Client

type Client interface {
	// List the available names
	List() []string
	// Input returns the input struct for the name.
	Input(name string) interface{}
	// Call the named function.
	Call(name string, ctx context.Context, input interface{}, opts ...grpc.CallOption) (Receiver, error)
}

Client is the client interface for calling a gRPC server.

type DialConfig

type DialConfig struct {
	*slog.Logger
	PathPrefix                     string
	CAFile                         string
	ServerHostOverride             string
	Username, Password             string
	ServiceName, ServiceVersion    string
	AllowInsecurePasswordTransport bool
}

DialConfig contains the configuration variables.

type Field added in v0.6.0

type Field struct {
	Value   interface{}
	Name    string
	TagName string
}

func SliceFields added in v0.6.0

func SliceFields(part interface{}, tagName string) (slice, notSlice []Field)

type JSONHandler

type JSONHandler struct {
	Client       `json:"-"`
	*slog.Logger `json:"-"`
	Timeout      time.Duration
	MergeStreams bool
}

func (JSONHandler) DecodeRequest added in v0.6.1

func (h JSONHandler) DecodeRequest(ctx context.Context, r *http.Request) (RequestInfo, interface{}, error)

func (JSONHandler) ServeHTTP

func (h JSONHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Receiver

type Receiver interface {
	Recv() (interface{}, error)
}

Receiver is an interface for Recv()-ing streamed responses from the server.

type RequestInfo added in v0.6.1

type RequestInfo interface {
	Name() string
}

type TempFile added in v0.6.2

type TempFile struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

func NewTempFile added in v0.6.2

func NewTempFile(dir, name string) (*TempFile, error)

NewTempFile creates a new compressed tempfile, that can be read back.

func (*TempFile) Close added in v0.6.2

func (f *TempFile) Close() error

func (*TempFile) GetReader added in v0.6.2

func (f *TempFile) GetReader() (io.ReadCloser, error)

GetReader finishes the writing of the temp file, and returns an io.ReadCloser for reading it back.

type XMLRPCHandler

type XMLRPCHandler struct {
	Client
	*slog.Logger
	Timeout time.Duration
}

func (XMLRPCHandler) ServeHTTP

func (h XMLRPCHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
protoc-gen-grpc generates a grpcer.Client from the given protoc file.
protoc-gen-grpc generates a grpcer.Client from the given protoc file.

Jump to

Keyboard shortcuts

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