-
-
Save CMGS/2458c95202e807c86c0d to your computer and use it in GitHub Desktop.
reflect
This file contains 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 ( | |
"fmt" | |
"github.com/fsouza/go-dockerclient" | |
"reflect" | |
) | |
type Test struct { | |
*docker.Client | |
PushImage func(docker.PushImageOptions, docker.AuthConfiguration) error | |
} | |
func main() { | |
errorType := reflect.TypeOf(make([]error, 1)).Elem() | |
client, _ := docker.NewClient("tcp://192.168.59.103:2375") | |
t := Test{Client: client} | |
v := reflect.ValueOf(&t).Elem() | |
for i := 1; i < reflect.TypeOf(t).NumField(); i++ { | |
a := v.Field(i) | |
f := reflect.MakeFunc(a.Type(), func(in []reflect.Value) []reflect.Value { | |
return []reflect.Value{reflect.Zero(errorType)} | |
}) | |
a.Set(f) | |
} | |
z := &t | |
fmt.Println(z) | |
fmt.Println(z.PushImage(docker.PushImageOptions{}, docker.AuthConfiguration{})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment