divert

package module
v0.0.0-...-ec8c8fc Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: Apache-2.0 Imports: 2 Imported by: 2

README

Divert: A Package for Assisting with Okteto Divert Usage

GoDoc Apache License 2.0

The package provided assists with using the Okteto divert feature and HTTP headers.

Documentation

Index

Examples

Constants

View Source
const (
	// DivertHeaderName is the header used for divert values.
	DivertHeaderName = "x-okteto-dvrt"
)

Variables

This section is empty.

Functions

func AddToContext

func AddToContext(ctx context.Context, value string) context.Context

func FromContext

func FromContext(ctx context.Context) string

FromContext provides the divert header value stored in context.

func FromHeaders

func FromHeaders(r *http.Request) string

FromHeaders extracts divert headers from an http request and provides the value. If missing then empty string is provided.

func InjectDivertHeader

func InjectDivertHeader() func(http.Handler) http.Handler

InjectDivertHeader is an http middleware handler that injects Okteto divert headers into context from http.Request.

Example
appHandler := func(w http.ResponseWriter, _ *http.Request) {
	io.WriteString(w, "This is your application's handler\n")
}

injectionHandler := InjectDivertHeader()

http.Handle("/", injectionHandler(http.HandlerFunc(appHandler)))

log.Fatal(http.ListenAndServe(":8080", nil))
Output:

func SetHeader

func SetHeader(ctx context.Context, r *http.Request)

SetHeader sets the okteto divert header and value from context into the provided request.

Types

This section is empty.

Jump to

Keyboard shortcuts

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