diff --git a/codemsg/stringer.go b/codemsg/stringer.go index 0560dc5..df29ce4 100644 --- a/codemsg/stringer.go +++ b/codemsg/stringer.go @@ -464,19 +464,22 @@ func (f *File) genDecl(node ast.Node) bool { mapName := "" var err error v.Name, mapName, err = parseTakeCodeToMap(v.Name) - if err != nil { - panic(err) + if len(mapName) > 0 { + + if err != nil { + panic(err) + } + if f.c.SaveCodeToMap == nil { + f.c.SaveCodeToMap = make(map[string]map[int]bool) + } + + saveMap := f.c.SaveCodeToMap[mapName] + if saveMap == nil { + saveMap = make(map[int]bool) + } + saveMap[int(v.value)] = true + f.c.SaveCodeToMap[mapName] = saveMap } - if f.c.SaveCodeToMap == nil { - f.c.SaveCodeToMap = make(map[string]map[int]bool) - } - - saveMap := f.c.SaveCodeToMap[mapName] - if saveMap == nil { - saveMap = make(map[int]bool) - } - saveMap[int(v.value)] = true - f.c.SaveCodeToMap[mapName] = saveMap } f.values = append(f.values, v) diff --git a/codemsg/take_to_map.go b/codemsg/take_to_map.go index cfcc6e8..dce960d 100644 --- a/codemsg/take_to_map.go +++ b/codemsg/take_to_map.go @@ -63,7 +63,7 @@ func saveTakeFileMap(dir, packageName, types string, mapName string, m map[int]b } sourceCode, err := format.Source(buf.Bytes()) if err != nil { - panic(err) + panic(string(buf.Bytes())) } err = os.WriteFile(fileName, sourceCode, 0o644) diff --git a/testdata/err.go b/testdata/err.go index 0dfe6a5..bebc991 100644 --- a/testdata/err.go +++ b/testdata/err.go @@ -6,4 +6,6 @@ const ( ENo ErrNo = 1003 // 号码出错 @TakeCodeToMap(InfoMap) ENotFound ErrNo = 1004 // 找不到 @TakeCodeToMap(InfoMap) + + ENotLogin ErrNo = 1005 // 未登录 )