diff --git a/pkg/service/decl.go b/pkg/service/decl.go new file mode 100644 index 0000000..8101073 --- /dev/null +++ b/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 +} diff --git a/pkg/service/service.go b/pkg/service/service.go index 9b5138c..5f2afe1 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -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 -} diff --git a/pkg/service/spec.go b/pkg/service/spec.go index c559d97..2057a79 100644 --- a/pkg/service/spec.go +++ b/pkg/service/spec.go @@ -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 {