responder

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

cod-responder

Build Status

Responder middleware for cod, it can convert Context.Body to json data. By this middleware, it's more simple for successful response.

package main

import (
	"github.com/vicanso/cod"

	responder "github.com/vicanso/cod-responder"
)

func main() {
	d := cod.New()

	d.Use(responder.NewDefault())

	// {"name":"tree.xie","id":123}
	d.GET("/", func(c *cod.Context) (err error) {
		c.Body = &struct {
			Name string `json:"name"`
			ID   int    `json:"id"`
		}{
			"tree.xie",
			123,
		}
		return
	})

	d.ListenAndServe(":7001")
}

API

  • Config.Skipper skipper function to skip middleware
  • Config.Fastest if set true will use the json-iterator fastest config for better performance

Documentation

Index

Constants

View Source
const (
	// ErrCategory responder error category
	ErrCategory = "cod-responder"
)

Variables

This section is empty.

Functions

func New

func New(config Config) cod.Handler

New create a responder

func NewDefault

func NewDefault() cod.Handler

NewDefault create a default responder

Types

type Config

type Config struct {
	Skipper cod.Skipper
	// Fastest set to true will use fast json
	Fastest bool
}

Config response config

Jump to

Keyboard shortcuts

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