Skip to content

Commit

Permalink
use replaceall instead of replace -1
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervcp committed Apr 11, 2024
1 parent e35a943 commit db74fe4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,18 @@ func (s *Server) Context() context.Context {
// We can use this to set the container command with all variables replaced.
func parseInvocation(invocation string, envvars map[string]interface{}, memory int64, port int, ip string) (parsed string) {
// replace "{{" and "}}" with "${" and "}" respectively
invocation = strings.Replace(invocation, "{{", "${", -1)
invocation = strings.Replace(invocation, "}}", "}", -1)
invocation = strings.ReplaceAll(invocation, "{{", "${")
invocation = strings.ReplaceAll(invocation, "}}", "}")

// replaces ${varname} with varval
for varname, varval := range envvars {
invocation = strings.Replace(invocation, fmt.Sprintf("${%s}", varname), fmt.Sprint(varval), -1)
invocation = strings.ReplaceAll(invocation, fmt.Sprintf("${%s}", varname), fmt.Sprint(varval))
}

// replace the defaults with their configured values.
invocation = strings.Replace(invocation, "${SERVER_PORT}", strconv.Itoa(port), -1)
invocation = strings.Replace(invocation, "${SERVER_MEMORY}", strconv.Itoa(int(memory)), -1)
invocation = strings.Replace(invocation, "${SERVER_IP}", ip, -1)
invocation = strings.ReplaceAll(invocation, "${SERVER_PORT}", strconv.Itoa(port))
invocation = strings.ReplaceAll(invocation, "${SERVER_MEMORY}", strconv.Itoa(int(memory)))
invocation = strings.ReplaceAll(invocation, "${SERVER_IP}", ip)

return invocation
}
Expand Down

0 comments on commit db74fe4

Please sign in to comment.