Documentation ¶
Index ¶
- Variables
- func Assemble(interfaceName string, packageName string, inject []string, signatures []string, ...) (err error)
- func Extract(structName string, codePath string, poolSize int) ([]string, error)
- func FindMethodsInFile(filePath string, structName string) ([]string, error)
- type Job
- type MultiError
- type WorkerPool
Constants ¶
This section is empty.
Variables ¶
var (
ErrPathIsFile = errors.New("root path is not a directory")
)
Functions ¶
func Assemble ¶
func Assemble( interfaceName string, packageName string, inject []string, signatures []string, w io.Writer, ) (err error)
Assemble takes an array of method signatures and builds an interface with the defined interfaceName and writes it to w. If a packageName is specified, the package header with the given package name is added to the output. When inject is specified, the contets will be added to the output in between the package statement and the interface injection.
func Extract ¶
Extract walks through all files recursively starting from codePath creating an index of Go source files which are no unit test files.
Then, it looks through all files line-by-line to find methods which have the given structName as receiver. This applies either to both receivers by value or by reference. Only methods which are exported are included in the result set.
The poolSize defines the number of files which can be opened and searched through simultaneously.
The resulting method signatures are then returned as an array of strings. The result set is sorted alphabetically.
Types ¶
type Job ¶
type Job func(workerId int, params ...interface{}) interface{}
Job defines a job function which will be executed in a worker getting passed the worker ID and parameters specified when pushing the job.
type MultiError ¶
type MultiError []error
MultiError is an array of errors which can be handled and one error object.
func (MultiError) Error ¶
func (t MultiError) Error() string
Error assembles a single error message out of all errors in the array.
If the array is empty, an empty string is returned.
func (MultiError) ToError ¶
func (t MultiError) ToError() error
ToError returns nil if the length of the error array is 0 and returns the array if not.
This should be called before returning the MultiError in a function to ensure that subsequent nil checks perform as expected.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool provides a simple "thread" pool implementation based on goroutines.
func NewWorkerpool ¶
func NewWorkerpool(size int) *WorkerPool
NewWorkerpool creates a new instance of WorkerPool and spawns the defined number (size) of workers available waiting for jobs.
func (*WorkerPool) Close ¶
func (w *WorkerPool) Close()
Close closes the Jobs channel so that the workers stop after executing all enqueued jobs. This is nessecary to be executed before WaitBlocking is called.
func (*WorkerPool) Push ¶
func (w *WorkerPool) Push(job Job, params ...interface{})
Push enqueues a job with specified parameters which will be passed on executing the job.
func (*WorkerPool) Results ¶
func (w *WorkerPool) Results() <-chan interface{}
Results returns the read-only results channel where executed job results are pushed in.
func (*WorkerPool) WaitBlocking ¶
func (w *WorkerPool) WaitBlocking()
WaitBlocking blocks until all jobs are finished.