Back to

Package httprpc

Latest Go to latest

The latest major version is .

Published: Jul 31, 2020 | License: BSD-3-Clause | Module:


Package httprpc provides goma httprpc implementation.


func AdmissionControl

func AdmissionControl(ac AdmissionController, h http.Handler) http.Handler

AdmissionControl adds admission controller to h.

func AuthHandler

func AuthHandler(a AuthChecker, h http.Handler) http.Handler

AuthHandler converts given http.Handler to access controlled HTTP handler using AuthChecker. Alternatives: WithAuth handler option if it requires retry with Unauthenticated error.

func Call

func Call(ctx context.Context, client *http.Client, url string, req proto.Message, resp proto.Message) error

Call calls remote services over http.

func Handler

func Handler(name string, req, resp proto.Message, h func(context.Context, proto.Message) (proto.Message, error), opts ...HandlerOption) http.Handler

Handler returns http.Handler to serve http rpc handler.

func RemoteAddr

func RemoteAddr(req *http.Request) string

RemoteAddr returns http's remote (client) addr.

func StreamHandler

func StreamHandler(name string, h func(ctx context.Context, w http.ResponseWriter, req *http.Request) error, opts ...HandlerOption) http.Handler

Handler returns http.Handler to serve http stream.

func Trace

func Trace(handler http.Handler, labels map[string]string) http.Handler

Trace adds labels to trace span for requested path. It would be used as top handler for incoming request under ochttp.Handler.

type AdmissionController

type AdmissionController interface {
	Admit(*http.Request) error

AdmissionController checks incoming request.

type Auth

type Auth interface {
	Auth(context.Context, *http.Request) (context.Context, error)

Auth authenticates the request.

type AuthChecker

type AuthChecker interface {
	// Check represents the function to check HTTP access.
	// If the access is granted, it returns non-nil enduser.EndUser instance.
	Check(context.Context, *http.Request) (*enduser.EndUser, error)

AuthChecker represents an interface to checks HTTP access.

type Client

type Client struct {

	// endpoint URL.
	URL string

	// ContentEncoding of the request. "identity", "gzip" or "deflate".
	// "deflate" uses "deflate" compressed data (RFC1951) without
	// zlib header, different from RFC7230 says, for histrical reason.
	// default is "deflate" for backward compatibility.
	// TODO: change default to gzip?
	ContentEncoding string

Client is httprpc client.

func (*Client) Call

func (c *Client) Call(ctx context.Context, req proto.Message, resp proto.Message) error

Call calls remote services over http.

type HandlerOption

type HandlerOption func(*option)

HandlerOption sets option for handler.

func Timeout

func Timeout(d time.Duration) HandlerOption

Timeout sets timeout to the handler. Default is 1 second.

func WithAPIKey

func WithAPIKey(apiKey string) HandlerOption

WithAPIKey sets api key in outgoing context.

func WithAuth

func WithAuth(a Auth) HandlerOption

WithAuth sets auth to the handler.

func WithCluster

func WithCluster(c string) HandlerOption

WithCluster sets cluster name to the handler for logging/monitoring etc.

func WithNamespace

func WithNamespace(ns string) HandlerOption

WithNamespace sets cluster namespace to the handler for logging/monitoring etc.

func WithRetry

func WithRetry(retry rpc.Retry) HandlerOption

WithRetry sets retry config to the handler.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier