MCPcopy Create free account
hub / github.com/52funny/pikpakcli / buildConfig

Function buildConfig

cli/setup/setup.go:148–171  ·  view source on GitHub ↗
(values setupValues)

Source from the content-addressed store, hash-verified

146}
147
148func buildConfig(values setupValues) ([]byte, error) {
149 if len(configTemplate) == 0 {
150 return nil, fmt.Errorf("embedded config template is empty")
151 }
152
153 var node yaml.Node
154 if err := yaml.Unmarshal(configTemplate, &node); err != nil {
155 return nil, fmt.Errorf("parse embedded config template: %w", err)
156 }
157 if values.Proxy != "" {
158 setMappingValue(&node, []string{"proxy"}, values.Proxy)
159 }
160 setMappingValue(&node, []string{"username"}, values.Username)
161 setMappingValue(&node, []string{"password"}, values.Password)
162 if values.DownloadDir != "" {
163 setMappingValue(&node, []string{"open", "download_dir"}, values.DownloadDir)
164 }
165
166 out, err := yaml.Marshal(&node)
167 if err != nil {
168 return nil, fmt.Errorf("encode config: %w", err)
169 }
170 return out, nil
171}
172
173func setMappingValue(node *yaml.Node, path []string, value string) bool {
174 if node.Kind == yaml.DocumentNode && len(node.Content) > 0 {

Callers 1

RunFunction · 0.85

Calls 1

setMappingValueFunction · 0.85

Tested by

no test coverage detected