AFAIRE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
scheduler/config.go

48 lines
1.1 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### scheduler ####### Copyright (c) 2021-2022 losyme ########################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package scheduler
import "errors"
type OnMessage func(*Message)
type Config struct {
OnMessage OnMessage
Logger Logger
}
type Option func(*Config)
func WithLogger(logger Logger) Option {
return func(c *Config) {
c.Logger = logger
}
}
func NewConfig(onMessage OnMessage, options ...Option) *Config {
c := &Config{
OnMessage: onMessage,
}
for _, option := range options {
option(c)
}
return c
}
func (c *Config) validate() error {
if c.OnMessage == nil {
return errors.New("config field 'OnMessage' cannot be nil") ////////////////////////////////////////////////////
}
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/