podman
31 строка · 843.0 Байт
1// Copyright 2013-2022 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
5package properties
6
7import (
8"fmt"
9"math"
10)
11
12// make this a var to overwrite it in a test
13var is32Bit = ^uint(0) == math.MaxUint32
14
15// intRangeCheck checks if the value fits into the int type and
16// panics if it does not.
17func intRangeCheck(key string, v int64) int {
18if is32Bit && (v < math.MinInt32 || v > math.MaxInt32) {
19panic(fmt.Sprintf("Value %d for key %s out of range", v, key))
20}
21return int(v)
22}
23
24// uintRangeCheck checks if the value fits into the uint type and
25// panics if it does not.
26func uintRangeCheck(key string, v uint64) uint {
27if is32Bit && v > math.MaxUint32 {
28panic(fmt.Sprintf("Value %d for key %s out of range", v, key))
29}
30return uint(v)
31}
32