mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.
Remove these imports in preparation of migrating our code to become an
actual go module.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
timetypes "github.com/docker/docker/api/types/time"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// ServiceLogs returns the logs generated by a service in an io.ReadCloser.
|
|
// It's up to the caller to close the stream.
|
|
func (cli *Client) ServiceLogs(ctx context.Context, serviceID string, options container.LogsOptions) (io.ReadCloser, error) {
|
|
serviceID, err := trimID("service", serviceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
query := url.Values{}
|
|
if options.ShowStdout {
|
|
query.Set("stdout", "1")
|
|
}
|
|
|
|
if options.ShowStderr {
|
|
query.Set("stderr", "1")
|
|
}
|
|
|
|
if options.Since != "" {
|
|
ts, err := timetypes.GetTimestamp(options.Since, time.Now())
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, `invalid value for "since"`)
|
|
}
|
|
query.Set("since", ts)
|
|
}
|
|
|
|
if options.Timestamps {
|
|
query.Set("timestamps", "1")
|
|
}
|
|
|
|
if options.Details {
|
|
query.Set("details", "1")
|
|
}
|
|
|
|
if options.Follow {
|
|
query.Set("follow", "1")
|
|
}
|
|
query.Set("tail", options.Tail)
|
|
|
|
resp, err := cli.get(ctx, "/services/"+serviceID+"/logs", query, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resp.Body, nil
|
|
}
|