Add INSTANCE_ID env port offset
This commit is contained in:
17
src/util.go
17
src/util.go
@@ -6,7 +6,9 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -124,6 +126,21 @@ func ParseAddress(address string, defaultPort uint16) (string, uint16, error) {
|
||||
return result[0], uint16(port), nil
|
||||
}
|
||||
|
||||
// GetInstanceID returns the INSTANCE_ID environment variable parsed as an unsigned 16-bit integer.
|
||||
func GetInstanceID() (uint16, error) {
|
||||
if instanceID := os.Getenv("INSTANCE_ID"); len(instanceID) > 0 {
|
||||
value, err := strconv.ParseUint(instanceID, 10, 16)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return uint16(value), nil
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// PointerOf returns a pointer of the argument passed.
|
||||
func PointerOf[T any](v T) *T {
|
||||
return &v
|
||||
|
||||
Reference in New Issue
Block a user