Improving

master
Paulo Simão 2021-11-28 19:08:32 -03:00
parent 984592b7fd
commit 3cc08c6bb9
6 changed files with 101 additions and 16 deletions

View File

@ -34,6 +34,9 @@ func addStruct(a *ast.GenDecl) {
llog("Adding type: %s => %#v", tp.Name, md) llog("Adding type: %s => %#v", tp.Name, md)
for _, v := range a.Specs[0].(*ast.TypeSpec).Type.(*ast.StructType).Fields.List { for _, v := range a.Specs[0].(*ast.TypeSpec).Type.(*ast.StructType).Fields.List {
if len(v.Names) < 1 {
panic("Does not support Composition: " + tp.Name)
}
tp.Fields[v.Names[0].Name] = &APIField{} tp.Fields[v.Names[0].Name] = &APIField{}
tp.Fields[v.Names[0].Name].Tags = make(map[string]APIFieldTag) tp.Fields[v.Names[0].Name].Tags = make(map[string]APIFieldTag)
@ -203,6 +206,7 @@ func addFunction(a *ast.FuncDecl) error {
return nil return nil
} }
// load is responsible for loading the package for AST Parsing
func load(src string) error { func load(src string) error {
api.Types = (make(map[string]*APIType)) api.Types = (make(map[string]*APIType))
@ -221,6 +225,7 @@ func load(src string) error {
return err return err
} }
//iterate over packages
for _, v := range f { for _, v := range f {
llog("Loading Package: %s", v.Name) llog("Loading Package: %s", v.Name)

View File

@ -9,7 +9,7 @@ type API struct {
Imports map[string]string `yaml:"imports"` Imports map[string]string `yaml:"imports"`
UsedImportsTypes map[string]string `yaml:"used_imports_types"` UsedImportsTypes map[string]string `yaml:"used_imports_types"`
UsedImportsFunctions map[string]string `yaml:"used_imports_functions"` UsedImportsFunctions map[string]string `yaml:"used_imports_functions"`
SortedPaths []*APIPath `yaml:"sorted_paths"` SortedPaths []*APIPath `yaml:"-"`
Paths map[string]*APIPath `yaml:"paths"` Paths map[string]*APIPath `yaml:"paths"`
} }
@ -65,8 +65,9 @@ type APIMethod struct {
Desc string `yaml:"desc"` Desc string `yaml:"desc"`
Verb string `yaml:"verb"` Verb string `yaml:"verb"`
Path string `yaml:"path"` Path string `yaml:"path"`
Perm string `yaml:perm` Perm string `yaml:"perm"`
Raw bool `yaml:"raw"` Raw bool `yaml:"raw"`
OpID string `yaml:"op_id"`
ReqType *APIParamType ReqType *APIParamType
ResType *APIParamType ResType *APIParamType
} }

View File

@ -6,7 +6,7 @@ import (
"os" "os"
) )
var Ver string = "Tue Sep 7 12:38:32 -03 2021" var Ver string = "2021-11-28T13:57:28.822468Z"
func main() { func main() {
os.Stdout.WriteString(fmt.Sprintf("Version: %s\n", Ver)) os.Stdout.WriteString(fmt.Sprintf("Version: %s\n", Ver))

View File

@ -191,6 +191,7 @@ func Init() *API {
}) })
mux.HandleFunc("/some2", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/some2", func(w http.ResponseWriter, r *http.Request) {
switch r.Method { switch r.Method {
case "POST": case "POST":
h_Dosome2(w, r) h_Dosome2(w, r)
default: default:

View File

@ -1,21 +1,99 @@
types:
AStr:
name: AStr
fields:
Arrofpstr:
type: string
array: true
tags:
json:
key: json
name: arrofpstr
opts:
- omitempty
City:
type: string
Country:
type: string
HouseNumber:
type: int64
IsCondo:
type: bool
Recursive:
map: true
mapkey: string
mapval: AStr
Some:
type: crypto.Decrypter
SomeWeirdTest:
type: string
tags:
json:
key: json
name: SUPERCALIFRAGILISPEALIDOUX
opts: []
When:
type: time.Time
methods: methods:
SomeAPI3: SomeAPI:
desc: SomeAPI3 name: SomeAPI
verb: PUT desc: SomeAPI
verb: POST
path: /someapi path: /someapi
perm: ASD perm: ASD
raw: false
reqtype: reqtype:
typename: time.Time typename: AStr
ispointer: false ispointer: true
isarray: false isarray: false
restype: restype:
typename: string typename: AStr
ispointer: false ispointer: true
isarray: true isarray: false
raw: false namespace: goapi
namespace: ""
imports: imports:
context: context context: context
crypto: crypto
time: time time: time
used_imports: used_imports_types:
- time crypto: crypto
time: time
used_imports_functions: {}
paths:
/someapi:
path: /someapi
map_verbs:
POST:
verb: POST
method:
name: SomeAPI
desc: SomeAPI
verb: POST
path: /someapi
perm: ASD
raw: false
reqtype:
typename: AStr
ispointer: true
isarray: false
restype:
typename: AStr
ispointer: true
isarray: false
sorted_verbs:
- verb: POST
method:
name: SomeAPI
desc: SomeAPI
verb: POST
path: /someapi
perm: ASD
raw: false
reqtype:
typename: AStr
ispointer: true
isarray: false
restype:
typename: AStr
ispointer: true
isarray: false

View File

@ -25,7 +25,7 @@ type AStr struct {
@PERM: ASD @PERM: ASD
@VERB: POST @VERB: POST
*/ */
func SomeAPI(ctx context.Context, s *AStr, c int) (out *AStr, err error) { func SomeAPI(ctx context.Context, s *AStr) (out *AStr, err error) {
//print("Got:" + s) //print("Got:" + s)
//out = time.Now().String() + " - Hey Ya!" //out = time.Now().String() + " - Hey Ya!"
return return