A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
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.
 
 
 
 
 

52 lines
927 B

  1. /*
  2. * Copyright © 2018 A Bunch Tell LLC.
  3. *
  4. * This file is part of WriteFreely.
  5. *
  6. * WriteFreely is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License, included
  8. * in the LICENSE file in this source code package.
  9. */
  10. package config
  11. import (
  12. "fmt"
  13. "regexp"
  14. "strconv"
  15. )
  16. var (
  17. domainReg = regexp.MustCompile("^https?://")
  18. )
  19. const (
  20. minPort = 80
  21. maxPort = 1<<16 - 1
  22. )
  23. func validateDomain(i string) error {
  24. if !domainReg.MatchString(i) {
  25. return fmt.Errorf("Domain must start with http:// or https://")
  26. }
  27. return nil
  28. }
  29. func validatePort(i string) error {
  30. p, err := strconv.Atoi(i)
  31. if err != nil {
  32. return err
  33. }
  34. if p < minPort || p > maxPort {
  35. return fmt.Errorf("Port must be a number %d - %d", minPort, maxPort)
  36. }
  37. return nil
  38. }
  39. func validateNonEmpty(i string) error {
  40. if i == "" {
  41. return fmt.Errorf("Must not be empty")
  42. }
  43. return nil
  44. }