Skip to content

Commit

Permalink
realdatatype bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
celt237 committed Jul 4, 2024
1 parent 6574231 commit 09f0f55
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestAnnotation(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
CurrentAnnotationMode = tt.mode
currentAnnotationMode = tt.mode
fileParser := GetFileParser(tt.fileName)
fileDesc, err := fileParser.Parse()
if (err != nil) != tt.wantErr {
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package go_annotation

const AnnotationPrefix = "@"

var CurrentAnnotationMode = AnnotationModeArray
var currentAnnotationMode = AnnotationModeArray
8 changes: 5 additions & 3 deletions go-annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ package go_annotation

// GetFileDesc 获取文件描述
// fileName: 文件名
func GetFileDesc(fileName string) (*FileDesc, error) {
func GetFileDesc(fileName string, mode AnnotationMode) (*FileDesc, error) {
currentAnnotationMode = mode
return GetFileParser(fileName).Parse()
}

// GetFilesDescList 获取文件描述列表
// directory: 目录
func GetFilesDescList(directory string) ([]*FileDesc, error) {
func GetFilesDescList(directory string, mode AnnotationMode) ([]*FileDesc, error) {
currentAnnotationMode = mode
var filesDesc []*FileDesc
// 读取目录下的所有文件
fileNames, err := GetFileNames(directory)
if err != nil {
return nil, err
}
for _, fileName := range fileNames {
fileDesc, err := GetFileDesc(fileName)
fileDesc, err := GetFileParser(fileName).Parse()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions interfaceParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *InterfaceParser) Parse() (*InterfaceDesc, error) {
Methods: methods,
Imports: s.parserImports(methods),
Comments: comments,
Annotations: getAnnotationParser(CurrentAnnotationMode).Parse(comments),
Annotations: getAnnotationParser(currentAnnotationMode).Parse(comments),
}
return sDesc, nil
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func (s *InterfaceParser) parserMethod(method *ast.Field) (methodDesc *MethodDes
// comment
methodDesc.Comments = parseAtComments(method.Doc)
methodDesc.Description = parseDescription(methodDesc.Name, method.Doc)
methodDesc.Annotations = getAnnotationParser(CurrentAnnotationMode).Parse(methodDesc.Comments)
methodDesc.Annotations = getAnnotationParser(currentAnnotationMode).Parse(methodDesc.Comments)
return methodDesc, err
} else {
err = fmt.Errorf("method type is not funcType")
Expand Down
4 changes: 2 additions & 2 deletions structParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *StructParser) Parse() (*StructDesc, error) {
Methods: methods,
Imports: s.parserImports(methods),
Comments: comments,
Annotations: getAnnotationParser(CurrentAnnotationMode).Parse(comments),
Annotations: getAnnotationParser(currentAnnotationMode).Parse(comments),
}
return sDesc, nil
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func (s *StructParser) parserMethod(method *ast.FuncDecl) (methodDesc *MethodDes
// comment
methodDesc.Comments = parseAtComments(method.Doc)
methodDesc.Description = parseDescription(methodDesc.Name, method.Doc)
methodDesc.Annotations = getAnnotationParser(CurrentAnnotationMode).Parse(methodDesc.Comments)
methodDesc.Annotations = getAnnotationParser(currentAnnotationMode).Parse(methodDesc.Comments)
return methodDesc, err
}

Expand Down

0 comments on commit 09f0f55

Please sign in to comment.