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)
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].Tags = make(map[string]APIFieldTag)
@ -203,6 +206,7 @@ func addFunction(a *ast.FuncDecl) error {
return nil
}
// load is responsible for loading the package for AST Parsing
func load(src string) error {
api.Types = (make(map[string]*APIType))
@ -221,6 +225,7 @@ func load(src string) error {
return err
}
//iterate over packages
for _, v := range f {
llog("Loading Package: %s", v.Name)

View File

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

View File

@ -6,7 +6,7 @@ import (
"os"
)
var Ver string = "Tue Sep 7 12:38:32 -03 2021"
var Ver string = "2021-11-28T13:57:28.822468Z"
func main() {
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) {
switch r.Method {
case "POST":
h_Dosome2(w, r)
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:
SomeAPI3:
desc: SomeAPI3
verb: PUT
SomeAPI:
name: SomeAPI
desc: SomeAPI
verb: POST
path: /someapi
perm: ASD
raw: false
reqtype:
typename: time.Time
ispointer: false
typename: AStr
ispointer: true
isarray: false
restype:
typename: string
ispointer: false
isarray: true
raw: false
namespace: ""
typename: AStr
ispointer: true
isarray: false
namespace: goapi
imports:
context: context
crypto: crypto
time: time
used_imports:
- time
used_imports_types:
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
@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)
//out = time.Now().String() + " - Hey Ya!"
return