hop

package module
v0.0.0-...-3f57d83 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2016 License: Apache-2.0 Imports: 7 Imported by: 3

README

HOP

Handler OPerators

You can add pre operations to your http.HandlerFunc

op1 - op2 - op3 - ... - your http.HandlerFunc

Example

Gets Contenty-Type(MIME type) Header

import (
    "github.com/mokelab-go/hop"
)

// main handler
handler := func(w http.ResponseWriter, r *http.Request) {
    contentType := hop.ContentType(r.Context())
    fmt.Fprintf(w, "Content type is %s", contentType)
}
handler = op.Operations(op.GetContentType)(handler)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyJSON

func BodyJSON(c context.Context) map[string]interface{}

BodyJSON returns request body as JSON(map[string]interface{}) format

func ContentType

func ContentType(c context.Context) string

ContentType returns Content-Type header

func GetBodyAsJSON

func GetBodyAsJSON(next http.HandlerFunc) http.HandlerFunc

GetBodyAsJSON returns handler, this handler decodes request body as JSON format.

func GetContentType

func GetContentType(next http.HandlerFunc) http.HandlerFunc

GetContentType returns handler, this handler gets Content-Type

func GetCredential

func GetCredential(next http.HandlerFunc) http.HandlerFunc

func GetPathInt

func GetPathInt(name string) func(next http.HandlerFunc) http.HandlerFunc

GetPathInt returns Operator, this handler gets Path parameter as int value

func GetPathParams

func GetPathParams(next http.HandlerFunc) http.HandlerFunc

GetPathParams returns handler. This handler gets path params.

func GetPathString

func GetPathString(name string) func(next http.HandlerFunc) http.HandlerFunc

GetPathString returns Operator. this handler gets Path parameter as string value

func PathInt

func PathInt(c context.Context, key string) int

PathInt returns path parameter as int value. If value is not int, returns 0 instread.

func PathParams

func PathParams(c context.Context) map[string]string

PathParams returns Path parameters

func PathString

func PathString(c context.Context, key string) string

PathString returns path parameter as int value. If value is not string, returns "" instread.

Types

type Cred

type Cred struct {
	TokenType string
	Token     string
}

func Credential

func Credential(c context.Context) Cred

Credential returns TokenType and Token

type Op

Op is Operator function

func Operations

func Operations(list ...Op) Op

Operations returns Operator

Jump to

Keyboard shortcuts

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