Documentation ¶
Overview ¶
Package revrpc provides jsonrpc library that matches ns_server's json_rpc_connection module. It allows golang service to connect to ns_server and receive jsonrpc requests via that connection.
Index ¶
- Variables
- func BabysitService(setupBody ServiceSetupCallback, svc *Service, errorPolicy BabysitErrorPolicy) error
- type BabysitErrorPolicy
- type DefaultErrorPolicy
- type ErrorPolicyFn
- type FnBabysitErrorPolicy
- type HttpError
- type RevrpcSvc
- type Service
- type ServiceSetupCallback
- type URLChange
- type URLChangeResult
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyRunning = errors.New("service is already running")
ErrAlreadyRunning is returned from Run method to indicate that given Service instance is already running.
Functions ¶
func BabysitService ¶
func BabysitService(setupBody ServiceSetupCallback, svc *Service, errorPolicy BabysitErrorPolicy) error
BabysitService function runs given service instance, restarting it as needed if allowed by given BabysitErrorPolicy. nil can be passed to errorPolicy argument, in which case value of DefaultBabysitErrorPolicy is used.
Types ¶
type BabysitErrorPolicy ¶
type BabysitErrorPolicy interface { // New method is expected to initialize and return // ErrorPolicyFn instance. That instance will be used by // BabysitService invocation until ErrorPolicyFn returns // non-nil error. New() ErrorPolicyFn }
BabysitErrorPolicy represents error handling policy.
var DefaultBabysitErrorPolicy BabysitErrorPolicy = DefaultErrorPolicy{ RestartsToExit: -1, SleepBetweenRestarts: time.Second, LogPrint: log.Print, }
DefaultBabysitErrorPolicy is BabysitErrorPolicy instance that is used by default. It's initial value is "suitably configured" DefaultErrorPolicy instance.
var NoRestartsBabysitErrorPolicy BabysitErrorPolicy = FnBabysitErrorPolicy(func(err error) error { return err })
NoRestartsBabysitErrorPolicy is error policy that always forbids restarts.
type DefaultErrorPolicy ¶
type DefaultErrorPolicy struct { // RestartsToExit determines how many restarts this error // policy will do before giving up. Negative value means // restart infinitely. RestartsToExit int // SleepBetweenRestarts specifies duration to sleep between // restarts. SleepBetweenRestarts time.Duration // LogPrint function, if non-nil, is used by // DefaultErrorPolicy to log it's events & decisions. // log.Print function is one suitable implementation. LogPrint func(args ...interface{}) // contains filtered or unexported fields }
DefaultErrorPolicy is default configurable implementation of BabysitErrorPolicy.
func (DefaultErrorPolicy) New ¶
func (p DefaultErrorPolicy) New() ErrorPolicyFn
New method of DefaultErrorPolicy implements New method of BabysitErrorPolicy interface. It returns ErrorPolicyFn that will allow configured number of restarts and will sleep configured duration between restarts.
type ErrorPolicyFn ¶
ErrorPolicyFn function is used to make error handling decision in BabysitService. Function returns nil to "eat" error and case BabysitService to restart Service. Otherwise, returned error provides return value for BabysitService invocation.
type FnBabysitErrorPolicy ¶
type FnBabysitErrorPolicy ErrorPolicyFn
FnBabysitErrorPolicy type adapts ErrorPolicyFn to BabysitErrorPolicy interface.
func (FnBabysitErrorPolicy) New ¶
func (p FnBabysitErrorPolicy) New() ErrorPolicyFn
New method simply returns "this" function.
type RevrpcSvc ¶ added in v0.1.5
type RevrpcSvc struct {
// contains filtered or unexported fields
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service type represents specific configured instance of revrpc.
func GetDefaultServiceFromEnv ¶
GetDefaultServiceFromEnv returns Service instance that connects to ns_server according to CBAUTH_REVRPC_URL environment variable. Trying to obtain same service twice will return error. I.e. you're supposed to get your Service instance once and only once and hold it forever.
func MustService ¶
MustService is like NewService except that it panics on errors. I.e. it is useful in cases where errors are not expected.
func NewService ¶
NewService creates and returns Service instance that connects to given ns_server url (which is expected to have creds encoded). Returns error if url is malformed. Does not actually connect to ns_server, so it will succeed even if ns_server is not running or if creds are not valid admin creds.
func (*Service) Disconnect ¶ added in v0.1.11
func (*Service) Run ¶
func (s *Service) Run(setupBody ServiceSetupCallback) error
Run method connects to ns_server, sets up json rpc instance and handles rpc requests loop until connection is alive. Returned error is always non-nil. In case connection was closed by ns_server io.EOF is returned.
type ServiceSetupCallback ¶
ServiceSetupCallback type defines functions that can be passed to Run and to BabysitService. Function is expected to register "rpc-exported" object instances with given rpc server.