Skip to content

Instantly share code, notes, and snippets.

@CMGS
Created September 24, 2014 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMGS/2458c95202e807c86c0d to your computer and use it in GitHub Desktop.
Save CMGS/2458c95202e807c86c0d to your computer and use it in GitHub Desktop.
reflect
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