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 }