Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannm committed Jun 12, 2022
1 parent ae3a74a commit 0afe93d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
4 changes: 4 additions & 0 deletions desc/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/clubpay/ronykit/utils/reflector"
)

type Desc interface {
Desc() *Service
}

type Error struct {
Code int
Item string
Expand Down
11 changes: 11 additions & 0 deletions desc/edge_option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package desc

import "github.com/clubpay/ronykit"

func Register(descriptions ...Desc) ronykit.Option {
return func(s *ronykit.EdgeServer) {
for _, d := range descriptions {
s.RegisterService(d.Desc().Generate())
}
}
}
5 changes: 3 additions & 2 deletions edge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var _ = Describe("EdgeServer", func() {
}
edge = ronykit.NewServer(
ronykit.RegisterBundle(b),
ronykit.RegisterServiceDesc(
ronykit.RegisterService(
desc.NewService("testService").
AddContract(
desc.NewContract().
Expand All @@ -94,7 +94,8 @@ var _ = Describe("EdgeServer", func() {
return
},
),
),
).
Generate(),
),
)
edge.Start(nil)
Expand Down
3 changes: 2 additions & 1 deletion exmples/mixed-jsonrpc-rest/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"runtime"

"github.com/clubpay/ronykit"
"github.com/clubpay/ronykit/desc"
"github.com/clubpay/ronykit/std/gateway/fasthttp"
"github.com/clubpay/ronykit/std/gateway/fastws"
)
Expand Down Expand Up @@ -37,7 +38,7 @@ func main() {
fasthttp.Listen(":81"),
),
),
ronykit.RegisterServiceDesc(NewSample().Desc()),
desc.Register(NewSample()),
).
Start(nil).
PrintRoutes(os.Stdout).
Expand Down
5 changes: 2 additions & 3 deletions exmples/simple-rest-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"syscall"

"github.com/clubpay/ronykit"
"github.com/clubpay/ronykit/desc"
"github.com/clubpay/ronykit/exmples/simple-rest-server/api"
"github.com/clubpay/ronykit/std/gateway/fasthttp"
)
Expand All @@ -35,9 +36,7 @@ func main() {
fasthttp.WithReflectTag("json"),
),
),
ronykit.RegisterServiceDesc(
api.NewSample().Desc(),
),
desc.Register(api.NewSample()),
).
Start(nil).
PrintRoutes(os.Stdout).
Expand Down
10 changes: 0 additions & 10 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ func RegisterService(services ...Service) Option {
}
}

// RegisterServiceDesc registers a service by accepting the desc.Service as input.
// **Note**: we are using ServiceGenerator interface instead of desc.Service to prevent cyclic dependencies.
func RegisterServiceDesc(serviceGens ...ServiceGenerator) Option {
return func(s *EdgeServer) {
for _, svcGen := range serviceGens {
s.RegisterService(svcGen.Generate())
}
}
}

func WithErrorHandler(h ErrHandler) Option {
return func(s *EdgeServer) {
s.eh = h
Expand Down
5 changes: 0 additions & 5 deletions service.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package ronykit

// ServiceGenerator generates a service. desc.Service is the implementor of this.
type ServiceGenerator interface {
Generate() Service
}

// Service defines a set of RPC handlers which usually they are related to one service.
// Name must be unique per each Gateway.
type Service interface {
Expand Down

0 comments on commit 0afe93d

Please sign in to comment.