docker / engine-api

DEPRECATED: Please see https://github.com/docker/docker/tree/master/client
Apache License 2.0
264 stars 163 forks source link

ContainerLogs with default ContainerLogsOption #345

Open htfy96 opened 8 years ago

htfy96 commented 8 years ago

I copied

func ExampleClient_ContainerLogs_withTimeout() {
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()

    client, _ := NewEnvClient()
    reader, err := client.ContainerLogs(ctx, "container_id", types.ContainerLogsOptions{})
    if err != nil {
        log.Fatal(err)
    }

    _, err = io.Copy(os.Stdout, reader)
    if err != nil && err != io.EOF {
        log.Fatal(err)
    }
}

from the example at container_logs_test.go, but the server raised an error Error response from daemon: Bad parameters: you must choose at least one stream.

Then I changed types.ContainerLogsOptions{} with types.ContainerLogsOptions{ShowStdout: true} and everything worked well.

So I was wondering whether this example could be misleading for beginners, or is there anything that I didn't notice?

zsluedem commented 6 years ago

as the error said, you have to choose one stream either stdout or stderr. If you don't input any of these option to be true, it would panic.