Чистка: Decl обработчики вынесены в отдельный файл

Этот коммит содержится в:
Softonik 2024-01-22 03:35:47 +03:00 коммит произвёл Nobody
родитель 912d0c6a29
коммит 3b400bccbb
3 изменённых файлов: 32 добавлений и 27 удалений

18
pkg/service/decl.go Обычный файл
Просмотреть файл

@ -0,0 +1,18 @@
package service
import (
"go/ast"
)
func handleDecl(id int, decl ast.Decl, dst chan<- string, done chan<- bool) {
code := ""
switch d := decl.(type) {
case *ast.FuncDecl:
code += handleFuncDecl(d)
case *ast.GenDecl:
code += handleGenDecl(d)
}
dst <- code
close(dst)
done <- true
}

Просмотреть файл

@ -2,7 +2,6 @@ package service
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"io"
@ -152,29 +151,3 @@ func (s *defaultService) printGoHelperDeclarations() {
}
s.out.Write([]byte("\n"))
}
func handleDecl(id int, decl ast.Decl, dst chan<- string, done chan<- bool) {
code := ""
switch d := decl.(type) {
case *ast.FuncDecl:
code += handleFuncDecl(d)
case *ast.GenDecl:
code += handleGenDecl(d)
}
dst <- code
close(dst)
done <- true
}
func handleGenDecl(decl ast.Decl) string {
gd := decl.(*ast.GenDecl)
code := ""
switch gd.Tok {
case token.CONST:
code += "const "
case token.VAR:
code += ""
}
code += handleSpecs(gd.Specs)
return code
}

Просмотреть файл

@ -2,8 +2,22 @@ package service
import (
"go/ast"
"go/token"
)
func handleGenDecl(decl ast.Decl) string {
gd := decl.(*ast.GenDecl)
code := ""
switch gd.Tok {
case token.CONST:
code += "const "
case token.VAR:
code += ""
}
code += handleSpecs(gd.Specs)
return code
}
func handleSpecs(specs []ast.Spec) string {
code := ""
for _, spec := range specs {