envoy

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

Simplified Go interface for HTTP Golang Filter on Envoy Proxy

Go Reference Go Report Card Test Codecov

A simplified interface for building plugin on Envoy Proxy with HTTP Golang Filter.

Features

Development Guide

Prerequisites
Setup
  • Install Git.

  • Install Go 1.20.

  • Clone the project.

    $ git clone -b plugin git@github.com:ardkabs/go-envoy.git
    
  • Create a meaningful branch

    $ git checkout -b <your-meaningful-branch>
    
  • Test your changes.

    $ make test
    
  • We highly recommend instead of only run test, please also do audit which include formatting, linting, vetting, and testing.

    $ make audit
    
  • Add, commit, and push changes to repository

    $ git add .
    $ git commit -s -m "<conventional commit style>"
    $ git push origin <your-meaningful-branch>
    

    For writing commit message, please use conventionalcommits as a reference.

  • Create a Pull Request (PR). In your PR's description, please explain the goal of the PR and its changes.

Testing
Unit Test
$ make test
Try It

To try this interface in action, heads to example directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastTo added in v0.1.1

func CastTo(target interface{}, value interface{}) bool

func CreateSimpleJSONBody

func CreateSimpleJSONBody(code, message string, errs ...error) []byte

func DefaultErrorHandler

func DefaultErrorHandler(ctx Context, err error) api.StatusType

func DefaultRender added in v0.1.1

func DefaultRender(keysAndValues []interface{}) []interface{}

DefaultRender supports logr.Marshaler and fmt.Stringer.

func NewLogger added in v0.1.1

func NewLogger(callback api.FilterCallbacks) logr.Logger

func ToFlatHeader

func ToFlatHeader(header http.Header) map[string]string

Types

type Context

type Context interface {
	// RequestHeader provides an interface to access HTTP Request header, including
	// add, overwrite, or delete existing header.
	RequestHeader() Header

	// Request returns an http.Request struct, which is a read-only data.
	// Attempting to modify this value will have no effect.
	// To make modifications to the request, such as its headers, please use the RequestHeader() method instead.
	Request() *http.Request

	// SetRequest is a low-level API, it set response from RequestHeaderMap interface
	SetRequest(api.RequestHeaderMap)

	// ResponseHeader provides an interface to access HTTP Response header, including
	// add, overwrite, or delete existing header.
	ResponseHeader() Header

	// Response returns an http.Response struct, which is a read-only data.
	// It means, update anything to this value will result nothing.
	// To make modifications to the response, such as its headers, please use the ResponseHeader() method instead.
	Response() *http.Response

	// SetResponse is a low-level API, it set response from ResponseHeaderMap interface
	SetResponse(api.ResponseHeaderMap)

	// StreamInfo offers an interface for retrieving comprehensive details about the incoming HTTP traffic, including
	// information such as the route name, filter chain name, dynamic metadata, and more.
	// It provides direct access to low-level Envoy information, so it's important to use it with a clear understanding of your intent.
	StreamInfo() api.StreamInfo

	// Store allows you to save a value of any type under a key of any type.
	// Please be cautious! The Store function overwrites any existing data.
	Store(key any, value any)

	// Load retrieves a value associated with a specific key and assigns it to the receiver.
	// It returns true if a compatible value is successfully loaded,
	// and false if no value is found or an error occurs during the process.
	Load(key any, receiver interface{}) (ok bool, err error)

	// Log provides a logger from the plugin to the Envoy Log. It accessible under Envoy `http` component.
	// e.g., Envoy flag `--component-log-level http:{debug,info,warn,error,critical}`
	Log() logr.Logger

	// JSON sends a JSON response with status code.
	JSON(code int, b []byte, headers map[string]string, opts ...ReplyOption) error

	// String sends a plain text response with status code.
	String(code int, s string, opts ...ReplyOption) error

	// StatusType is a low-level API used to specify the type of status to be communicated to Envoy.
	StatusType() api.StatusType

	// Committed indicates whether the current context has already completed its processing
	// within the plugin and forwarded the result to Envoy.
	Committed() bool
}

func NewContext added in v0.1.1

func NewContext(callback api.FilterCallbacks) (Context, error)

type ErrorHandler

type ErrorHandler func(Context, error) api.StatusType

type Handler added in v0.1.1

type Handler func(next HandlerFunc) HandlerFunc

type HandlerFunc added in v0.1.1

type HandlerFunc func(ctx Context) error

func HandlerDecorator added in v0.1.1

func HandlerDecorator(next HandlerFunc) HandlerFunc

type HandlerManager added in v0.1.1

type HandlerManager interface {
	Use(handler Handler)
	Handle(ctx Context) api.StatusType
}

func NewManager added in v0.1.1

func NewManager() HandlerManager

func NewManagerWithErrorHandler added in v0.1.1

func NewManagerWithErrorHandler(errHandler ErrorHandler) HandlerManager
type Header interface {
	api.HeaderMap

	AsMap() map[string]string
}

type ReplyOption added in v0.1.1

type ReplyOption func(o *ReplyOptions)

func WithGrpcStatus

func WithGrpcStatus(status int64) ReplyOption

func WithResponseCodeDetails added in v0.1.1

func WithResponseCodeDetails(detail string) ReplyOption

type ReplyOptions added in v0.1.1

type ReplyOptions struct {
	// contains filtered or unexported fields
}

func GetDefaultReplyOptions added in v0.1.1

func GetDefaultReplyOptions() *ReplyOptions

Directories

Path Synopsis
pkg
test

Jump to

Keyboard shortcuts

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