Last active
April 11, 2017 18:02
-
-
Save narqo/7270b3783a29999774b74db82abb78d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/mailru/easyjson" | |
) | |
type FlatJSONResponse struct { | |
Tmpl string | |
Vars easyjson.RawMessage | |
} | |
func (r *FlatJSONResponse) MarshalJSON() ([]byte, error) { | |
// TODO: | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func writePrefixed(sw *sotaWriter, prefix string, v interface{}) { | |
original := reflect.ValueOf(v) | |
kind := original.Kind() | |
if kind == reflect.Ptr || kind == reflect.Interface { | |
original = reflect.Indirect(original) | |
kind = original.Kind() | |
} | |
t := original.Type() | |
switch kind { | |
case reflect.Struct: | |
for i := 0; i < original.NumField(); i += 1 { | |
childValue := original.Field(i) | |
childKey := t.Field(i).Name | |
writePrefixed(sw, prefix + "_" + childKey, childValue.Interface()) | |
} | |
case reflect.Slice: | |
s := reflect.ValueOf(t) | |
for i := 0; i < s.Len(); i++ { | |
writePrefixed(sw, prefix + "_" + strconv.Itoa(i), s.Index(i).Interface()) | |
} | |
default: | |
sw.w.RawByte(',') | |
sw.writeLeaf(prefix, v) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment