service

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 4 Imported by: 69

README

GitHub Test Status GoDoc License Go Report CodeFactor Maintainability Codecov

Simple Service

Licensing License

This program is free software: you can redistribute it and/or modify it under the terms of the Apache license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseService

type BaseService struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BaseService provides common mechanisms to all services implementing the Service interface.

func NewBaseService

func NewBaseService(srv Service, name string) *BaseService

NewBaseService returns an initialized BaseService object.

func (*BaseService) CheckRateLimit

func (bas *BaseService) CheckRateLimit()

CheckRateLimit implements the Service interface.

func (*BaseService) Description

func (bas *BaseService) Description() string

Description implements the Service interface.

func (*BaseService) Done

func (bas *BaseService) Done() <-chan struct{}

Done implements the Service interface.

func (*BaseService) HandlesReq added in v0.3.0

func (bas *BaseService) HandlesReq(req interface{}) bool

HandlesReq implements the Service interface.

func (*BaseService) Input added in v0.2.0

func (bas *BaseService) Input() chan interface{}

Input implements the Service interface.

func (*BaseService) OnStart

func (bas *BaseService) OnStart() error

OnStart implements the Service interface.

func (*BaseService) OnStop

func (bas *BaseService) OnStop() error

OnStop implements the Service interface.

func (*BaseService) Output added in v0.2.0

func (bas *BaseService) Output() chan interface{}

Output implements the Service interface.

func (*BaseService) SetRateLimit

func (bas *BaseService) SetRateLimit(persec int)

SetRateLimit implements the Service interface.

func (*BaseService) Start

func (bas *BaseService) Start() error

Start implements the Service interface.

func (*BaseService) Stop

func (bas *BaseService) Stop() error

Stop implements the Service interface.

func (*BaseService) String

func (bas *BaseService) String() string

String implements the Stringer interface.

type Service

type Service interface {
	fmt.Stringer

	// Description returns a greeting message from the service.
	Description() string

	// Start requests that the service be started.
	Start() error

	// OnStart is called when the Start method requests the service be started.
	OnStart() error

	// Stop requests that the service be stopped.
	Stop() error

	// OnStop is called when the Stop method requests the service be stopped.
	OnStop() error

	// Done returns a channel that is closed when the service is stopped.
	Done() <-chan struct{}

	// Input returns a channel that the service receives requests on.
	Input() chan interface{}

	// HandlesReq returns true when the provided request is processed by the service.
	HandlesReq(req interface{}) bool

	// Output returns a channel that the service send results on.
	Output() chan interface{}

	// SetRateLimit sets the number of calls to the OnRequest method each second.
	SetRateLimit(persec int)

	// CheckRateLimit blocks until the minimum wait duration since the last call.
	CheckRateLimit()
}

Service handles queued requests at an optional rate limit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL