This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/cmd/server/jsonrpc/service.go

35 lines
852 B
Go
Raw Normal View History

2018-12-06 22:12:32 +01:00
package jsonrpc
import (
"forge.cadoles.com/wpetit/goweb/service"
"github.com/gorilla/rpc"
"github.com/pkg/errors"
)
const ServiceName service.Name = "jsonrpc"
// From retrieves the JSONRPC service in the given container or panic
func From(container *service.Container) (*rpc.Server, error) {
service, err := container.Service(ServiceName)
if err != nil {
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
}
jsonRPCService, ok := service.(*rpc.Server)
if !ok {
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
}
return jsonRPCService, nil
}
// Must retrieves the json-rpc service in the given container or panic otherwise
func Must(container *service.Container) *rpc.Server {
service, err := From(container)
if err != nil {
panic(err)
}
return service
}