示例#1
0
func LoadConfig(fileName string, config interface{}) error {
	file, err := os.Open(fileName)
	if err != nil {
		return errors.New(err)
	}

	decoder := json.NewDecoder(file)
	err = decoder.Decode(config)
	if err != nil {
		return errors.New(err)
	}

	return nil
}
示例#2
0
文件: pool.go 项目: lrsec/gpool
func NewGPool(minSize, maxSize, maxIdleSize int64,
	maxIdleTime, monitorPeriod time.Duration,
	inputChannel, outputChannel chan interface{},
	name string,
	handler func(interface{}, chan interface{}) error,
) (*GPool, error) {

	if minSize < 0 || maxSize < 0 || maxIdleSize < 0 || handler == nil {
		return nil, errors.New(fmt.Sprintf("Illegal parameters to create goroutine pool. minSize: %v, maxSize: %v, maxIdleSize: %v, handler: %v.", minSize, maxSize, maxIdleSize, handler))
	}

	gpool := &GPool{
		minSize:     minSize,
		maxSize:     maxSize,
		maxIdleSize: maxIdleSize,
		maxIdleTime: maxIdleTime,

		monitorPeriod: monitorPeriod,

		poolSize:  0,
		watermark: minSize / 2,

		InputChannel:  inputChannel,
		OutputChannel: outputChannel,

		Name: name,

		handler: handler,
	}

	gpool.isClosed.Store(false)

	return gpool, nil
}