a lil bit refactoring

This commit is contained in:
Egor Aristov 2025-11-08 10:41:17 +03:00
parent 2759bec46c
commit 10ac5dfae8
Signed by: egor3f
GPG Key ID: 40482A264AAEC85F
3 changed files with 15 additions and 12 deletions

9
kitcom/common/parser.go Normal file
View File

@ -0,0 +1,9 @@
package common
type Parser struct {
Files []string
}
func (p *Parser) AddFile(path string) {
p.Files = append(p.Files, path)
}

View File

@ -8,23 +8,20 @@ import (
"regexp" "regexp"
"efprojects.com/kitten-ipc/kitcom/api" "efprojects.com/kitten-ipc/kitcom/api"
"efprojects.com/kitten-ipc/kitcom/common"
) )
var decorComment = regexp.MustCompile(`^//\s?kittenipc:api$`) var decorComment = regexp.MustCompile(`^//\s?kittenipc:api$`)
type GoApiParser struct { type GoApiParser struct {
files []string *common.Parser
}
func (g *GoApiParser) AddFile(path string) {
g.files = append(g.files, path)
} }
func (g *GoApiParser) Parse() (*api.Api, error) { func (g *GoApiParser) Parse() (*api.Api, error) {
var apis api.Api var apis api.Api
for _, f := range g.files { for _, f := range g.Files {
endpoints, err := g.parseFile(f) endpoints, err := g.parseFile(f)
if err != nil { if err != nil {
return nil, fmt.Errorf("parse file: %w", err) return nil, fmt.Errorf("parse file: %w", err)

View File

@ -7,6 +7,7 @@ import (
"strings" "strings"
"efprojects.com/kitten-ipc/kitcom/api" "efprojects.com/kitten-ipc/kitcom/api"
"efprojects.com/kitten-ipc/kitcom/common"
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/ast" "efprojects.com/kitten-ipc/kitcom/internal/tsgo/ast"
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/core" "efprojects.com/kitten-ipc/kitcom/internal/tsgo/core"
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/parser" "efprojects.com/kitten-ipc/kitcom/internal/tsgo/parser"
@ -17,18 +18,14 @@ const TagName = "kittenipc"
const TagComment = "api" const TagComment = "api"
type TypescriptApiParser struct { type TypescriptApiParser struct {
files []string *common.Parser
}
func (t *TypescriptApiParser) AddFile(path string) {
t.files = append(t.files, path)
} }
func (t *TypescriptApiParser) Parse() (*api.Api, error) { func (t *TypescriptApiParser) Parse() (*api.Api, error) {
var apis api.Api var apis api.Api
for _, f := range t.files { for _, f := range t.Files {
endpoints, err := t.parseFile(f) endpoints, err := t.parseFile(f)
if err != nil { if err != nil {
return nil, fmt.Errorf("parse file: %w", err) return nil, fmt.Errorf("parse file: %w", err)