Skip to content

Commit

Permalink
all: Use strings.Cut
Browse files Browse the repository at this point in the history
Updates #9687
  • Loading branch information
bep committed Mar 21, 2022
1 parent 5adb81c commit 0e305d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions config/env.go
Expand Up @@ -41,8 +41,8 @@ func SetEnvVars(oldVars *[]string, keyValues ...string) {
}

func SplitEnvVar(v string) (string, string) {
parts := strings.SplitN(v, "=", 2)
return parts[0], parts[1]
name, value, _ := strings.Cut(v, "=")
return name, value
}

func setEnvVar(vars *[]string, key, value string) {
Expand Down
7 changes: 2 additions & 5 deletions modules/config.go
Expand Up @@ -402,11 +402,8 @@ func (m Mount) Component() string {
}

func (m Mount) ComponentAndName() (string, string) {
k := strings.Index(m.Target, fileSeparator)
if k == -1 {
return m.Target, ""
}
return m.Target[:k], m.Target[k+1:]
c, n, _ := strings.Cut(m.Target, fileSeparator)
return c, n
}

func getStaticDirs(cfg config.Provider) []string {
Expand Down
9 changes: 4 additions & 5 deletions tpl/collections/apply.go
Expand Up @@ -107,15 +107,14 @@ func applyFnToThis(ctx context.Context, fn, this reflect.Value, args ...any) (re
}

func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
if !strings.ContainsRune(fname, '.') {
namespace, methodName, ok := strings.Cut(fname, ".")
if !ok {
templ := ns.deps.Tmpl().(tpl.TemplateFuncGetter)
return templ.GetFunc(fname)
}

ss := strings.SplitN(fname, ".", 2)

// Namespace
nv, found := ns.lookupFunc(ss[0])
nv, found := ns.lookupFunc(namespace)
if !found {
return reflect.Value{}, false
}
Expand All @@ -131,7 +130,7 @@ func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
nv = reflect.ValueOf(v)

// method
m := hreflect.GetMethodByName(nv, ss[1])
m := hreflect.GetMethodByName(nv, methodName)

if m.Kind() == reflect.Invalid {
return reflect.Value{}, false
Expand Down

0 comments on commit 0e305d6

Please sign in to comment.