1//+build appengine gopherjs purego 2// NB: other environments where unsafe is unappropriate should use "purego" build tag 3// https://github.com/golang/go/issues/23172 4 5package desc 6 7type jsonNameMap struct{} 8type memoizedDefault struct{} 9 10// FindFieldByJSONName finds the field with the given JSON field name. If no such 11// field exists then nil is returned. Only regular fields are returned, not 12// extensions. 13func (md *MessageDescriptor) FindFieldByJSONName(jsonName string) *FieldDescriptor { 14 // NB: With allowed use of unsafe, we use it to atomically define an index 15 // via atomic.LoadPointer/atomic.StorePointer. Without it, we skip the index 16 // and must do a linear scan of fields each time. 17 for _, f := range md.fields { 18 jn := f.GetJSONName() 19 if jn == jsonName { 20 return f 21 } 22 } 23 return nil 24} 25 26func (fd *FieldDescriptor) getDefaultValue() interface{} { 27 return fd.determineDefault() 28} 29