MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / MarshalWithOrder

Function MarshalWithOrder

agent/utils/env/env.go:60–86  ·  view source on GitHub ↗
(envMap map[string]string, orders []string)

Source from the content-addressed store, hash-verified

58}
59
60func MarshalWithOrder(envMap map[string]string, orders []string) (string, error) {
61 lines := make([]string, 0, len(envMap))
62 for _, k := range orders {
63 if v, ok := envMap[k]; ok {
64 lines = append(lines, formatEnvLine(k, v))
65 }
66 }
67
68 extraKeys := make([]string, 0)
69 for k := range envMap {
70 found := false
71 for _, okk := range orders {
72 if k == okk {
73 found = true
74 break
75 }
76 }
77 if !found {
78 extraKeys = append(extraKeys, k)
79 }
80 }
81 sort.Strings(extraKeys)
82 for _, k := range extraKeys {
83 lines = append(lines, formatEnvLine(k, envMap[k]))
84 }
85 return strings.Join(lines, "\n"), nil
86}
87
88func formatEnvLine(k, v string) string {
89 if d, err := strconv.Atoi(v); err == nil && !isStartWithZero(v) {

Callers 1

WriteWithOrderFunction · 0.85

Calls 1

formatEnvLineFunction · 0.85

Tested by

no test coverage detected