Skip to content

Commit

Permalink
fix panic when reflecting on maps (#181)
Browse files Browse the repository at this point in the history
```
package main

//go:generate msgp

import (
	"bytes"
	"fmt"
	"os"

	"github.com/tinylib/msgp/msgp"
)

type Feedback map[string]interface{}

func main() {
	deepMap := make(map[string]map[string]string)
	feedback := Feedback{"general": deepMap}

	bb := new(bytes.Buffer)
	if err := msgp.Encode(bb, feedback); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
		os.Exit(1)
	}
	fmt.Printf("%#v\n", bb.Bytes())
}

// 1. Type `go generate main.go`.
// 2. Type `go run main.go main_gen.go`.
```
  • Loading branch information
Karrick McDermott authored and philhofer committed Jun 27, 2017
1 parent 02d047e commit b2b6a67
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion msgp/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ func (mw *Writer) WriteIntf(v interface{}) error {
}

func (mw *Writer) writeMap(v reflect.Value) (err error) {
if v.Elem().Kind() != reflect.String {
if v.Type().Key().Kind() != reflect.String {
return errors.New("msgp: map keys must be strings")
}
ks := v.MapKeys()
Expand Down

0 comments on commit b2b6a67

Please sign in to comment.