port.go 433 B

123456789101112131415161718192021222324252627282930
  1. package host
  2. import (
  3. "git.giaever.org/joachimmg/go-log.git/log"
  4. "git.giaever.org/joachimmg/m-dns/errors"
  5. )
  6. type HostPort interface {
  7. Int() int
  8. Uint16() uint16
  9. }
  10. type Port int
  11. func (p Port) Int() int {
  12. return int(p)
  13. }
  14. func (p Port) Uint16() uint16 {
  15. return uint16(p)
  16. }
  17. func (p Port) isValid() error {
  18. log.Traceln(errors.HostPort, p)
  19. if int(p) < 0 || int(p) > 65535 {
  20. return errors.HostPortIsInvalid
  21. }
  22. return nil
  23. }