diff --git a/rony/go.mod b/rony/go.mod index f6a93e65..80561419 100644 --- a/rony/go.mod +++ b/rony/go.mod @@ -6,6 +6,7 @@ require ( github.com/clubpay/ronykit/contrib v0.16.0 github.com/clubpay/ronykit/kit v0.16.0 github.com/clubpay/ronykit/std/gateways/fasthttp v0.16.0 + github.com/clubpay/ronykit/stub v0.16.0 ) require ( diff --git a/rony/go.sum b/rony/go.sum index 9ca64f68..1bb89621 100644 --- a/rony/go.sum +++ b/rony/go.sum @@ -6,6 +6,8 @@ github.com/clubpay/ronykit/kit v0.16.0 h1:89nrRSXVc0FaLNcHzShRZqtaRrk7hFjE5TVgkO github.com/clubpay/ronykit/kit v0.16.0/go.mod h1:JmRsAjBYhNsrU7iaQM9oVw5OSIQpMET+VDKx1suUPbk= github.com/clubpay/ronykit/std/gateways/fasthttp v0.16.0 h1:+hw9yPt/b2vgnAE1UaXKrvHdT23Gd0xm7rtIMJNK3Bg= github.com/clubpay/ronykit/std/gateways/fasthttp v0.16.0/go.mod h1:BdeIyy2GIYbNlz8QUr/z17+rNwMAXtxJop6AR0QZhvY= +github.com/clubpay/ronykit/stub v0.16.0 h1:elxm5/GmWevgZy77wSc61NcmlEeTiFEI1xaIQmRBnhE= +github.com/clubpay/ronykit/stub v0.16.0/go.mod h1:XS9NvlW26riWRYs1z2H8yVahQq4TtolQoZmeWP+Z9nc= 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= diff --git a/rony/setup_swagger.go b/rony/setup_swagger.go deleted file mode 100644 index 0775518c..00000000 --- a/rony/setup_swagger.go +++ /dev/null @@ -1 +0,0 @@ -package rony diff --git a/rony/stub.go b/rony/stub.go new file mode 100644 index 00000000..2117af01 --- /dev/null +++ b/rony/stub.go @@ -0,0 +1,26 @@ +package rony + +import "github.com/clubpay/ronykit/stub/stubgen" + +// GenerateStub generates a stub file for the given service description. +// The generated file will be placed in the `outputDir/folderName` directory. +// The package name of the generated file will be `pkgName`. +// The struct holding the stub functions will be named `name`. +func GenerateStub[S State[A], A Action]( + name, folderName, outputDir, pkgName string, + genFunc stubgen.GenFunc, ext string, + opt ...SetupOption[S, A], +) error { + ctx := SetupContext[S, A]{} + for _, o := range opt { + o(&ctx) + } + + return stubgen.New( + stubgen.WithStubName(name), + stubgen.WithFolderName(folderName), + stubgen.WithOutputDir(outputDir), + stubgen.WithPkgName(pkgName), + stubgen.WithGenFunc(genFunc, ext), + ).Generate(ctx.cfg.allServiceDesc()...) +} diff --git a/ronyup/internal/skeleton/rony/cmd/gen-stub/main.go.gotmpl b/ronyup/internal/skeleton/rony/cmd/gen-stub/main.go.gotmpl new file mode 100644 index 00000000..71469303 --- /dev/null +++ b/ronyup/internal/skeleton/rony/cmd/gen-stub/main.go.gotmpl @@ -0,0 +1,12 @@ +package main + +import ( + "{{.ModulePath}}/service" +) + +func main() { + err := service.GenerateStub() + if err != nil { + panic(err) + } +} diff --git a/ronyup/internal/skeleton/rony/service/setup.go.gotmpl b/ronyup/internal/skeleton/rony/service/setup.go.gotmpl index 4885ce89..73363cfd 100644 --- a/ronyup/internal/skeleton/rony/service/setup.go.gotmpl +++ b/ronyup/internal/skeleton/rony/service/setup.go.gotmpl @@ -2,6 +2,7 @@ package service import ( "github.com/clubpay/ronykit/rony" + "github.com/clubpay/ronykit/stub/stubgen" "{{ .ModulePath }}/service/endpoint" "{{ .ModulePath }}/service/state" ) @@ -27,3 +28,12 @@ func Setup() rony.SetupOption[*state.Counter, state.Action] { ), ) } + +//go:generate go run {{.ModulePath}}/cmd/gen-stub/main.go}} +func GenerateStub() error { + return rony.GenerateStub( + "CounterStub", "counter", ".", "counterc", + stubgen.GolangStub, ".go", + Setup(), + ) +}