I want to parse service-file (yaml content) into swarm.ServiceSpec (go sdk) or even SeviceSpec (http json)

I am working on a project which require me to use docker engine api, i am using go-sdk.
In which i want to create a new service (docker swarm service).

Going thought the documentation of docker-engine-api, and into the section of CreateService (Docker Engine API v1.42 Reference)

I found that inorder to create a new service we need a long-json-object called ServiceSpec.

What i have is a simple compore file (service file) which is a yaml specification. i want it to convert into that object in go-sdk so that i can create service in my app.

Later after more research, i found out that there is not straight forward way of doing it

So how can i just parse the string file data into object. That is how can i convert my yaml file (service schema) into nice go object. For this i need to represent swarm file in an object.

what is that object?

You mentioned you use the Go SDK. Have you tried to search for “service” in the sdk reference?

https://pkg.go.dev/github.com/docker/docker/client#ServiceAPIClient.ServiceCreate

What you linked was the HTTP API which you don’t need when you are using an SDK.

If you want to parse a json file, jq can help in bash or yq for Yaml files. In Go, I don’t know, but I’m sure you can find a way on Google or in the Go reference.

https://pkg.go.dev/search?q=json&m=