Documentation ¶
Overview ¶
Package service is boilerplate code for making nexus services.
Index ¶
- type Method
- type Semaphore
- type Service
- func (s *Service) AddMethod(name string, f func(*nexus.Task) (interface{}, *nexus.JsonRpcErr))
- func (s *Service) AddMethodSchema(name string, schema string, ...)
- func (s *Service) GetConn() *nexus.NexusConn
- func (s *Service) GetMethods() []string
- func (s *Service) GetStats() *Stats
- func (s *Service) GracefulStop()
- func (s *Service) Serve() error
- func (s *Service) SetConn(nc *nexus.NexusConn)
- func (s *Service) SetGracefulExitTime(t time.Duration)
- func (s *Service) SetHandler(h func(*nexus.Task) (interface{}, *nexus.JsonRpcErr))
- func (s *Service) SetLogLevel(t string)
- func (s *Service) SetMaxThreads(maxThreads int)
- func (s *Service) SetPass(pass string)
- func (s *Service) SetPrefix(prefix string)
- func (s *Service) SetPullTimeout(t time.Duration)
- func (s *Service) SetPulls(pulls int)
- func (s *Service) SetStatsPeriod(t time.Duration)
- func (s *Service) SetUrl(url string)
- func (s *Service) SetUser(user string)
- func (s *Service) Stop()
- func (s *Service) String() string
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct { Name string Server string User string Password string Prefix string Pulls int PullTimeout time.Duration MaxThreads int StatsPeriod time.Duration GracefulExitTime time.Duration LogLevel string // contains filtered or unexported fields }
func (*Service) AddMethod ¶
AddMethod adds (or replaces if already added) a method for the service The function that receives the nexus.Task should return a result or an error
func (*Service) AddMethodSchema ¶
func (s *Service) AddMethodSchema(name string, schema string, f func(*nexus.Task) (interface{}, *nexus.JsonRpcErr))
AddSchemaMethod adds (or replaces if already added) a method for the service with a JSON schema The function that receives the nexus.Task should return a result or an error If the schema validation does not succeed, an ErrInvalidParams error will be sent as a result for the task
func (*Service) GetMethods ¶
GetMethods returns a list of the methods the service has It returns nil if using a handler
func (*Service) GracefulStop ¶
func (s *Service) GracefulStop()
GracefulStop stops pulling tasks, tries to finish working tasks and then cancels nexus connection (with a timeout)
func (*Service) SetConn ¶
SetConn sets the underlying nexus connection. Once SetConn is called, service url, user and password are ignored and the provided connection is used on serve.
func (*Service) SetGracefulExitTime ¶
SetGratefulExitTime sets the gracefull waiting time after a call to StopGraceful() is done
func (*Service) SetHandler ¶
func (s *Service) SetHandler(h func(*nexus.Task) (interface{}, *nexus.JsonRpcErr))
SetHandler sets the task handler for all methods, to allow custom parsing of the method When a handler is set, methods added with AddMethod() have no effect Passing a nil will remove the handler and turn back to methods from AddMethod()
func (*Service) SetLogLevel ¶
SetLogLevel sets the log level
func (*Service) SetMaxThreads ¶
SetMaxThreads modifies the number of maximum concurrent goroutines resolving nexus.Task
func (*Service) SetPullTimeout ¶
SetPullTimeout modifies the time to wait for a nexus.Task for each nexus.TaskPull call
func (*Service) SetStatsPeriod ¶
SetStatsPeriod changes the period for the stats to be printed