yare

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 12 Imported by: 0

README

yare

codecov GoDoc Go Report Card

HTTP echo service with JSON output

yare (Yet Another REST Echo) is a small HTTP echo server written in Go programming language. Core features are also available as Go package.

Features

  • JSON output - Echoes back HTTP request data (version, method, headers, etc) as JSON object.
  • Parse body - Supports JSON and JWT request body formats (other formats ignored silently).
  • Parse Authorization - Supports Bearer authentication scheme with JWT tokens and Basic scheme. The response will include parsed credentials.
  • Custom parsers - The Go package supports custom body and authorization scheme parser registration.
  • Request method - Any HTTP methods are supported (GET, POST, PUT, etc), the response will include the original request method.
  • Request path - Accessible on any request path, the response will include the original path.
  • Query parameters - Supports arbitrary query parameters, the response will include original parameters.
  • Form parameters - Supports arbitrary form parameters, the response will include original parameters.
  • http.Request and http.Response mapping - The Go package supports mapping request and response parameters to map[string]interface{} for trace logging.

Install

You can install the pre-compiled binary or use Docker.

Install the pre-compiled binary

Download the pre-compiled binaries from the releases page and copy to the desired location.

Install with Go

If you have Go environment set up, you can build yare from source by running:

go get github.com/szkiba/yare/cmd/yare

Binary would be installed to $GOPATH/bin/yare.

Running with Docker

You can also use it within a Docker container. To do that, you'll need to execute something more-or-less like the following:

docker run --network=host szkiba/yare
Verifying your installation

To verify your installation, use the yare -v command:

$ yare -v

yare/1.0.0 linux/amd64

You should see yare/VERSION in the output.

Usage

To print usage information, use the yare --help command:

$ yare --help

Usage of yare:
  -port int
        port to listen on (default 8080)
  -v    prints version

TODO

Document, document, document...

Documentation

Overview

Package yare maps http.Request and http.Response properties to easily JSON loggable map.

Index

Constants

This section is empty.

Variables

View Source
var ErrParse = errors.New("parse error")

ErrParse indicates a parsing error.

Functions

func EchoHander

func EchoHander(body bool) http.Handler

EchoHander returns a handler that serves HTTP requests with Echo response.

func RegisterAuthScheme

func RegisterAuthScheme(scheme string, parser ParserFunc)

RegisterAuthScheme registers custom authentication credentials parser for a given scheme.

func RegisterContentType

func RegisterContentType(cty string, parser ParserFunc) error

RegisterContentType registers custom content parser for a given Content-Type.

Types

type Dict

type Dict map[string]interface{}

A Dict represents generic key-value pairs.

func MapRequest

func MapRequest(r *http.Request, body bool) (Dict, error)

MapRequest creates Dict from various request attributes.

func MapResponse

func MapResponse(r *http.Response, body bool) (Dict, error)

MapResponse creates Dict from various response attributes.

func MapValues

func MapValues(in map[string][]string) Dict

MapValues creates Dict from string multimap (like url.Values and http.Header).

Stores single values as string multi values as string array.

func ParseJSON

func ParseJSON(in []byte) (Dict, error)

ParseJSON is a ParserFunc for parsing JSON string to Dict.

Can use as RegisterContentType parser argument.

func ParseJWT

func ParseJWT(in []byte) (Dict, error)

ParseJWT is a ParserFunc for parsing JWT to Dict.

Can use as RegisterContentType or RegisterAuthScheme parser argument.

type ParserFunc

type ParserFunc func([]byte) (Dict, error)

ParserFunc used to register custom body and authorization parsers.

func (ParserFunc) Optional added in v1.3.0

func (p ParserFunc) Optional() ParserFunc

Optional returns a new ParserFunc which silently ignore errors.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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