Source File
json.go
Belonging Package
google.golang.org/api/internal/gensupport
package gensupport
import (
)
func ( interface{}, , []string) ([]byte, error) {
if len() == 0 && len() == 0 {
return json.Marshal()
}
:= make(map[string]bool)
for , := range {
[] = true
}
:= make(map[string]bool)
:= make(map[string]map[string]bool)
for , := range {
:= strings.SplitN(, ".", 2)
:= [0]
if len() == 1 {
[] = true
} else {
if [] == nil {
[] = map[string]bool{}
}
[][[1]] = true
}
}
, := schemaToMap(, , , )
if != nil {
return nil,
}
return json.Marshal()
}
func ( interface{}, , map[string]bool, map[string]map[string]bool) (map[string]interface{}, error) {
:= make(map[string]interface{})
:= reflect.ValueOf()
:= .Type()
for := 0; < .NumField(); ++ {
:= .Field().Tag.Get("json")
if == "" {
continue
}
, := parseJSONTag()
if != nil {
return nil,
}
if .ignore {
continue
}
:= .Field()
:= .Field()
if [.Name] {
if !isEmptyValue() {
return nil, fmt.Errorf("field %q in NullFields has non-empty value", .Name)
}
[.apiName] = nil
continue
}
if !includeField(, , ) {
continue
}
if .Type.Kind() == reflect.Map && [.Name] != nil {
, := .Interface().(map[string]string)
if ! {
return nil, fmt.Errorf("field %q has keys in NullFields but is not a map[string]string", .Name)
}
:= map[string]interface{}{}
for , := range {
[] =
}
for := range [.Name] {
[] = nil
}
[.apiName] =
continue
}
func ( string) (jsonTag, error) {
if == "-" {
return jsonTag{ignore: true}, nil
}
var jsonTag
:= strings.Index(, ",")
if == -1 || [:] == "" {
return , fmt.Errorf("malformed json tag: %s", )
}
= jsonTag{
apiName: [:],
}
switch [+1:] {
case "omitempty":
case "omitempty,string":
.stringFormat = true
default:
return , fmt.Errorf("malformed json tag: %s", )
}
return , nil
}
func ( reflect.Value) bool {
switch .Kind() {
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
return .Len() == 0
case reflect.Bool:
return !.Bool()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return .Int() == 0
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return .Uint() == 0
case reflect.Float32, reflect.Float64:
return .Float() == 0
case reflect.Interface, reflect.Ptr:
return .IsNil()
}
return false
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |