Files
nomad/api/utils.go
Tim Gross 10dd738a03 jobspec: update gateway.ingress.service Consul API fields (#20176)
Add support for further configuring `gateway.ingress.service` blocks to bring
this block up-to-date with currently available Consul API fields (except for
namespace and admin partition, which will need be handled under a different
PR). These fields are sent to Consul as part of the job endpoint submission hook
for Connect gateways.

Co-authored-by: Horacio Monsalvo <horacio.monsalvo@southworks.com>
2024-03-22 13:50:48 -04:00

45 lines
802 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package api
import (
"strconv"
"strings"
)
// formatFloat converts the floating-point number f to a string,
// after rounding it to the passed unit.
//
// Uses 'f' format (-ddd.dddddd, no exponent), and uses at most
// maxPrec digits after the decimal point.
func formatFloat(f float64, maxPrec int) string {
v := strconv.FormatFloat(f, 'f', -1, 64)
idx := strings.LastIndex(v, ".")
if idx == -1 {
return v
}
sublen := idx + maxPrec + 1
if sublen > len(v) {
sublen = len(v)
}
return v[:sublen]
}
// pointerOf returns a pointer to a.
func pointerOf[A any](a A) *A {
return &a
}
// pointerCopy returns a new pointer to a.
func pointerCopy[A any](a *A) *A {
if a == nil {
return nil
}
na := *a
return &na
}