Skip to content

Commit

Permalink
fix: make compiled regex expressions global
Browse files Browse the repository at this point in the history
  • Loading branch information
raman2805 committed Apr 4, 2023
1 parent 507c141 commit 33e1356
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions config/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"strings"
)

var (
regexGwHa = regexp.MustCompile(`^.*-gw-ha-\d+-\w+-\w+$`)
regexGwNonHaOrProcessor = regexp.MustCompile(`^.*-\d+$`)
)

// GetWorkspaceToken returns the workspace token provided in the environment variables
// Env variable CONFIG_BACKEND_TOKEN is deprecating soon
// WORKSPACE_TOKEN is newly introduced. This will override CONFIG_BACKEND_TOKEN
Expand Down Expand Up @@ -35,8 +40,6 @@ func GetInstanceID() string {
instance := GetString("INSTANCE_ID", "")
instanceArr := strings.Split(instance, "-")
length := len(instanceArr)
regexGwHa := regexp.MustCompile(`^.*-gw-ha-\d+-\w+-\w+$`)
regexGwNonHaOrProcessor := regexp.MustCompile(`^.*-\d+$`)
// This handles 2 kinds of server instances
// a) Processor OR Gateway running in non HA mod where the instance name ends with the index
// b) Gateway running in HA mode, where the instance name is of the form *-gw-ha-<index>-<statefulset-id>-<pod-id>
Expand Down

0 comments on commit 33e1356

Please sign in to comment.