func (ctx context) CopyTo(target match.Context) { // shallow copy *target.Misc() = ctx.misc *target.Special() = ctx.special trg := target.Map() for k, val := range ctx.Map() { // If we want to allow pointers to structs in the map, we have to copy // one level deeper, i.e. instead of copying the pointer, reflect and // copy what it points to. rval := reflect.ValueOf(val) if rval.Kind() == reflect.Ptr { rv := reflect.New(rval.Type().Elem()) rv.Elem().Set(rval.Elem()) trg[k] = rv.Interface() } else { trg[k] = val } } }