a lil bit refactoring
This commit is contained in:
parent
2759bec46c
commit
10ac5dfae8
9
kitcom/common/parser.go
Normal file
9
kitcom/common/parser.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
type Parser struct {
|
||||||
|
Files []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Parser) AddFile(path string) {
|
||||||
|
p.Files = append(p.Files, path)
|
||||||
|
}
|
||||||
@ -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)
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user