Skip to content

Commit 36a6d27

Browse files
authored
Merge pull request #23751 from dvdksn/update-go-sdk-examples
update go sdk examples
2 parents 90bbaac + 66e8d18 commit 36a6d27

File tree

3 files changed

+144
-150
lines changed

3 files changed

+144
-150
lines changed

content/manuals/engine/release-notes/29.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ For a full list of pull requests and changes in this release, refer to the relev
488488
- Go SDK: container: remove deprecated `IsValidHealthString`. [moby/moby#50378](https://github.com/moby/moby/pull/50378)
489489
- Go SDK: container: remove deprecated `IsValidStateString`. [moby/moby#50378](https://github.com/moby/moby/pull/50378)
490490
- Go SDK: container: remove deprecated `StateStatus`, `WaitCondition`, and the related `WaitConditionNotRunning`, `WaitConditionNextExit`, and `WaitConditionRemoved` consts. [moby/moby#50378](https://github.com/moby/moby/pull/50378)
491-
- Go SDK: deprecate `pkg/stdcopy`, which was moved to `api/stdcopy`. [moby/moby#50462](https://github.com/moby/moby/pull/50462)
491+
- Go SDK: deprecate `pkg/stdcopy`, which was moved to `api/pkg/stdcopy`. [moby/moby#50462](https://github.com/moby/moby/pull/50462)
492492
- Go SDK: Deprecate field `NetworkSettingsBase.Bridge`, struct `NetworkSettingsBase`, all the fields of `DefaultNetworkSettings`, and struct `DefaultNetworkSettings`. [moby/moby#50848](https://github.com/moby/moby/pull/50848)
493493
- Go SDK: deprecate pkg/stringid in favour of `github.com/moby/moby/client/pkg/stringid`. [moby/moby#50504](https://github.com/moby/moby/pull/50504)
494494
- Go SDK: deprecate profiles package which got migrated to `github.com/moby/profiles`. [moby/moby#50481](https://github.com/moby/moby/pull/50481)

content/reference/api/engine/sdk/_index.md

Lines changed: 75 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,18 @@ installed and coexist together.
2626
### Go SDK
2727

2828
```console
29-
$ go get github.com/docker/docker/client
29+
$ go get github.com/moby/moby/client
3030
```
3131

3232
The client requires a recent version of Go. Run `go version` and ensure that you're running a currently supported version of Go.
3333

34-
35-
For more information, see [Docker Engine Go SDK reference](https://godoc.org/github.com/docker/docker/client).
34+
For more information, see [Go client reference](https://pkg.go.dev/github.com/moby/moby/client).
3635

3736
### Python SDK
3837

3938
- Recommended: Run `pip install docker`.
4039

4140
- If you can't use `pip`:
42-
4341
1. [Download the package directly](https://pypi.python.org/pypi/docker/).
4442
2. Extract it and change to the extracted directory.
4543
3. Run `python setup.py install`.
@@ -84,53 +82,54 @@ import (
8482
"io"
8583
"os"
8684

87-
"github.com/docker/docker/api/types/container"
88-
"github.com/docker/docker/api/types/image"
89-
"github.com/docker/docker/client"
90-
"github.com/docker/docker/pkg/stdcopy"
85+
"github.com/moby/moby/api/pkg/stdcopy"
86+
"github.com/moby/moby/api/types/container"
87+
"github.com/moby/moby/client"
9188
)
9289

9390
func main() {
94-
ctx := context.Background()
95-
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
96-
if err != nil {
97-
panic(err)
98-
}
99-
defer cli.Close()
100-
101-
reader, err := cli.ImagePull(ctx, "docker.io/library/alpine", image.PullOptions{})
102-
if err != nil {
103-
panic(err)
104-
}
105-
io.Copy(os.Stdout, reader)
106-
107-
resp, err := cli.ContainerCreate(ctx, &container.Config{
108-
Image: "alpine",
109-
Cmd: []string{"echo", "hello world"},
110-
}, nil, nil, nil, "")
111-
if err != nil {
112-
panic(err)
113-
}
114-
115-
if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil {
116-
panic(err)
117-
}
118-
119-
statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning)
120-
select {
121-
case err := <-errCh:
122-
if err != nil {
123-
panic(err)
124-
}
125-
case <-statusCh:
126-
}
127-
128-
out, err := cli.ContainerLogs(ctx, resp.ID, container.LogsOptions{ShowStdout: true})
129-
if err != nil {
130-
panic(err)
131-
}
132-
133-
stdcopy.StdCopy(os.Stdout, os.Stderr, out)
91+
ctx := context.Background()
92+
apiClient, err := client.New(client.FromEnv)
93+
if err != nil {
94+
panic(err)
95+
}
96+
defer apiClient.Close()
97+
98+
reader, err := apiClient.ImagePull(ctx, "docker.io/library/alpine", client.ImagePullOptions{})
99+
if err != nil {
100+
panic(err)
101+
}
102+
io.Copy(os.Stdout, reader)
103+
104+
resp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{
105+
Image: "alpine",
106+
Config: &container.Config{
107+
Cmd: []string{"echo", "hello world"},
108+
},
109+
})
110+
if err != nil {
111+
panic(err)
112+
}
113+
114+
if _, err := apiClient.ContainerStart(ctx, resp.ID, client.ContainerStartOptions{}); err != nil {
115+
panic(err)
116+
}
117+
118+
wait := apiClient.ContainerWait(ctx, resp.ID, client.ContainerWaitOptions{})
119+
select {
120+
case err := <-wait.Error:
121+
if err != nil {
122+
panic(err)
123+
}
124+
case <-wait.Result:
125+
}
126+
127+
out, err := apiClient.ContainerLogs(ctx, resp.ID, client.ContainerLogsOptions{ShowStdout: true})
128+
if err != nil {
129+
panic(err)
130+
}
131+
132+
stdcopy.StdCopy(os.Stdout, os.Stderr, out)
134133
}
135134
```
136135

@@ -184,31 +183,31 @@ There are a number of community supported libraries available for other
184183
languages. They haven't been tested by Docker, so if you run into any issues,
185184
file them with the library maintainers.
186185

187-
| Language | Library |
188-
|:----------------------|:----------------------------------------------------------------------------|
189-
| C | [libdocker](https://github.com/danielsuo/libdocker) |
190-
| C# | [Docker.DotNet](https://github.com/ahmetalpbalkan/Docker.DotNet) |
191-
| C++ | [lasote/docker_client](https://github.com/lasote/docker_client) |
192-
| Clojure | [clj-docker-client](https://github.com/into-docker/clj-docker-client) |
193-
| Clojure | [contajners](https://github.com/lispyclouds/contajners) |
194-
| Dart | [bwu_docker](https://github.com/bwu-dart/bwu_docker) |
195-
| Erlang | [erldocker](https://github.com/proger/erldocker) |
196-
| Gradle | [gradle-docker-plugin](https://github.com/gesellix/gradle-docker-plugin) |
197-
| Groovy | [docker-client](https://github.com/gesellix/docker-client) |
198-
| Haskell | [docker-hs](https://github.com/denibertovic/docker-hs) |
199-
| Java | [docker-client](https://github.com/spotify/docker-client) |
200-
| Java | [docker-java](https://github.com/docker-java/docker-java) |
201-
| Java | [docker-java-api](https://github.com/amihaiemil/docker-java-api) |
202-
| Java | [jocker](https://github.com/ndeloof/jocker) |
203-
| NodeJS | [dockerode](https://github.com/apocas/dockerode) |
204-
| NodeJS | [harbor-master](https://github.com/arhea/harbor-master) |
205-
| NodeJS | [the-moby-effect](https://github.com/leonitousconforti/the-moby-effect) |
206-
| Perl | [Eixo::Docker](https://github.com/alambike/eixo-docker) |
207-
| PHP | [Docker-PHP](https://github.com/docker-php/docker-php) |
208-
| Ruby | [docker-api](https://github.com/swipely/docker-api) |
209-
| Rust | [bollard](https://github.com/fussybeaver/bollard) |
210-
| Rust | [docker-rust](https://github.com/abh1nav/docker-rust) |
211-
| Rust | [shiplift](https://github.com/softprops/shiplift) |
212-
| Scala | [tugboat](https://github.com/softprops/tugboat) |
213-
| Scala | [reactive-docker](https://github.com/almoehi/reactive-docker) |
214-
| Swift | [docker-client-swift](https://github.com/valeriomazzeo/docker-client-swift) |
186+
| Language | Library |
187+
| :------- | :-------------------------------------------------------------------------- |
188+
| C | [libdocker](https://github.com/danielsuo/libdocker) |
189+
| C# | [Docker.DotNet](https://github.com/ahmetalpbalkan/Docker.DotNet) |
190+
| C++ | [lasote/docker_client](https://github.com/lasote/docker_client) |
191+
| Clojure | [clj-docker-client](https://github.com/into-docker/clj-docker-client) |
192+
| Clojure | [contajners](https://github.com/lispyclouds/contajners) |
193+
| Dart | [bwu_docker](https://github.com/bwu-dart/bwu_docker) |
194+
| Erlang | [erldocker](https://github.com/proger/erldocker) |
195+
| Gradle | [gradle-docker-plugin](https://github.com/gesellix/gradle-docker-plugin) |
196+
| Groovy | [docker-client](https://github.com/gesellix/docker-client) |
197+
| Haskell | [docker-hs](https://github.com/denibertovic/docker-hs) |
198+
| Java | [docker-client](https://github.com/spotify/docker-client) |
199+
| Java | [docker-java](https://github.com/docker-java/docker-java) |
200+
| Java | [docker-java-api](https://github.com/amihaiemil/docker-java-api) |
201+
| Java | [jocker](https://github.com/ndeloof/jocker) |
202+
| NodeJS | [dockerode](https://github.com/apocas/dockerode) |
203+
| NodeJS | [harbor-master](https://github.com/arhea/harbor-master) |
204+
| NodeJS | [the-moby-effect](https://github.com/leonitousconforti/the-moby-effect) |
205+
| Perl | [Eixo::Docker](https://github.com/alambike/eixo-docker) |
206+
| PHP | [Docker-PHP](https://github.com/docker-php/docker-php) |
207+
| Ruby | [docker-api](https://github.com/swipely/docker-api) |
208+
| Rust | [bollard](https://github.com/fussybeaver/bollard) |
209+
| Rust | [docker-rust](https://github.com/abh1nav/docker-rust) |
210+
| Rust | [shiplift](https://github.com/softprops/shiplift) |
211+
| Scala | [tugboat](https://github.com/softprops/tugboat) |
212+
| Scala | [reactive-docker](https://github.com/almoehi/reactive-docker) |
213+
| Swift | [docker-client-swift](https://github.com/valeriomazzeo/docker-client-swift) |

0 commit comments

Comments
 (0)