Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Dec 20, 2023
1 parent fe498e9 commit f06ff8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
27 changes: 15 additions & 12 deletions codemsg/stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion codemsg/take_to_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions testdata/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ const (
ENo ErrNo = 1003 // 号码出错 @TakeCodeToMap(InfoMap)

ENotFound ErrNo = 1004 // 找不到 @TakeCodeToMap(InfoMap)

ENotLogin ErrNo = 1005 // 未登录
)

0 comments on commit f06ff8d

Please sign in to comment.