mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-31 13:50:01 +00:00 
			
		
		
		
	godep restore pushd $GOPATH/src/github.com/appc/spec git co master popd go get go4.org/errorutil rm -rf Godeps godep save ./... git add vendor git add -f $(git ls-files --other vendor/) git co -- Godeps/LICENSES Godeps/.license_file_state Godeps/OWNERS
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package rest
 | |
| 
 | |
| import "reflect"
 | |
| 
 | |
| // PayloadMember returns the payload field member of i if there is one, or nil.
 | |
| func PayloadMember(i interface{}) interface{} {
 | |
| 	if i == nil {
 | |
| 		return nil
 | |
| 	}
 | |
| 
 | |
| 	v := reflect.ValueOf(i).Elem()
 | |
| 	if !v.IsValid() {
 | |
| 		return nil
 | |
| 	}
 | |
| 	if field, ok := v.Type().FieldByName("_"); ok {
 | |
| 		if payloadName := field.Tag.Get("payload"); payloadName != "" {
 | |
| 			field, _ := v.Type().FieldByName(payloadName)
 | |
| 			if field.Tag.Get("type") != "structure" {
 | |
| 				return nil
 | |
| 			}
 | |
| 
 | |
| 			payload := v.FieldByName(payloadName)
 | |
| 			if payload.IsValid() || (payload.Kind() == reflect.Ptr && !payload.IsNil()) {
 | |
| 				return payload.Interface()
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| // PayloadType returns the type of a payload field member of i if there is one, or "".
 | |
| func PayloadType(i interface{}) string {
 | |
| 	v := reflect.Indirect(reflect.ValueOf(i))
 | |
| 	if !v.IsValid() {
 | |
| 		return ""
 | |
| 	}
 | |
| 	if field, ok := v.Type().FieldByName("_"); ok {
 | |
| 		if payloadName := field.Tag.Get("payload"); payloadName != "" {
 | |
| 			if member, ok := v.Type().FieldByName(payloadName); ok {
 | |
| 				return member.Tag.Get("type")
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	return ""
 | |
| }
 |