go.temporal.io/server/common/number/number.go
131 LOC · 69 covered · 62 uncovered · 20 ranges · 10 concepts · 8 introducers · 5 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package number
import (
"fmt"
)
const (
TypeUnknown Type = iota
TypeFloat
TypeInt
TypeUint
)
type (
Type int
Number struct {
numberType Type
value any
}
)
func NewNumber(
value any,
var numberType Type
var number any
switch n := value.(type) {
numberType = TypeInt
number = int(n)
case int16:
numberType = TypeInt
number = int(n)
numberType = TypeInt
number = int(n)
numberType = TypeInt
number = int(n)
numberType = TypeInt
number = n
numberType = TypeUint
number = uint(n)
case uint16:
numberType = TypeUint
number = uint(n)
case uint32:
numberType = TypeUint
number = uint(n)
case uint64:
numberType = TypeUint
number = uint(n)
case uint:
numberType = TypeUint
number = n
numberType = TypeFloat
number = float64(n)
case float64:
numberType = TypeFloat
number = n
default:
// DO NOT panic here
// the value is provided during runtime
// the logic cannot just panic if input is not a number
numberType = TypeUnknown
number = nil
}
numberType: numberType,
value: number,
}
}
func (n Number) GetIntOrDefault(
defaultValue int,
switch n.numberType {
return int(n.value.(float64))
return n.value.(int)
return int(n.value.(uint))
case TypeUnknown:
return defaultValue
default:
panic(fmt.Sprintf("unknown number type: %v", n.numberType))
}
}
func (n Number) GetUintOrDefault(
defaultValue uint,
switch n.numberType {
return uint(n.value.(float64))
return uint(n.value.(int))
return n.value.(uint)
case TypeUnknown:
return defaultValue
default:
panic(fmt.Sprintf("unknown number type: %v", n.numberType))
}
}
func (n Number) GetFloatOrDefault(
defaultValue float64,
switch n.numberType {
return n.value.(float64)
return float64(n.value.(int))
return float64(n.value.(uint))
case TypeUnknown:
return defaultValue
default:
panic(fmt.Sprintf("unknown number type: %v", n.numberType))
}
}