diff --git a/example/testapp/go.mod b/example/testapp/go.mod index 0387e07..bfc1a8e 100644 --- a/example/testapp/go.mod +++ b/example/testapp/go.mod @@ -1,37 +1,40 @@ module testapp -go 1.21.1 +go 1.21.4 require ( github.com/go-sql-driver/mysql v1.7.1 - github.com/google/uuid v1.3.1 - github.com/gorilla/mux v1.8.0 - github.com/hanagantig/gracy v0.0.0-20220629074052-41c110a9e5e2 + github.com/google/uuid v1.4.0 + github.com/gorilla/mux v1.8.1 + github.com/hanagantig/gracy v0.0.0-20231003055507-4d3ebe0e0a0a github.com/jmoiron/sqlx v1.3.5 github.com/lib/pq v1.10.9 - github.com/spf13/cobra v1.7.0 - github.com/spf13/viper v1.16.0 + github.com/spf13/cobra v1.8.0 + github.com/spf13/viper v1.17.0 github.com/stretchr/testify v1.8.4 go.uber.org/zap v1.26.0 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/spf13/afero v1.9.5 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/sagikazarmark/locafero v0.3.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.10.0 // indirect github.com/spf13/cast v1.5.1 // indirect - github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/subosito/gotenv v1.4.2 // indirect + github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/multierr v1.10.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/example/testapp/go.sum b/example/testapp/go.sum index 7ebecef..aad3a44 100644 --- a/example/testapp/go.sum +++ b/example/testapp/go.sum @@ -46,10 +46,11 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -119,15 +120,15 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/hanagantig/gracy v0.0.0-20220629074052-41c110a9e5e2 h1:ptbA6+ou6CLj3nMGZI9Vvolal5YiZJjPyLopGBmWJ/s= -github.com/hanagantig/gracy v0.0.0-20220629074052-41c110a9e5e2/go.mod h1:zYxTkOjIwjnb6vQqC8NByFToJJFkQenCfRxvIP4gI2M= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/hanagantig/gracy v0.0.0-20231003055507-4d3ebe0e0a0a h1:CR69czWLKNoKYA04kZK7hlxTehZi0weSteDJKvVnRqA= +github.com/hanagantig/gracy v0.0.0-20231003055507-4d3ebe0e0a0a/go.mod h1:zYxTkOjIwjnb6vQqC8NByFToJJFkQenCfRxvIP4gI2M= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= @@ -158,43 +159,46 @@ github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRU github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= +github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -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.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= -github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9cJvm4SvQ= +github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= +github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= -github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= -github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= -github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= -github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= -github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= +github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI= +github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= -github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -228,6 +232,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -338,8 +344,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -349,8 +355,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -494,8 +500,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/example/testapp/goro.yaml b/example/testapp/goro.yaml index 86982e1..a15a594 100644 --- a/example/testapp/goro.yaml +++ b/example/testapp/goro.yaml @@ -7,6 +7,7 @@ storages: - mysql - mysqlx - pgsqlx + - http handlers: - http @@ -37,6 +38,12 @@ services: deps: - MyRepo + - name: OrderService + methods: + - GetByID + deps: + - OrdersRepo + adapters: - name: MyRepo storage: mysql @@ -54,4 +61,10 @@ adapters: - name: UserRepo storage: pgsqlx methods: - - GetByID \ No newline at end of file + - GetByID + + - name: OrdersRepo + storage: http + methods: + - GetByID + diff --git a/example/testapp/internal/adapter/httprepo/ordersrepo/get_by_id.go b/example/testapp/internal/adapter/httprepo/ordersrepo/get_by_id.go new file mode 100644 index 0000000..e17286a --- /dev/null +++ b/example/testapp/internal/adapter/httprepo/ordersrepo/get_by_id.go @@ -0,0 +1,10 @@ +package ordersrepo + +import ( + "context" +) + +func (r *Repository) GetByID(ctx context.Context) { + // TODO: put your repository logic here + panic("implement me") +} diff --git a/example/testapp/internal/adapter/httprepo/ordersrepo/repository.go b/example/testapp/internal/adapter/httprepo/ordersrepo/repository.go new file mode 100644 index 0000000..e4bc253 --- /dev/null +++ b/example/testapp/internal/adapter/httprepo/ordersrepo/repository.go @@ -0,0 +1,20 @@ +// Code generated by goro; + +package ordersrepo + +// This file was generated by the goro tool. + +import ( + "net/http" +) + +type Repository struct { + client *http.Client +} + +func NewRepository(client *http.Client) *Repository { + return &Repository{ + + client: client, + } +} diff --git a/example/testapp/internal/adapter/mysqlrepo/myrepo/repository.go b/example/testapp/internal/adapter/mysqlrepo/myrepo/repository.go index e7179ae..62d2745 100644 --- a/example/testapp/internal/adapter/mysqlrepo/myrepo/repository.go +++ b/example/testapp/internal/adapter/mysqlrepo/myrepo/repository.go @@ -6,6 +6,7 @@ package myrepo import ( "database/sql" + "testapp/internal/adapter/mysqlrepo" ) @@ -15,6 +16,7 @@ type Repository struct { func NewRepository(conn *sql.DB) *Repository { return &Repository{ + mysqlrepo.NewTransactor(conn), } } diff --git a/example/testapp/internal/adapter/mysqlxrepo/clientrepo/repository.go b/example/testapp/internal/adapter/mysqlxrepo/clientrepo/repository.go index 4beec75..27f998b 100644 --- a/example/testapp/internal/adapter/mysqlxrepo/clientrepo/repository.go +++ b/example/testapp/internal/adapter/mysqlxrepo/clientrepo/repository.go @@ -6,6 +6,7 @@ package clientrepo import ( "github.com/jmoiron/sqlx" + "testapp/internal/adapter/mysqlxrepo" ) @@ -15,6 +16,7 @@ type Repository struct { func NewRepository(conn *sqlx.DB) *Repository { return &Repository{ + mysqlxrepo.NewTransactor(conn), } } diff --git a/example/testapp/internal/adapter/pgsqlxrepo/userrepo/repository.go b/example/testapp/internal/adapter/pgsqlxrepo/userrepo/repository.go index 2663d89..2fc643c 100644 --- a/example/testapp/internal/adapter/pgsqlxrepo/userrepo/repository.go +++ b/example/testapp/internal/adapter/pgsqlxrepo/userrepo/repository.go @@ -6,6 +6,7 @@ package userrepo import ( "github.com/jmoiron/sqlx" + "testapp/internal/adapter/pgsqlxrepo" ) @@ -15,6 +16,7 @@ type Repository struct { func NewRepository(conn *sqlx.DB) *Repository { return &Repository{ + pgsqlxrepo.NewTransactor(conn), } } diff --git a/example/testapp/internal/app/app.go b/example/testapp/internal/app/app.go index d4a68e4..5056196 100644 --- a/example/testapp/internal/app/app.go +++ b/example/testapp/internal/app/app.go @@ -9,6 +9,7 @@ import ( "database/sql" "errors" "github.com/jmoiron/sqlx" + "net/http" "sync" "go.uber.org/zap/zapcore" @@ -34,6 +35,7 @@ type App struct { mysql *sql.DB mysqlx *sqlx.DB pgsqlx *sqlx.DB + http *http.Client logger Logger } @@ -74,8 +76,11 @@ func NewApp(configPath string) (*App, error) { } app.pgsqlx = pgSqlxConn + httpClient := app.newHttpClient() + app.http = httpClient + //goro:init dependencies - app.c = NewContainer(app.mysql, app.mysqlx, app.pgsqlx) + app.c = NewContainer(app.mysql, app.mysqlx, app.pgsqlx, app.http) return app, nil } diff --git a/example/testapp/internal/app/container.go b/example/testapp/internal/app/container.go index 9584cb4..33a66a0 100644 --- a/example/testapp/internal/app/container.go +++ b/example/testapp/internal/app/container.go @@ -8,12 +8,15 @@ package app import ( "database/sql" "github.com/jmoiron/sqlx" + "net/http" "testapp/internal/usecase" "testapp/internal/service/myservice" + "testapp/internal/service/orderservice" "testapp/internal/service/pingpong" + "testapp/internal/adapter/httprepo/ordersrepo" "testapp/internal/adapter/mysqlrepo/myrepo" "testapp/internal/adapter/mysqlxrepo/clientrepo" "testapp/internal/adapter/pgsqlxrepo/userrepo" @@ -23,16 +26,18 @@ type Container struct { mysql *sql.DB mysqlx *sqlx.DB pgsqlx *sqlx.DB + http *http.Client deps map[string]interface{} } -func NewContainer(mysqlConnect *sql.DB, mysqlxConn *sqlx.DB, pgSqlxConn *sqlx.DB) *Container { +func NewContainer(mysqlConnect *sql.DB, mysqlxConn *sqlx.DB, pgSqlxConn *sqlx.DB, httpClient *http.Client) *Container { return &Container{ mysql: mysqlConnect, mysqlx: mysqlxConn, pgsqlx: pgSqlxConn, + http: httpClient, deps: make(map[string]interface{}), } @@ -55,6 +60,10 @@ func (c *Container) getPgsqlx() *sqlx.DB { return c.pgsqlx } +func (c *Container) getHttp() *http.Client { + return c.http +} + func (c *Container) getMyService() *myservice.Service { return myservice.NewService(c.getMyRepo()) @@ -65,6 +74,11 @@ func (c *Container) getPingPong() *pingpong.Service { return pingpong.NewService(c.getMyRepo()) } +func (c *Container) getOrderService() *orderservice.Service { + + return orderservice.NewService(c.getOrdersRepo()) +} + func (c *Container) getMyRepo() *myrepo.Repository { return myrepo.NewRepository(c.getMysql()) @@ -79,3 +93,8 @@ func (c *Container) getUserRepo() *userrepo.Repository { return userrepo.NewRepository(c.getPgsqlx()) } + +func (c *Container) getOrdersRepo() *ordersrepo.Repository { + + return ordersrepo.NewRepository(c.getHttp()) +} diff --git a/example/testapp/internal/app/http.go b/example/testapp/internal/app/http.go index e8e65e8..cf275ec 100644 --- a/example/testapp/internal/app/http.go +++ b/example/testapp/internal/app/http.go @@ -9,6 +9,7 @@ import ( "fmt" "github.com/hanagantig/gracy" "go.uber.org/zap" + client "net/http" "testapp/internal/handler/http" "testapp/internal/handler/http/api/v1" ) @@ -51,3 +52,8 @@ func (a *App) startHTTPServer() { a.logger.Fatal("Fail to start %s http server:", zap.String("app", a.cfg.App.Name), zap.Error(err)) } } + +func (a *App) newHttpClient() *client.Client { + client := client.Client{} + return &client +} diff --git a/example/testapp/internal/service/myservice/service.go b/example/testapp/internal/service/myservice/service.go index b43904c..7113b91 100644 --- a/example/testapp/internal/service/myservice/service.go +++ b/example/testapp/internal/service/myservice/service.go @@ -10,7 +10,6 @@ import ( type myRepo interface { service.Transactor - // TODO: define interface to inject a service or an adapter } diff --git a/example/testapp/internal/service/orderservice/get_by_id.go b/example/testapp/internal/service/orderservice/get_by_id.go new file mode 100644 index 0000000..3fa4342 --- /dev/null +++ b/example/testapp/internal/service/orderservice/get_by_id.go @@ -0,0 +1,11 @@ +package orderservice + +import ( + "context" +) + +func (s *Service) GetByID(ctx context.Context) { + + // TODO: put your business logic here + panic("implement me") +} diff --git a/example/testapp/internal/service/orderservice/service.go b/example/testapp/internal/service/orderservice/service.go new file mode 100644 index 0000000..d44d036 --- /dev/null +++ b/example/testapp/internal/service/orderservice/service.go @@ -0,0 +1,20 @@ +// Code generated by goro; + +package orderservice + +// This file was generated by the goro tool. + +type ordersRepo interface { + // TODO: define interface to inject a service or an adapter +} + +type Service struct { + ordersRepo ordersRepo +} + +func NewService(ordersRepo ordersRepo) *Service { + return &Service{ + + ordersRepo: ordersRepo, + } +} diff --git a/example/testapp/internal/service/pingpong/service.go b/example/testapp/internal/service/pingpong/service.go index d394e57..5a2895c 100644 --- a/example/testapp/internal/service/pingpong/service.go +++ b/example/testapp/internal/service/pingpong/service.go @@ -10,7 +10,6 @@ import ( type myRepo interface { service.Transactor - // TODO: define interface to inject a service or an adapter } diff --git a/internal/config/adapter.go b/internal/config/adapter.go index c333090..3d11fa4 100644 --- a/internal/config/adapter.go +++ b/internal/config/adapter.go @@ -1,6 +1,8 @@ package config -import "strings" +import ( + "strings" +) type Adapter struct { Name string `yaml:"name"` @@ -19,6 +21,10 @@ func (a Adapter) GetConstructorName() string { return "NewRepository" } +func (a Adapter) IsTransactional() bool { + return transactionalStorages[a.Storage] +} + func (a Adapters) GetMap() map[string]struct{} { res := make(map[string]struct{}, 0) for _, ad := range a { @@ -27,3 +33,12 @@ func (a Adapters) GetMap() map[string]struct{} { return res } + +func (a Adapters) GetTransactionalMap() map[string]bool { + res := make(map[string]bool, len(a)) + for _, ad := range a { + res[ad.Name] = ad.IsTransactional() + } + + return res +} diff --git a/internal/config/data.go b/internal/config/data.go index b0e86a8..c1696b3 100644 --- a/internal/config/data.go +++ b/internal/config/data.go @@ -2,11 +2,12 @@ package config import ( "fmt" - "github.com/manifoldco/promptui" - "gopkg.in/yaml.v2" "io/ioutil" "os" "strings" + + "github.com/manifoldco/promptui" + "gopkg.in/yaml.v2" ) type DependencyName string @@ -30,6 +31,8 @@ type Chunk struct { InitFunc string Build string Configs string + InitConfig string + InitHasErr bool } type App struct { @@ -130,3 +133,36 @@ func (c *Config) askWorkDir() (string, error) { // TODO: validate path }).Run() } + +func (c *Config) GetChunksByScope(scope string) []Chunk { + chunks := make([]Chunk, 0, len(c.Chunks)) + for _, ch := range c.Chunks { + if strings.HasPrefix(ch.Scope, scope) { + chunks = append(chunks, ch) + } + } + + return chunks +} + +func (c *Config) GetChunksByScopeAndInitHasErr(scope string) []Chunk { + chunks := make([]Chunk, 0, len(c.Chunks)) + for _, ch := range c.Chunks { + if strings.HasPrefix(ch.Scope, scope) && ch.InitHasErr { + chunks = append(chunks, ch) + } + } + + return chunks +} + +func (c *Config) GetChunksByScopeAndInitHasNotErr(scope string) []Chunk { + chunks := make([]Chunk, 0, len(c.Chunks)) + for _, ch := range c.Chunks { + if strings.HasPrefix(ch.Scope, scope) && !ch.InitHasErr { + chunks = append(chunks, ch) + } + } + + return chunks +} diff --git a/internal/config/service.go b/internal/config/service.go index c1ed8f3..ee86f2d 100644 --- a/internal/config/service.go +++ b/internal/config/service.go @@ -1,6 +1,8 @@ package config -import "strings" +import ( + "strings" +) type Service struct { AppModule string @@ -19,6 +21,41 @@ func (s Service) GetPkgName() string { return strings.ToLower(s.Name) } +func (s Service) CheckTransactionalDeps(txAdapterMap map[string]bool) bool { + for _, depsName := range s.Deps { + tx := txAdapterMap[depsName] + if tx { + return true + } + } + + return false +} + +func (s Service) GetTransactionalDeps(txAdapterMap map[string]bool) []string { + res := make([]string, 0, len(s.Deps)) + for _, depsName := range s.Deps { + tx := txAdapterMap[depsName] + if tx { + res = append(res, depsName) + } + } + + return res +} + +func (s Service) GetNonTransactionalDeps(txAdapterMap map[string]bool) []string { + res := make([]string, 0, len(s.Deps)) + for _, depsName := range s.Deps { + tx := txAdapterMap[depsName] + if !tx { + res = append(res, depsName) + } + } + + return res +} + func (s Services) GetMap() map[string]struct{} { res := make(map[string]struct{}, 0) for _, svc := range s { diff --git a/internal/config/storage.go b/internal/config/storage.go index 284b5e2..be334e5 100644 --- a/internal/config/storage.go +++ b/internal/config/storage.go @@ -4,12 +4,28 @@ var storagePackages = map[Storage]string{ "mysql": "\"database/sql\"", "mysqlx": "\"github.com/jmoiron/sqlx\"", "pgsqlx": "\"github.com/jmoiron/sqlx\"", + "http": "\"net/http\"", } var connectionsType = map[Storage]string{ "mysql": "*sql.DB", "mysqlx": "*sqlx.DB", "pgsqlx": "*sqlx.DB", + "http": "*http.Client", +} + +var connectionName = map[Storage]string{ + "pgsqlx": "conn", + "mysql": "conn", + "mysqlx": "conn", + "http": "client", +} + +var transactionalStorages = map[Storage]bool{ + "pgsqlx": true, + "mysql": true, + "mysqlx": true, + "http": false, } type Storage string @@ -39,3 +55,7 @@ func (s Storage) GetConnImportName() string { func (s Storage) GetConnectionType() string { return connectionsType[s] } + +func (s Storage) GetConnectionName() string { + return connectionName[s] +} diff --git a/internal/generator/chains/generate_adapters.go b/internal/generator/chains/generate_adapters.go index 393c85b..162b07d 100644 --- a/internal/generator/chains/generate_adapters.go +++ b/internal/generator/chains/generate_adapters.go @@ -2,11 +2,13 @@ package chains import ( "fmt" - entity "github.com/hanagantig/goro/internal/config" - "github.com/hanagantig/goro/pkg/afero" - "github.com/iancoleman/strcase" "os" "strings" + + "github.com/iancoleman/strcase" + + entity "github.com/hanagantig/goro/internal/config" + "github.com/hanagantig/goro/pkg/afero" ) type generateAdapterChain struct{} @@ -61,14 +63,16 @@ func (g *generateAdapterChain) Apply(fs *afero.Afero, data entity.Config) (*afer return nil, err } - generated, err := generate(transactorFilePath, transactorTmpl, adapter) - if err != nil { - return nil, err - } + if adapter.IsTransactional() { + generated, err := generate(transactorFilePath, transactorTmpl, adapter) + if err != nil { + return nil, err + } - err = fs.WriteFile(storageFolderPath+"/transactor.go.tmpl", generated, 0644) - if err != nil { - return nil, err + err = fs.WriteFile(storageFolderPath+"/transactor.go.tmpl", generated, 0644) + if err != nil { + return nil, err + } } } diff --git a/internal/generator/chains/generate_code.go b/internal/generator/chains/generate_code.go index 26e26ce..24364ac 100644 --- a/internal/generator/chains/generate_code.go +++ b/internal/generator/chains/generate_code.go @@ -2,13 +2,15 @@ package chains import ( "bytes" - entity "github.com/hanagantig/goro/internal/config" - "github.com/hanagantig/goro/internal/generator" - "github.com/hanagantig/goro/pkg/afero" + "fmt" "go/format" "os" "strings" "text/template" + + entity "github.com/hanagantig/goro/internal/config" + "github.com/hanagantig/goro/internal/generator" + "github.com/hanagantig/goro/pkg/afero" ) type generateCodeChain struct{} @@ -57,7 +59,7 @@ func (g *generateCodeChain) Apply(fs *afero.Afero, data entity.Config) (*afero.A if strings.Contains(f.Name(), ".go") { formatted, err = format.Source(formatted) if err != nil { - return err + return fmt.Errorf("formated golang file: %w", err) } } diff --git a/internal/generator/chains/generate_services.go b/internal/generator/chains/generate_services.go index 780cf0d..44ae365 100644 --- a/internal/generator/chains/generate_services.go +++ b/internal/generator/chains/generate_services.go @@ -1,10 +1,12 @@ package chains import ( + "os" + + "github.com/iancoleman/strcase" + entity "github.com/hanagantig/goro/internal/config" "github.com/hanagantig/goro/pkg/afero" - "github.com/iancoleman/strcase" - "os" ) type generateServicesChain struct{} @@ -38,6 +40,8 @@ func (g *generateServicesChain) Apply(fs *afero.Afero, data entity.Config) (*afe return nil, err } + trxMap := data.Adapters.GetTransactionalMap() + for _, svc := range data.Services { svc.AppModule = data.App.Module @@ -49,7 +53,19 @@ func (g *generateServicesChain) Apply(fs *afero.Afero, data entity.Config) (*afe } } - generated, err := generate(path, svcTmpl, svc) + svcData := struct { + Service entity.Service + IsTrx bool + TrxDeps []string + NonTrxDeps []string + }{ + Service: svc, + IsTrx: svc.CheckTransactionalDeps(trxMap), + TrxDeps: svc.GetTransactionalDeps(trxMap), + NonTrxDeps: svc.GetNonTransactionalDeps(trxMap), + } + + generated, err := generate(path, svcTmpl, svcData) if err != nil { return nil, err } diff --git a/internal/generator/chunks.go b/internal/generator/chunks.go index ce9e3fd..7347f36 100644 --- a/internal/generator/chunks.go +++ b/internal/generator/chunks.go @@ -2,6 +2,7 @@ package generator import ( "github.com/hanagantig/goro/internal/config" + "github.com/hanagantig/goro/internal/generator/chunks/httpchunk" "github.com/hanagantig/goro/internal/generator/chunks/mysqlchunk" "github.com/hanagantig/goro/internal/generator/chunks/mysqlxchunk" "github.com/hanagantig/goro/internal/generator/chunks/pgsqlxchunk" @@ -11,4 +12,5 @@ var supportedChunks = map[string]config.Chunk{ "mysql": mysqlchunk.NewMySQLChunk(), "mysqlx": mysqlxchunk.NewMySQLxChunk(), "pgsqlx": pgsqlxchunk.NewPostgresChunk(), + "http": httpchunk.NewHttpChunk(), } diff --git a/internal/generator/chunks/httpchunk/build.tpl b/internal/generator/chunks/httpchunk/build.tpl new file mode 100644 index 0000000..283c9c1 --- /dev/null +++ b/internal/generator/chunks/httpchunk/build.tpl @@ -0,0 +1,4 @@ +func (a *App) newHttpClient() *client.Client { + client := client.Client{} + return &client +} diff --git a/internal/generator/chunks/httpchunk/chunk.go b/internal/generator/chunks/httpchunk/chunk.go new file mode 100644 index 0000000..f0b1391 --- /dev/null +++ b/internal/generator/chunks/httpchunk/chunk.go @@ -0,0 +1,29 @@ +package httpchunk + +import ( + _ "embed" + + "github.com/hanagantig/goro/internal/config" +) + +//go:embed build.tpl +var buildTmpl string + +const name = "http" +const initName = "httpClient" + +func NewHttpChunk() config.Chunk { + return config.Chunk{ + Name: name, + Scope: "storage.http", + ArgName: initName, + ReturnType: "*http.Client", + DefinitionImports: "\"net/http\"", + BuildImports: "client \"net/http\"", + InitFunc: "newHttpClient", + Build: buildTmpl, + Configs: "http configs", + InitConfig: "", + InitHasErr: false, + } +} diff --git a/internal/generator/chunks/mysqlchunk/chunk.go b/internal/generator/chunks/mysqlchunk/chunk.go index f9f3c13..e9eca2d 100644 --- a/internal/generator/chunks/mysqlchunk/chunk.go +++ b/internal/generator/chunks/mysqlchunk/chunk.go @@ -2,6 +2,7 @@ package mysqlchunk import ( _ "embed" + "github.com/hanagantig/goro/internal/config" ) @@ -16,7 +17,7 @@ const initHasErr = true func NewMySQLChunk() config.Chunk { return config.Chunk{ Name: name, - Scope: "storage", + Scope: "storage.database.mysql", ArgName: "mysqlConnect", ReturnType: "*sql.DB", DefinitionImports: "\"database/sql\"", @@ -24,5 +25,7 @@ func NewMySQLChunk() config.Chunk { InitFunc: "newMySQLConnect", Build: buildTmpl, Configs: "mysql configs", + InitConfig: "cfg.MainDB", + InitHasErr: true, } } diff --git a/internal/generator/chunks/mysqlxchunk/chunk.go b/internal/generator/chunks/mysqlxchunk/chunk.go index a18bc41..323075d 100644 --- a/internal/generator/chunks/mysqlxchunk/chunk.go +++ b/internal/generator/chunks/mysqlxchunk/chunk.go @@ -2,6 +2,7 @@ package mysqlxchunk import ( _ "embed" + "github.com/hanagantig/goro/internal/config" ) @@ -14,7 +15,7 @@ const initName = "mysqlxConn" func NewMySQLxChunk() config.Chunk { return config.Chunk{ Name: name, - Scope: "storage", + Scope: "storage.database.mysqlx", ArgName: initName, ReturnType: "*sqlx.DB", DefinitionImports: "\"github.com/jmoiron/sqlx\"", @@ -22,5 +23,7 @@ func NewMySQLxChunk() config.Chunk { InitFunc: "newMySQLxConnect", Build: buildTmpl, Configs: "mysqlx configs", + InitConfig: "cfg.MainDB", + InitHasErr: true, } } diff --git a/internal/generator/chunks/pgsqlxchunk/chunk.go b/internal/generator/chunks/pgsqlxchunk/chunk.go index 93d68c1..732adc8 100644 --- a/internal/generator/chunks/pgsqlxchunk/chunk.go +++ b/internal/generator/chunks/pgsqlxchunk/chunk.go @@ -2,6 +2,7 @@ package pgsqlxchunk import ( _ "embed" + "github.com/hanagantig/goro/internal/config" ) @@ -14,7 +15,7 @@ const initName = "pgSqlxConn" func NewPostgresChunk() config.Chunk { return config.Chunk{ Name: name, - Scope: "storage", + Scope: "storage.database.pgsqlx", ArgName: initName, ReturnType: "*sqlx.DB", DefinitionImports: "\"github.com/jmoiron/sqlx\"", @@ -22,5 +23,7 @@ func NewPostgresChunk() config.Chunk { InitFunc: "newPgSqlxConnect", Build: buildTmpl, Configs: "pgSqlx configs", + InitConfig: "cfg.MainDB", + InitHasErr: true, } } diff --git a/internal/generator/renderer.go b/internal/generator/renderer.go index 6948305..be46937 100644 --- a/internal/generator/renderer.go +++ b/internal/generator/renderer.go @@ -2,26 +2,30 @@ package generator import ( "fmt" - entity "github.com/hanagantig/goro/internal/config" - "github.com/iancoleman/strcase" "strings" "text/template" + + "github.com/iancoleman/strcase" + + entity "github.com/hanagantig/goro/internal/config" ) var FuncMap = template.FuncMap{ - "renderImports": RenderImports, - "renderDefinition": RenderDefinitions, - "renderInitializationsWithError": RenderInitializationsWithError, - "renderStructPopulation": RenderStructPopulation, - "renderArgs": RenderArgs, - "renderBuild": RenderBuild, - "toCamelCase": strcase.ToCamel, - "toPrivateName": ToPrivateName, - "toPublicName": ToPublicName, - "contains": strings.Contains, + "renderImports": RenderImports, + "renderDefinition": RenderDefinitions, + "renderInitializationsWithError": RenderInitializationsWithError, + "renderInitializationsWithoutError": RenderInitializationsWithoutError, + "renderStructPopulation": RenderStructPopulation, + "renderArgs": RenderArgs, + "renderBuild": RenderBuild, + "toCamelCase": strcase.ToCamel, + "toPrivateName": ToPrivateName, + "toPublicName": ToPublicName, + "contains": strings.Contains, } -func RenderImports(scope, stage string, chunks []entity.Chunk) string { +func RenderImports(scope, stage string, cfg entity.Config) string { + chunks := cfg.GetChunksByScope(scope) res := strings.Builder{} for _, ch := range chunks { switch stage { @@ -37,7 +41,8 @@ func RenderImports(scope, stage string, chunks []entity.Chunk) string { return res.String() } -func RenderDefinitions(scope string, chunks []entity.Chunk) string { +func RenderDefinitions(scope string, cfg entity.Config) string { + chunks := cfg.GetChunksByScope(scope) res := strings.Builder{} for _, ch := range chunks { fmt.Fprintf(&res, "%v %v\n", ch.Name, ch.ReturnType) @@ -46,10 +51,11 @@ func RenderDefinitions(scope string, chunks []entity.Chunk) string { return res.String() } -func RenderInitializationsWithError(scope, prefix string, chunks []entity.Chunk) string { +func RenderInitializationsWithError(scope, prefix string, cfg entity.Config) string { + chunks := cfg.GetChunksByScopeAndInitHasErr(scope) res := strings.Builder{} for _, ch := range chunks { - fmt.Fprintf(&res, "%v,%v := %v.%v(cfg.MainDB)\n", ch.ArgName, "err", prefix, ch.InitFunc) + fmt.Fprintf(&res, "%v,%v := %v.%v(%v)\n", ch.ArgName, "err", prefix, ch.InitFunc, ch.InitConfig) fmt.Fprintf(&res, "if err != nil {\n return nil, err\n}\n") fmt.Fprintf(&res, "%v.%v = %v\n", prefix, ch.Name, ch.ArgName) } @@ -57,11 +63,23 @@ func RenderInitializationsWithError(scope, prefix string, chunks []entity.Chunk) return res.String() } -func RenderDependency(scope, prefix string, chunks []entity.Chunk) string { +func RenderInitializationsWithoutError(scope, prefix string, cfg entity.Config) string { + chunks := cfg.GetChunksByScopeAndInitHasNotErr(scope) + res := strings.Builder{} + for _, ch := range chunks { + fmt.Fprintf(&res, "%v := %v.%v(%v)\n", ch.ArgName, prefix, ch.InitFunc, ch.InitConfig) + fmt.Fprintf(&res, "%v.%v = %v\n", prefix, ch.Name, ch.ArgName) + } + + return res.String() +} + +func RenderDependency(scope, prefix string, cfg entity.Config) string { return "// render dependencies code" } -func RenderBuild(scope string, chunks []entity.Chunk) string { +func RenderBuild(scope string, cfg entity.Config) string { + chunks := cfg.GetChunksByScope(scope) res := strings.Builder{} for _, ch := range chunks { fmt.Fprintf(&res, "%v\n\n", ch.Build) @@ -70,7 +88,8 @@ func RenderBuild(scope string, chunks []entity.Chunk) string { return res.String() } -func RenderArgs(scope string, chunks []entity.Chunk) string { +func RenderArgs(scope string, cfg entity.Config) string { + chunks := cfg.GetChunksByScope(scope) res := strings.Builder{} for _, ch := range chunks { fmt.Fprintf(&res, "%v %v,", ch.ArgName, ch.ReturnType) @@ -79,7 +98,8 @@ func RenderArgs(scope string, chunks []entity.Chunk) string { return res.String() } -func RenderStructPopulation(scope string, chunks []entity.Chunk) string { +func RenderStructPopulation(scope string, cfg entity.Config) string { + chunks := cfg.GetChunksByScope(scope) res := strings.Builder{} for _, ch := range chunks { fmt.Fprintf(&res, "%v: %v,\n", ch.Name, ch.ArgName) diff --git a/internal/generator/templates/app/internal/adapter/repository.go.tmpl b/internal/generator/templates/app/internal/adapter/repository.go.tmpl index 597bcea..134a07c 100644 --- a/internal/generator/templates/app/internal/adapter/repository.go.tmpl +++ b/internal/generator/templates/app/internal/adapter/repository.go.tmpl @@ -6,15 +6,25 @@ package {{$.GetPkgName}} import ( {{ $.Storage.GetConnImportName }} + {{if $.IsTransactional}} "{{ $.AppModule }}/internal/adapter/{{$.Storage.GetFolderName}}" + {{end}} ) type Repository struct { - {{$.Storage.GetFolderName}}.Transactor + {{if $.IsTransactional}} + {{$.Storage.GetFolderName}}.Transactor + {{else}} + {{$.Storage.GetConnectionName}} {{$.Storage.GetConnectionType}} + {{end}} } -func {{$.GetConstructorName}}(conn {{ $.Storage.GetConnectionType }}) *Repository { +func {{$.GetConstructorName}}({{$.Storage.GetConnectionName}} {{ $.Storage.GetConnectionType }}) *Repository { return &Repository{ - {{$.Storage.GetFolderName}}.NewTransactor(conn), + {{if $.IsTransactional}} + {{$.Storage.GetFolderName}}.NewTransactor({{$.Storage.GetConnectionName}}), + {{else}} + {{$.Storage.GetConnectionName}}: {{$.Storage.GetConnectionName}}, + {{end}} } -} \ No newline at end of file +} diff --git a/internal/generator/templates/app/internal/app/app.go.tmpl b/internal/generator/templates/app/internal/app/app.go.tmpl index 6a8402f..1152617 100644 --- a/internal/generator/templates/app/internal/app/app.go.tmpl +++ b/internal/generator/templates/app/internal/app/app.go.tmpl @@ -8,7 +8,7 @@ package app import ( "sync" "errors" - {{ renderImports "storage" "definition" .Chunks }} + {{ renderImports "storage" "definition" . }} "{{ .App.Module }}/internal/config" "go.uber.org/zap/zapcore" ) @@ -29,7 +29,7 @@ type App struct { //hc health.Checker //hcOnce *sync.Once - {{ renderDefinition "storage" .Chunks }} + {{ renderDefinition "storage" . }} logger Logger } @@ -54,10 +54,11 @@ func NewApp(configPath string) (*App, error) { //goro:init healthChecker //app.initHealthChecker() - {{ renderInitializationsWithError "storage" "app" .Chunks }} + {{ renderInitializationsWithError "storage" "app" . }} + {{ renderInitializationsWithoutError "storage" "app" . }} //goro:init dependencies - app.c = NewContainer({{range .Chunks}}{{if eq .Scope `storage`}}app.{{.Name}},{{end}}{{end}}) + app.c = NewContainer({{range .Chunks}}{{if contains .Scope "storage"}}app.{{.Name}},{{end}}{{end}}) return app, nil } @@ -72,4 +73,4 @@ func GetGlobalApp() (*App, error) { } return a, nil -} \ No newline at end of file +} diff --git a/internal/generator/templates/app/internal/app/container.go.tmpl b/internal/generator/templates/app/internal/app/container.go.tmpl index 750722d..c3ae354 100644 --- a/internal/generator/templates/app/internal/app/container.go.tmpl +++ b/internal/generator/templates/app/internal/app/container.go.tmpl @@ -6,7 +6,7 @@ package app // Editing this file might prove futile when you re-run the goro commands import ( - {{ renderImports "storage" "definition" .Chunks }} + {{ renderImports "storage" "definition" . }} "{{ $.App.Module }}/internal/usecase" @@ -24,15 +24,15 @@ import ( ) type Container struct { - {{ renderDefinition "storage" .Chunks }} + {{ renderDefinition "storage" . }} deps map[string]interface{} } -func NewContainer({{ renderArgs "storage" .Chunks }}) *Container { +func NewContainer({{ renderArgs "storage" . }}) *Container { return &Container{ - {{ renderStructPopulation "storage" .Chunks }} + {{ renderStructPopulation "storage" . }} deps: make(map[string]interface{}), } } @@ -43,7 +43,7 @@ func (c *Container) GetUseCase() *usecase.UseCase { } {{range .Chunks}} - {{if eq .Scope `storage`}} + {{if contains .Scope "storage"}} func (c *Container) get{{toCamelCase .Name}}() {{.ReturnType}} { return c.{{.Name}} } @@ -66,4 +66,4 @@ func (c *Container) GetUseCase() *usecase.UseCase { return {{$val.GetPkgName}}.{{ $val.GetConstructorName }} (c.get{{toCamelCase $val.Storage.String}}()) } {{end}} -{{end}} \ No newline at end of file +{{end}} diff --git a/internal/generator/templates/app/internal/app/database.go.tmpl b/internal/generator/templates/app/internal/app/database.go.tmpl index 9146dba..b883067 100644 --- a/internal/generator/templates/app/internal/app/database.go.tmpl +++ b/internal/generator/templates/app/internal/app/database.go.tmpl @@ -8,7 +8,7 @@ package app import ( "{{ .App.Module }}/internal/config" "fmt" - {{ renderImports "storage" "build" .Chunks }} + {{ renderImports "storage.database" "build" . }} ) -{{ renderBuild "storage" .Chunks }} \ No newline at end of file +{{ renderBuild "storage.database" . }} diff --git a/internal/generator/templates/app/internal/app/http.go.tmpl b/internal/generator/templates/app/internal/app/http.go.tmpl index c87472a..8f1699a 100644 --- a/internal/generator/templates/app/internal/app/http.go.tmpl +++ b/internal/generator/templates/app/internal/app/http.go.tmpl @@ -11,6 +11,7 @@ import ( "github.com/hanagantig/gracy" "fmt" "go.uber.org/zap" + {{ renderImports "storage.http" "build" . }} ) func (a *App) StartHTTPServer() error { @@ -51,3 +52,5 @@ func (a *App) startHTTPServer() { a.logger.Fatal("Fail to start %s http server:", zap.String("app",a.cfg.App.Name), zap.Error(err)) } } + +{{ renderBuild "storage.http" . }} diff --git a/internal/generator/templates/app/internal/service/service.go.tmpl b/internal/generator/templates/app/internal/service/service.go.tmpl index 5508644..b8541bd 100644 --- a/internal/generator/templates/app/internal/service/service.go.tmpl +++ b/internal/generator/templates/app/internal/service/service.go.tmpl @@ -1,36 +1,42 @@ // Code generated by goro; -package {{$.GetPkgName}} +package {{$.Service.GetPkgName}} // This file was generated by the goro tool. +{{if $.IsTrx}} import ( - "{{ $.AppModule }}/internal/service" + "{{ $.Service.AppModule }}/internal/service" ) +{{end}} -{{if .Deps}} - {{range $val := .Deps}} +{{if .Service.Deps}} + {{range $val := .TrxDeps}} type {{toPrivateName $val}} interface { - {{if contains $val "Repo"}} service.Transactor - {{end}} + // TODO: define interface to inject a service or an adapter + } + {{end}} + {{range $val := .NonTrxDeps}} + type {{toPrivateName $val}} interface { // TODO: define interface to inject a service or an adapter } {{end}} {{end}} + type Service struct { - {{if .Deps}} - {{range $val := .Deps}} + {{if .Service.Deps}} + {{range $val := .Service.Deps}} {{toPrivateName $val}} {{toPrivateName $val}} {{end}} {{end}} } -func {{$.GetConstructorName}}({{if .Deps}}{{range $val := .Deps}}{{toPrivateName $val}} {{toPrivateName $val}},{{end}}{{end}}) *Service { +func {{$.Service.GetConstructorName}}({{if .Service.Deps}}{{range $val := .Service.Deps}}{{toPrivateName $val}} {{toPrivateName $val}},{{end}}{{end}}) *Service { return &Service{ - {{if .Deps}} - {{range $val := .Deps}} + {{if .Service.Deps}} + {{range $val := .Service.Deps}} {{toPrivateName $val}}: {{toPrivateName $val}}, {{end}} {{end}}