jsonpicker

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

cod-json-picker

Build Status

JSON picker for cod, it can pick fields from json response.

package main

import (
	"bytes"

	"github.com/vicanso/cod"

	jp "github.com/vicanso/cod-json-picker"
)

func main() {

	d := cod.New()

	d.Use(jp.NewDefault("_fields"))

	// http://127.0.0.1:7001/?_fields=foo,id
	d.GET("/", func(c *cod.Context) (err error) {
		c.SetHeader(cod.HeaderContentType, cod.MIMEApplicationJSON)
		c.BodyBuffer = bytes.NewBufferString(`{
			"foo": "bar",
			"id": 1,
			"price": 1.21
		}`)
		return
	})

	d.ListenAndServe(":7001")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config Config) cod.Handler

New create a json picker middleware

func NewDefault

func NewDefault(field string) cod.Handler

NewDefault create default json picker middleware

Types

type Config

type Config struct {
	Validate Validate
	Field    string
	Skipper  cod.Skipper
}

Config json picker config

type Validate

type Validate func(*cod.Context) bool

Validate json picker validate

Jump to

Keyboard shortcuts

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