http urls monitor.

rangecheck.go 838B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2018 Frank Schroeder. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package properties
  5. import (
  6. "fmt"
  7. "math"
  8. )
  9. // make this a var to overwrite it in a test
  10. var is32Bit = ^uint(0) == math.MaxUint32
  11. // intRangeCheck checks if the value fits into the int type and
  12. // panics if it does not.
  13. func intRangeCheck(key string, v int64) int {
  14. if is32Bit && (v < math.MinInt32 || v > math.MaxInt32) {
  15. panic(fmt.Sprintf("Value %d for key %s out of range", v, key))
  16. }
  17. return int(v)
  18. }
  19. // uintRangeCheck checks if the value fits into the uint type and
  20. // panics if it does not.
  21. func uintRangeCheck(key string, v uint64) uint {
  22. if is32Bit && v > math.MaxUint32 {
  23. panic(fmt.Sprintf("Value %d for key %s out of range", v, key))
  24. }
  25. return uint(v)
  26. }