multi fixtures

master
Paulo Simão 2021-03-21 23:08:04 -03:00
parent 378306892f
commit 12e471958e
11 changed files with 240 additions and 201 deletions

View File

@ -1,4 +0,0 @@
gofname: test/goapi/api.go
goimpldir: test/goapi
tsfname: test/tscli/api.ts
goclifname: test/gocli/apicli.go

1
go.mod
View File

@ -6,6 +6,7 @@ require (
github.com/alecthomas/kong v0.2.15 github.com/alecthomas/kong v0.2.15
github.com/fatih/structtag v1.2.0 github.com/fatih/structtag v1.2.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
go.digitalcircle.com.br/dc/golib v0.0.0-20210321170103-c3e68008b19e // indirect
go.digitalcircle.com.br/golib/base v0.0.0-20210124165830-341c1d300435 go.digitalcircle.com.br/golib/base v0.0.0-20210124165830-341c1d300435
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
) )

101
go.sum
View File

@ -1,19 +1,120 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/alecthomas/kong v0.2.15 h1:HP3K1XuFn0wGSWFGVW67V+65tXw/Ht8FDYiLNAuX2Ug= github.com/alecthomas/kong v0.2.15 h1:HP3K1XuFn0wGSWFGVW67V+65tXw/Ht8FDYiLNAuX2Ug=
github.com/alecthomas/kong v0.2.15/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE= github.com/alecthomas/kong v0.2.15/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs=
github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk=
github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28=
github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo=
github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk=
github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw=
github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360=
github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg=
github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE=
github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8=
github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomodule/redigo v1.8.4/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
go.digitalcircle.com.br/dc/golib v0.0.0-20210321170103-c3e68008b19e h1:AJU6WBeMg8y0ijBabhpjS3rhlIpdNlQNv8sTLmVmmns=
go.digitalcircle.com.br/dc/golib v0.0.0-20210321170103-c3e68008b19e/go.mod h1:0DBjz1XuKGTxXge679K5ZYzkXrjbP6ImWm4kU/BlLUs=
go.digitalcircle.com.br/golib/base v0.0.0-20210124165830-341c1d300435 h1:XVnDH9egiX/iTc59738ZozUZHGahb494y52oxmLJYN4= go.digitalcircle.com.br/golib/base v0.0.0-20210124165830-341c1d300435 h1:XVnDH9egiX/iTc59738ZozUZHGahb494y52oxmLJYN4=
go.digitalcircle.com.br/golib/base v0.0.0-20210124165830-341c1d300435/go.mod h1:8BeArwDJW81pf5Fhchrs/Hh2YSg0FMnNeaV+j1kUEyM= go.digitalcircle.com.br/golib/base v0.0.0-20210124165830-341c1d300435/go.mod h1:8BeArwDJW81pf5Fhchrs/Hh2YSg0FMnNeaV+j1kUEyM=
go.mongodb.org/mongo-driver v1.5.0/go.mod h1:boiGPFqyBs5R0R5qf2ErokGRekMfwn+MqKaUyHs7wy0=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -1,20 +1,22 @@
package main package main
import ( import (
"fmt"
"github.com/fatih/structtag" "github.com/fatih/structtag"
"go/token"
"net/http"
)
import (
"go/ast" "go/ast"
"go/parser" "go/parser"
"go/token"
"log" "log"
"net/http"
"strings" "strings"
) )
var api API var api API
func llog(s string, p ...interface{}) {
fmt.Printf(s+"\n", p...)
}
func addStruct(a *ast.GenDecl) { func addStruct(a *ast.GenDecl) {
md := manageComments(a.Doc) md := manageComments(a.Doc)
if md["API"] == "" { if md["API"] == "" {
@ -27,12 +29,14 @@ func addStruct(a *ast.GenDecl) {
Col: md["COL"], Col: md["COL"],
} }
tp.Name = a.Specs[0].(*ast.TypeSpec).Name.Name tp.Name = a.Specs[0].(*ast.TypeSpec).Name.Name
log.Printf("Type:" + tp.Name) 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 {
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)
switch x := v.Type.(type) { switch x := v.Type.(type) {
case *ast.Ident: case *ast.Ident:
tp.Fields[v.Names[0].Name].Type = x.Name tp.Fields[v.Names[0].Name].Type = x.Name
case *ast.ArrayType: case *ast.ArrayType:
@ -43,8 +47,8 @@ func addStruct(a *ast.GenDecl) {
case *ast.InterfaceType: case *ast.InterfaceType:
tp.Fields[v.Names[0].Name].Type = "interface{}" tp.Fields[v.Names[0].Name].Type = "interface{}"
tp.Fields[v.Names[0].Name].Array = true tp.Fields[v.Names[0].Name].Array = true
case *ast.SelectorExpr: case *ast.SelectorExpr:
api.UsedImportsTypes[z.X.(*ast.Ident).Name] = true
tp.Fields[v.Names[0].Name].Type = z.X.(*ast.Ident).Name + "." + z.Sel.Name tp.Fields[v.Names[0].Name].Type = z.X.(*ast.Ident).Name + "." + z.Sel.Name
tp.Fields[v.Names[0].Name].Array = true tp.Fields[v.Names[0].Name].Array = true
} }
@ -56,9 +60,11 @@ func addStruct(a *ast.GenDecl) {
case *ast.SelectorExpr: case *ast.SelectorExpr:
switch z := y.X.(type) { switch z := y.X.(type) {
case *ast.Ident: case *ast.Ident:
api.UsedImportsTypes[z.Name] = true
tp.Fields[v.Names[0].Name].Type = z.Name + "." + y.Sel.Name tp.Fields[v.Names[0].Name].Type = z.Name + "." + y.Sel.Name
} }
} }
case *ast.InterfaceType: case *ast.InterfaceType:
tp.Fields[v.Names[0].Name].Type = "interface{}" tp.Fields[v.Names[0].Name].Type = "interface{}"
@ -66,6 +72,7 @@ func addStruct(a *ast.GenDecl) {
switch z := x.X.(type) { switch z := x.X.(type) {
case *ast.Ident: case *ast.Ident:
api.UsedImportsTypes[z.Name] = true
tp.Fields[v.Names[0].Name].Type = z.Name + "." + x.Sel.Name tp.Fields[v.Names[0].Name].Type = z.Name + "." + x.Sel.Name
} }
@ -115,6 +122,8 @@ func addFunction(a *ast.FuncDecl) {
if md["API"] == "" { if md["API"] == "" {
return return
} }
llog("Adding Fuction: %s => %#v", a.Name, md)
reqType := &APIParamType{} reqType := &APIParamType{}
resType := &APIParamType{} resType := &APIParamType{}
@ -126,6 +135,7 @@ func addFunction(a *ast.FuncDecl) {
case *ast.Ident: case *ast.Ident:
reqType.Typename = y.Name reqType.Typename = y.Name
case *ast.SelectorExpr: case *ast.SelectorExpr:
api.UsedImportsFunctions[y.X.(*ast.Ident).Name] = true
reqType.Typename = y.X.(*ast.Ident).Name + "." + y.Sel.Name reqType.Typename = y.X.(*ast.Ident).Name + "." + y.Sel.Name
} }
case *ast.ArrayType: case *ast.ArrayType:
@ -134,6 +144,7 @@ func addFunction(a *ast.FuncDecl) {
case *ast.Ident: case *ast.Ident:
reqType.Typename = y.Name reqType.Typename = y.Name
case *ast.SelectorExpr: case *ast.SelectorExpr:
api.UsedImportsFunctions[y.X.(*ast.Ident).Name] = true
reqType.Typename = y.X.(*ast.Ident).Name + "." + y.Sel.Name reqType.Typename = y.X.(*ast.Ident).Name + "." + y.Sel.Name
case *ast.StarExpr: case *ast.StarExpr:
reqType.Ispointer = true reqType.Ispointer = true
@ -141,11 +152,15 @@ func addFunction(a *ast.FuncDecl) {
case *ast.Ident: case *ast.Ident:
reqType.Typename = z.Name reqType.Typename = z.Name
case *ast.SelectorExpr: case *ast.SelectorExpr:
api.UsedImportsFunctions[z.X.(*ast.Ident).Name] = true
reqType.Typename = z.X.(*ast.Ident).Name + "." + z.Sel.Name reqType.Typename = z.X.(*ast.Ident).Name + "." + z.Sel.Name
} }
} }
case *ast.Ident: case *ast.Ident:
reqType.Typename = x.Name reqType.Typename = x.Name
case *ast.SelectorExpr:
api.UsedImportsFunctions[x.X.(*ast.Ident).Name] = true
reqType.Typename = x.X.(*ast.Ident).Name + "." + x.Sel.Name
} }
} }
@ -158,6 +173,7 @@ func addFunction(a *ast.FuncDecl) {
case *ast.Ident: case *ast.Ident:
resType.Typename = y.Name resType.Typename = y.Name
case *ast.SelectorExpr: case *ast.SelectorExpr:
api.UsedImportsFunctions[y.X.(*ast.Ident).Name] = true
resType.Typename = y.X.(*ast.Ident).Name + "." + y.Sel.Name resType.Typename = y.X.(*ast.Ident).Name + "." + y.Sel.Name
} }
case *ast.ArrayType: case *ast.ArrayType:
@ -166,6 +182,7 @@ func addFunction(a *ast.FuncDecl) {
case *ast.Ident: case *ast.Ident:
resType.Typename = y.Name resType.Typename = y.Name
case *ast.SelectorExpr: case *ast.SelectorExpr:
api.UsedImportsFunctions[y.X.(*ast.Ident).Name] = true
resType.Typename = y.X.(*ast.Ident).Name + "." + y.Sel.Name resType.Typename = y.X.(*ast.Ident).Name + "." + y.Sel.Name
case *ast.StarExpr: case *ast.StarExpr:
resType.Ispointer = true resType.Ispointer = true
@ -173,9 +190,15 @@ func addFunction(a *ast.FuncDecl) {
case *ast.Ident: case *ast.Ident:
resType.Typename = z.Name resType.Typename = z.Name
case *ast.SelectorExpr: case *ast.SelectorExpr:
api.UsedImportsFunctions[z.X.(*ast.Ident).Name] = true
resType.Typename = z.X.(*ast.Ident).Name + "." + z.Sel.Name resType.Typename = z.X.(*ast.Ident).Name + "." + z.Sel.Name
} }
} }
case *ast.Ident:
resType.Typename = x.Name
case *ast.SelectorExpr:
api.UsedImportsFunctions[x.X.(*ast.Ident).Name] = true
resType.Typename = x.X.(*ast.Ident).Name + "." + x.Sel.Name
} }
@ -211,6 +234,9 @@ func load(src string) error {
api.Types = (make(map[string]*APIType)) api.Types = (make(map[string]*APIType))
api.Methods = (make(map[string]*APIMethod)) api.Methods = (make(map[string]*APIMethod))
api.Imports = make(map[string]string)
api.UsedImportsTypes = make(map[string]bool)
api.UsedImportsFunctions = make(map[string]bool)
fset := token.NewFileSet() // positions are relative to fset fset := token.NewFileSet() // positions are relative to fset
@ -221,6 +247,8 @@ func load(src string) error {
} }
for _, v := range f { for _, v := range f {
llog("Loading Package: %s", v.Name)
// Print the AST. // Print the AST.
ast.Inspect(v, func(n ast.Node) bool { ast.Inspect(v, func(n ast.Node) bool {
@ -232,12 +260,23 @@ func load(src string) error {
} else { } else {
return true return true
} }
case *ast.ImportSpec:
var impkey = ""
var impval = ""
impval = strings.Replace(x.Path.Value, "\"", "", -1)
impval = strings.Replace(impval, "'", "", -1)
if x.Name != nil && x.Name.Name != "" {
impkey = x.Name.Name
} else {
parts := strings.Split(impval, "/")
impkey = parts[len(parts)-1]
}
api.Imports[impkey] = impval
case *ast.File: case *ast.File:
c := manageCommentsGroups(x.Comments) manageCommentsGroups(x.Comments)
log.Printf("%+v", c)
case *ast.FuncDecl: case *ast.FuncDecl:
addFunction(x) addFunction(x)
llog("Adding fn: %s", x.Name)
case *ast.ValueSpec: case *ast.ValueSpec:
if x.Names[0].Name == "BASEPATH" { if x.Names[0].Name == "BASEPATH" {
api.BasePath = strings.Replace(x.Values[0].(*ast.BasicLit).Value, "\"", "", -1) api.BasePath = strings.Replace(x.Values[0].(*ast.BasicLit).Value, "\"", "", -1)

View File

@ -38,6 +38,16 @@ import (
) )
`, packageName)) `, packageName))
for v, _ := range api.UsedImportsFunctions {
parts := strings.Split(api.Imports[v], "/")
lpart := parts[len(parts)-1]
if v != lpart {
b.WriteString(fmt.Sprintf("import %s \"%s\"\n", v, api.Imports[v]))
} else {
b.WriteString(fmt.Sprintf("import \"%s\"\n", api.Imports[v]))
}
}
b.WriteString(` b.WriteString(`
type API struct { type API struct {
@ -113,9 +123,9 @@ ret.Perms["%s_%s"]="%s"
ctx := r.Context() ctx := r.Context()
ctx = context.WithValue(r.Context(), "REQ", r) ctx = context.WithValue(r.Context(), "REQ", r)
ctx = context.WithValue(ctx, "RES", w) ctx = context.WithValue(ctx, "RES", w)
req := %s{} var req %s
if r.Method!=http.MethodGet && r.Method!=http.MethodHead { if r.Method!=http.MethodGet && r.Method!=http.MethodHead {
err := json.NewDecoder(r.Body).Decode(&req) err := json.NewDecoder(r.Body).Decode(%sreq)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
@ -135,7 +145,7 @@ ret.Perms["%s_%s"]="%s"
} }
} }
`, APIParamTypeToString(m.ReqType), k)) `, APIParamTypeToString(m.ReqType), APIParamTypeUseRef(m.ReqType), k))
} }
} }

