chore(optim): Optimizing some piece of code
Simply use modern methods
This commit is contained in:
@@ -6,8 +6,10 @@ import (
|
||||
"katenary/generator/labels/labelStructs"
|
||||
"katenary/utils"
|
||||
"log"
|
||||
"maps"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
@@ -136,9 +138,7 @@ func (chart *HelmChart) generateConfigMapsAndSecrets(project *types.Project) err
|
||||
secretsVar := types.MappingWithEquals{}
|
||||
|
||||
// copy env to originalEnv
|
||||
for k, v := range s.Environment {
|
||||
originalEnv[k] = v
|
||||
}
|
||||
maps.Copy(originalEnv, s.Environment)
|
||||
|
||||
if v, ok := s.Labels[labels.LabelSecrets]; ok {
|
||||
list, err := labelStructs.SecretsFrom(v)
|
||||
@@ -385,11 +385,8 @@ func (chart *HelmChart) setEnvironmentValuesFrom(service types.ServiceConfig, de
|
||||
isSecret := false
|
||||
secrets, err := labelStructs.SecretsFrom(dep.service.Labels[labels.LabelSecrets])
|
||||
if err == nil {
|
||||
for _, secret := range secrets {
|
||||
if secret == depName[1] {
|
||||
isSecret = true
|
||||
break
|
||||
}
|
||||
if slices.Contains(secrets, depName[1]) {
|
||||
isSecret = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -319,7 +319,7 @@ func computeNIndent(b []byte) []byte {
|
||||
startSpaces = spaces[0]
|
||||
}
|
||||
line = []byte(startSpaces + strings.TrimLeft(string(line), " "))
|
||||
line = bytes.ReplaceAll(line, []byte("__indent__"), []byte(fmt.Sprintf("%d", len(startSpaces))))
|
||||
line = bytes.ReplaceAll(line, []byte("__indent__"), fmt.Appendf(nil, "%d", len(startSpaces)))
|
||||
lines[i] = line
|
||||
}
|
||||
return bytes.Join(lines, []byte("\n"))
|
||||
|
@@ -53,8 +53,8 @@ func fixPorts(service *types.ServiceConfig) error {
|
||||
ports, err := labelStructs.PortsFrom(portsLabel)
|
||||
if err != nil {
|
||||
// maybe it's a string, comma separated
|
||||
parts := strings.Split(portsLabel, ",")
|
||||
for _, part := range parts {
|
||||
parts := strings.SplitSeq(portsLabel, ",")
|
||||
for part := range parts {
|
||||
part = strings.TrimSpace(part)
|
||||
if part == "" {
|
||||
continue
|
||||
|
Reference in New Issue
Block a user