Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
/ elton-responder Public archive

Responder middleware for elton, it convert struct(map) to json response.

License

Notifications You must be signed in to change notification settings

vicanso/elton-responder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elton-responder

The middleware has been archived, please use the middleware of elton.

Build Status

Responder middleware for elton, it can convert Context.Body to json data. Using this middleware, it's more simple for successful response. More response type can be supported through custom marshal function and content type.

package main

import (
	"github.com/vicanso/elton"

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

func main() {
	e := elton.New()

	e.Use(responder.NewDefault())

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

	er := e.ListenAndServe(":3000")
	if err != nil {
		panic(err)
	}
}

API

  • Config.Skipper skipper function to skip middleware
  • Config.Fastest if set true will use the json-iterator fastest config for better performance, deprecated
  • Config.Marshal custom marshal function
  • Config.ContentType the coontent type for response