View File

@ -1,11 +1,14 @@
package main package main
type API struct { type API struct {
BasePath string `yaml:"basepath"` BasePath string `yaml:"basepath,omitempty"`
Host string `yaml:"host"` Host string `yaml:"host,omitempty"`
Types map[string]*APIType `yaml:"types"` Types map[string]*APIType `yaml:"types,omitempty"`
Methods map[string]*APIMethod `yaml:"methods"` Methods map[string]*APIMethod `yaml:"methods,omitempty"`
Namespace string Namespace string `yaml:"namespace"`
Imports map[string]string `yaml:"imports"`
UsedImportsTypes map[string]bool `yaml:"used_imports_types"`
UsedImportsFunctions map[string]bool `yaml:"used_imports_functions"`
} }
type APIFieldTag struct { type APIFieldTag struct {
Key string Key string
@ -13,13 +16,13 @@ type APIFieldTag struct {
Opts []string Opts []string
} }
type APIField struct { type APIField struct {
Type string `yaml:"type"` Type string `yaml:"type,omitempty"`
Array bool `yaml:"array"` Array bool `yaml:"array,omitempty"`
Desc string `yaml:"desc"` Desc string `yaml:"desc,omitempty"`
Map bool `yaml:"map"` Map bool `yaml:"map,omitempty"`
Mapkey string `yaml:"mapkey"` Mapkey string `yaml:"mapkey,omitempty"`
Mapval string `yaml:"mapval"` Mapval string `yaml:"mapval,omitempty"`
Tags map[string]APIFieldTag Tags map[string]APIFieldTag `yaml:"tags,omitempty"`
} }
func (a *APIField) String() string { func (a *APIField) String() string {
@ -31,10 +34,10 @@ func (a *APIField) String() string {
} }
type APIType struct { type APIType struct {
Name string `yaml:"name"` Name string `yaml:"name,omitempty"`
Desc string `yaml:"desc"` Desc string `yaml:"desc,omitempty"`
Fields map[string]*APIField `yaml:"fields"` Fields map[string]*APIField `yaml:"fields,omitempty"`
Col string `yaml:"col"` Col string `yaml:"col,omitempty"`
} }
type APIParamType struct { type APIParamType struct {
@ -64,7 +67,7 @@ func APIParamTypeToString(t *APIParamType) string {
return ret return ret
} }
if t.Ispointer { if t.Ispointer {
ret = ret + "&" ret = ret + "*"
} }
ret = ret + t.Typename ret = ret + t.Typename
return ret return ret

View File

@ -1,66 +0,0 @@
basepath: ""
host: ""
types:
AStr:
name: AStr
desc: ""
fields:
A:
type: string
array: false
desc: ""
map: false
mapkey: ""
mapval: ""
B:
type: string
array: true
desc: ""
map: false
mapkey: ""
mapval: ""
col: ""
methods:
SomeAPI:
desc: SomeAPI
verb: PUT
path: /someapi
perm: ASD
reqtype:
typename: AStr
ispointer: true
isarray: false
restype:
typename: AStr
ispointer: true
isarray: true
raw: false
SomeAPI2:
desc: SomeAPI2
verb: POST
path: /someapi
perm: ""
reqtype:
typename: AStr
ispointer: true
isarray: false
restype:
typename: AStr
ispointer: true
isarray: true
raw: false
SomeAPI3:
desc: SomeAPI3
verb: POST
path: /someapi3
perm: ""
reqtype:
typename: AStr
ispointer: true
isarray: false
restype:
typename: AStr
ispointer: true
isarray: true
raw: false
namespace: ""

21
test/goapi.yaml 100644
View File

@ -0,0 +1,21 @@
methods:
SomeAPI3:
desc: SomeAPI3
verb: PUT
path: /someapi
perm: ASD
reqtype:
typename: time.Time
ispointer: false
isarray: false
restype:
typename: string
ispointer: false
isarray: true
raw: false
namespace: ""
imports:
context: context
time: time
used_imports:
- time

View File

@ -2,26 +2,10 @@ package goapi
import ( import (
"context" "context"
"crypto"
"time" "time"
) )
//
/*@API*/
type ARequestStruct struct {
A *string `json:"SUPERCALIFRAGILISPEALIDOUX"`
B int64 `json:"bcd"`
C time.Time
D *string
}
/*@API*/
type AResponseStruct struct {
A string
B int64
C time.Time
D *string
}
/*@API*/ /*@API*/
type AStr struct { type AStr struct {
Country string Country string
@ -29,41 +13,40 @@ type AStr struct {
HouseNumber int64 HouseNumber int64
IsCondo bool IsCondo bool
SomeWeirdTest string `json:"SUPERCALIFRAGILISPEALIDOUX"` SomeWeirdTest string `json:"SUPERCALIFRAGILISPEALIDOUX"`
Recursive map[string]AStr
Arrofpstr []string `json:"arrofpstr,omitempty"`
When time.Time
Some crypto.Decrypter
} }
/*@API*/ /*
type AStr2 struct { @API
Firstname string `json:"firstname"` @PATH: /someapi
Lastname string `json:"lastname"` @PERM: ASD
Products []string @VERB: POST
Addresses map[string]AStr */
func SomeAPI(ctx context.Context, s string) (out string, err error) {
print("Got:" + s)
out = time.Now().String() + " - Hey Ya!"
return
} }
/*@API*/
type Noop struct{}
/* /*
@API @API
@PATH: /someapi @PATH: /someapi
@PERM: ASD @PERM: ASD
@VERB: PUT @VERB: PUT
*/ */
func SomeAPI(ctx context.Context, a *Noop) ([]*AStr, error) { //func SomeAPI2(ctx context.Context, s dcsession.Session) ([]string, error) {
return nil, nil // return nil, nil
} //}
/* /*
@API @API
@PATH: /someapi @PATH: /someapi
@PERM: ASD
@VERB: PUT
*/ */
func SomeAPI2(ctx context.Context, a *AStr2) ([]*AStr, error) { //func SomeAPI3(ctx context.Context, a time.Time) ([]string, error) {
return nil, nil // return nil, nil
} //}
/*
@API
@PATH: /someapi3
*/
func SomeAPI3(ctx context.Context, a *AStr) ([]*AStr, error) {
return nil, nil
}

12
test/main.go 100644
View File

@ -0,0 +1,12 @@
package main
import (
"go.digitalcircle.com.br/tools/apigen/test/goapi"
"net/http"
)
func main() {
aapi := goapi.Init()
http.DefaultServeMux.HandleFunc("/", aapi.Mux.ServeHTTP)
http.ListenAndServe(":8080", nil)
}

View File

@ -1,61 +0,0 @@
###
#SomeAPI
PUT https://host/basepath/someapi
Content-Type: application/json
Cookie: dc=<MYCOOKIE>
{}
###
#SomeAPI2
POST https://host/basepath/someapi
Content-Type: application/json
Cookie: dc=<MYCOOKIE>
{
"addresses": {
"a": {
"SUPERCALIFRAGILISPEALIDOUX": "A STRING VALUE",
"city": "A STRING VALUE",
"country": "A STRING VALUE",
"housenumber": 123456,
"iscondo": true
},
"b": {
"SUPERCALIFRAGILISPEALIDOUX": "A STRING VALUE",
"city": "A STRING VALUE",
"country": "A STRING VALUE",
"housenumber": 123456,
"iscondo": true
},
"c": {
"SUPERCALIFRAGILISPEALIDOUX": "A STRING VALUE",
"city": "A STRING VALUE",
"country": "A STRING VALUE",
"housenumber": 123456,
"iscondo": true
}
},
"firstname": "A STRING VALUE",
"lastname": "A STRING VALUE",
"products": [
"A STRING VALUE",
"A STRING VALUE",
"A STRING VALUE"
]
}
###
#SomeAPI3
POST https://host/basepath/someapi3
Content-Type: application/json
Cookie: dc=<MYCOOKIE>
{
"SUPERCALIFRAGILISPEALIDOUX": "A STRING VALUE",
"city": "A STRING VALUE",
"country": "A STRING VALUE",
"housenumber": 123456,
"iscondo": true
}