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