config.go 546 B

123456789101112131415161718192021222324252627282930
  1. package lengthCheck
  2. import (
  3. "fmt"
  4. "github.com/BurntSushi/toml"
  5. )
  6. type Config struct {
  7. MaxLength int `toml:"maxLength"`
  8. }
  9. func (c *Config) ConfigValidate() (error) {
  10. if c == nil {
  11. return fmt.Errorf("Error can't be nil")
  12. }
  13. if c.MaxLength == 0 || c.MaxLength > 1024*32 {
  14. c.MaxLength = 1024 * 32 //32K by default
  15. }
  16. return nil
  17. }
  18. func DecodeConfig(md toml.MetaData, primValue toml.Primitive) (c interface{}, err error) {
  19. c = new(Config)
  20. if err = md.PrimitiveDecode(primValue, c); err != nil {
  21. return nil, err
  22. }
  23. return c, nil
  24. }