Add document

This commit is contained in:
Masaaki Goshima 2022-01-03 12:55:10 +09:00
parent 89bcc3be86
commit 594d0a55dc
No known key found for this signature in database
GPG Key ID: 6A53785055537153
2 changed files with 13 additions and 2 deletions

View File

@ -23,7 +23,6 @@ Fast JSON encoder/decoder compatible with encoding/json for Go
We are accepting requests for features that will be implemented between v0.8.0 and v.1.0.0. We are accepting requests for features that will be implemented between v0.8.0 and v.1.0.0.
If you have the API you need, please submit your issue [here](https://github.com/goccy/go-json/issues). If you have the API you need, please submit your issue [here](https://github.com/goccy/go-json/issues).
For example, I'm thinking of supporting `context.Context` of `json.Marshaler` and decoding using JSON Path.
# Features # Features
@ -32,6 +31,7 @@ For example, I'm thinking of supporting `context.Context` of `json.Marshaler` an
- Flexible customization with options - Flexible customization with options
- Coloring the encoded string - Coloring the encoded string
- Can propagate context.Context to `MarshalJSON` or `UnmarshalJSON` - Can propagate context.Context to `MarshalJSON` or `UnmarshalJSON`
- Can dynamically filter the fields of the structure type-safely
# Installation # Installation

View File

@ -5,15 +5,25 @@ import (
) )
type ( type (
// FieldQuery you can dynamically filter the fields in the structure by creating a FieldQuery,
// adding it to context.Context using SetFieldQueryToContext and then passing it to MarshalContext.
// This is a type-safe operation, so it is faster than filtering using map[string]interface{}.
FieldQuery = encoder.FieldQuery FieldQuery = encoder.FieldQuery
FieldQueryString = encoder.FieldQueryString FieldQueryString = encoder.FieldQueryString
) )
var ( var (
FieldQueryFromContext = encoder.FieldQueryFromContext // FieldQueryFromContext get current FieldQuery from context.Context.
FieldQueryFromContext = encoder.FieldQueryFromContext
// SetFieldQueryToContext set current FieldQuery to context.Context.
SetFieldQueryToContext = encoder.SetFieldQueryToContext SetFieldQueryToContext = encoder.SetFieldQueryToContext
) )
// BuildFieldQuery builds FieldQuery by fieldName or sub field query.
// First, specify the field name that you want to keep in structure type.
// If the field you want to keep is a structure type, by creating a sub field query using BuildSubFieldQuery,
// you can select the fields you want to keep in the structure.
// This description can be written recursively.
func BuildFieldQuery(fields ...FieldQueryString) (*FieldQuery, error) { func BuildFieldQuery(fields ...FieldQueryString) (*FieldQuery, error) {
query, err := Marshal(fields) query, err := Marshal(fields)
if err != nil { if err != nil {
@ -22,6 +32,7 @@ func BuildFieldQuery(fields ...FieldQueryString) (*FieldQuery, error) {
return FieldQueryString(query).Build() return FieldQueryString(query).Build()
} }
// BuildSubFieldQuery builds sub field query.
func BuildSubFieldQuery(name string) *SubFieldQuery { func BuildSubFieldQuery(name string) *SubFieldQuery {
return &SubFieldQuery{name: name} return &SubFieldQuery{name: name}
} }