Documentation ¶
Overview ¶
Example (Mask) ¶
package main import ( "fmt" jsonmask "github.com/teambition/json-mask-go" ) func main() { doc := ` { "kind": "demo", "items": [ { "title": "First title", "comment": "First comment.", "characteristics": { "length": "short", "accuracy": "high", "followers": ["Jo", "Will"] }, "status": "active" }, { "title": "Second title", "comment": "Second comment.", "characteristics": { "length": "long", "accuracy": "medium", "followers": [ ] }, "status": "pending" } ] } ` result, _ := jsonmask.Mask([]byte(doc), "kind,items(title,characteristics/length)") fmt.Println(string(result)) }
Output: {"items":[{"characteristics":{"length":"short"},"title":"First title"},{"characteristics":{"length":"long"},"title":"Second title"}],"kind":"demo"}
Index ¶
- func Mask(doc []byte, fields string) ([]byte, error)
- func NewJSONMask(next http.Handler, queryKey string) (http.Handler, error)
- type JSONMask
- type JSONMaskResponseWriter
- type JSONMaskResponseWriterStatus
- type ResponseWriter
- func (jrw *ResponseWriter) Close() error
- func (jrw *ResponseWriter) Flush()
- func (jrw *ResponseWriter) Header() http.Header
- func (jrw *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (jrw *ResponseWriter) Status() JSONMaskResponseWriterStatus
- func (jrw *ResponseWriter) Write(b []byte) (int, error)
- func (jrw *ResponseWriter) WriteHeader(s int)
- type ResponseWriterWithCloseNotify
- type Selection
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type JSONMask ¶ added in v1.2.0
type JSONMask struct {
// contains filtered or unexported fields
}
JSONMask
type JSONMaskResponseWriter ¶ added in v1.2.0
type JSONMaskResponseWriter interface { http.ResponseWriter Close() error Status() JSONMaskResponseWriterStatus }
func NewResponseWriter ¶ added in v1.2.0
func NewResponseWriter(rw http.ResponseWriter, sl Selection) JSONMaskResponseWriter
type JSONMaskResponseWriterStatus ¶ added in v1.2.0
type ResponseWriter ¶ added in v1.2.0
type ResponseWriter struct {
// contains filtered or unexported fields
}
func (*ResponseWriter) Close ¶ added in v1.2.0
func (jrw *ResponseWriter) Close() error
func (*ResponseWriter) Flush ¶ added in v1.2.0
func (jrw *ResponseWriter) Flush()
func (*ResponseWriter) Header ¶ added in v1.2.0
func (jrw *ResponseWriter) Header() http.Header
func (*ResponseWriter) Hijack ¶ added in v1.2.0
func (jrw *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*ResponseWriter) Status ¶ added in v1.2.0
func (jrw *ResponseWriter) Status() JSONMaskResponseWriterStatus
func (*ResponseWriter) Write ¶ added in v1.2.0
func (jrw *ResponseWriter) Write(b []byte) (int, error)
func (*ResponseWriter) WriteHeader ¶ added in v1.2.0
func (jrw *ResponseWriter) WriteHeader(s int)
type ResponseWriterWithCloseNotify ¶ added in v1.2.0
type ResponseWriterWithCloseNotify struct {
*ResponseWriter
}
func (*ResponseWriterWithCloseNotify) CloseNotify ¶ added in v1.2.0
func (jrw *ResponseWriterWithCloseNotify) CloseNotify() <-chan bool
type Selection ¶ added in v1.1.0
func Compile ¶ added in v1.1.0
The syntax is loosely based on XPath:
a select a field 'a' a,b,c comma-separated list will select multiple fields a/b/c path will select a field from its parent a(b,c) sub-selection will select many fields from a parent a/*/c the star * wildcard will select all items in a field a,b/c(d,e(f,g/h)),i
Click to show internal directories.
Click to hide internal directories.