@@ -18,10 +18,6 @@ import (
1818 "time"
1919
2020 "dario.cat/mergo"
21- "github.com/labstack/echo/v4"
22- "github.com/labstack/echo/v4/middleware"
23- "gopkg.in/yaml.v3"
24-
2521 "github.com/docker/cagent/pkg/api"
2622 "github.com/docker/cagent/pkg/config"
2723 latest "github.com/docker/cagent/pkg/config/v2"
@@ -35,6 +31,9 @@ import (
3531 "github.com/docker/cagent/pkg/session"
3632 "github.com/docker/cagent/pkg/team"
3733 "github.com/docker/cagent/pkg/teamloader"
34+ "github.com/goccy/go-yaml"
35+ "github.com/labstack/echo/v4"
36+ "github.com/labstack/echo/v4/middleware"
3837)
3938
4039type Server struct {
@@ -218,16 +217,11 @@ func (s *Server) editAgentConfig(c echo.Context) error {
218217 }
219218
220219 // Marshal the merged configuration to YAML
221- var buf bytes.Buffer
222- encoder := yaml .NewEncoder (& buf )
223- encoder .SetIndent (2 )
224- err = encoder .Encode (mergedConfig )
220+ yamlData , err := yaml .MarshalWithOptions (mergedConfig , yaml .Indent (2 ))
225221 if err != nil {
226222 slog .Error ("Failed to marshal merged config to YAML" , "error" , err )
227223 return c .JSON (http .StatusInternalServerError , map [string ]string {"error" : "failed to generate merged YAML configuration" })
228224 }
229- encoder .Close ()
230- yamlData := buf .Bytes ()
231225
232226 // Combine shebang, version, and merged YAML content
233227 finalContent := shebang + versionLine
@@ -346,16 +340,11 @@ func (s *Server) createAgentConfig(c echo.Context) error {
346340 }
347341
348342 // Marshal to YAML with custom indentation (2 spaces)
349- var buf bytes.Buffer
350- encoder := yaml .NewEncoder (& buf )
351- encoder .SetIndent (1 )
352- err := encoder .Encode (agentConfig )
343+ yamlData , err := yaml .MarshalWithOptions (agentConfig , yaml .Indent (2 ))
353344 if err != nil {
354345 slog .Error ("Failed to marshal agent config to YAML" , "error" , err )
355346 return c .JSON (http .StatusInternalServerError , map [string ]string {"error" : "failed to generate YAML configuration" })
356347 }
357- encoder .Close ()
358- yamlData := buf .Bytes ()
359348
360349 // Prepend shebang line to the YAML content
361350 shebang := "#!/usr/bin/env cagent run\n version: \" 1\" \n \n "
0 commit comments