本文整理汇总了Golang中github.com/docker/engine-api/types/filters.ToParam函数的典型用法代码示例。如果您正苦于以下问题:Golang ToParam函数的具体用法?Golang ToParam怎么用?Golang ToParam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ToParam函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ImageSearch
// ImageSearch makes the docker host to search by a term in a remote registry.
// The list of results is not sorted in any fashion.
func (cli *Client) ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error) {
var results []registry.SearchResult
query := url.Values{}
query.Set("term", term)
if options.Filters.Len() > 0 {
filterJSON, err := filters.ToParam(options.Filters)
if err != nil {
return results, err
}
query.Set("filters", filterJSON)
}
resp, err := cli.tryImageSearch(ctx, query, options.RegistryAuth)
if resp.statusCode == http.StatusUnauthorized && options.PrivilegeFunc != nil {
newAuthHeader, privilegeErr := options.PrivilegeFunc()
if privilegeErr != nil {
return results, privilegeErr
}
resp, err = cli.tryImageSearch(ctx, query, newAuthHeader)
}
if err != nil {
return results, err
}
err = json.NewDecoder(resp.body).Decode(&results)
ensureReaderClosed(resp)
return results, err
}
开发者ID:RAMESHBABUK,项目名称:docker,代码行数:31,代码来源:image_search.go
示例2: String
func (o *FilterOpt) String() string {
repr, err := filters.ToParam(o.filter)
if err != nil {
return "invalid filters"
}
return repr
}
开发者ID:CNDonny,项目名称:scope,代码行数:7,代码来源:opts.go
示例3: Events
// Events returns a stream of events in the daemon in a ReadCloser.
// It's up to the caller to close the stream.
func (cli *Client) Events(ctx context.Context, options types.EventsOptions) (io.ReadCloser, error) {
query := url.Values{}
ref := time.Now()
if options.Since != "" {
ts, err := timetypes.GetTimestamp(options.Since, ref)
if err != nil {
return nil, err
}
query.Set("since", ts)
}
if options.Until != "" {
ts, err := timetypes.GetTimestamp(options.Until, ref)
if err != nil {
return nil, err
}
query.Set("until", ts)
}
if options.Filters.Len() > 0 {
filterJSON, err := filters.ToParam(options.Filters)
if err != nil {
return nil, err
}
query.Set("filters", filterJSON)
}
serverResponse, err := cli.get(ctx, "/events", query, nil)
if err != nil {
return nil, err
}
return serverResponse.body, nil
}
开发者ID:40a,项目名称:bootkube,代码行数:34,代码来源:events.go
示例4: ImageList
// ImageList returns a list of images in the docker host.
func (cli *Client) ImageList(options types.ImageListOptions) ([]types.Image, error) {
var images []types.Image
query := url.Values{}
if options.Filters.Len() > 0 {
filterJSON, err := filters.ToParam(options.Filters)
if err != nil {
return images, err
}
query.Set("filters", filterJSON)
}
if options.MatchName != "" {
// FIXME rename this parameter, to not be confused with the filters flag
query.Set("filter", options.MatchName)
}
if options.All {
query.Set("all", "1")
}
serverResp, err := cli.get("/images/json", query, nil)
if err != nil {
return images, err
}
err = json.NewDecoder(serverResp.body).Decode(&images)
ensureReaderClosed(serverResp)
return images, err
}
开发者ID:wenchma,项目名称:engine-api,代码行数:29,代码来源:image_list.go
示例5: getServiceTasks
func (d *SwarmDaemon) getServiceTasks(c *check.C, service string) []swarm.Task {
var tasks []swarm.Task
filterArgs := filters.NewArgs()
filterArgs.Add("desired-state", "running")
filterArgs.Add("service", service)
filters, err := filters.ToParam(filterArgs)
c.Assert(err, checker.IsNil)
status, out, err := d.SockRequest("GET", "/tasks?filters="+filters, nil)
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf("output: %q", string(out)))
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
c.Assert(json.Unmarshal(out, &tasks), checker.IsNil)
return tasks
}
开发者ID:Raphaeljunior,项目名称:docker,代码行数:15,代码来源:daemon_swarm.go
示例6: NetworkList
// NetworkList returns the list of networks configured in the docker host.
func (cli *Client) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
query := url.Values{}
if options.Filters.Len() > 0 {
filterJSON, err := filters.ToParam(options.Filters)
if err != nil {
return nil, err
}
query.Set("filters", filterJSON)
}
var networkResources []types.NetworkResource
resp, err := cli.get(ctx, "/networks", query, nil)
if err != nil {
return networkResources, err
}
err = json.NewDecoder(resp.body).Decode(&networkResources)
ensureReaderClosed(resp)
return networkResources, err
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:20,代码来源:network_list.go
示例7: ContainerList
// ContainerList returns the list of containers in the docker host.
func (cli *Client) ContainerList(options types.ContainerListOptions) ([]types.Container, error) {
query := url.Values{}
if options.All {
query.Set("all", "1")
}
if options.Limit != -1 {
query.Set("limit", strconv.Itoa(options.Limit))
}
if options.Since != "" {
query.Set("since", options.Since)
}
if options.Before != "" {
query.Set("before", options.Before)
}
if options.Size {
query.Set("size", "1")
}
if options.Filter.Len() > 0 {
filterJSON, err := filters.ToParam(options.Filter)
if err != nil {
return nil, err
}
query.Set("filters", filterJSON)
}
resp, err := cli.get("/containers/json", query, nil)
if err != nil {
return nil, err
}
var containers []types.Container
err = json.NewDecoder(resp.body).Decode(&containers)
ensureReaderClosed(resp)
return containers, err
}
开发者ID:wenchma,项目名称:engine-api,代码行数:43,代码来源:container_list.go
示例8: VolumeList
// VolumeList returns the volumes configured in the docker host.
func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (types.VolumesListResponse, error) {
var volumes types.VolumesListResponse
query := url.Values{}
if filter.Len() > 0 {
filterJSON, err := filters.ToParam(filter)
if err != nil {
return volumes, err
}
query.Set("filters", filterJSON)
}
resp, err := cli.get(ctx, "/volumes", query, nil)
if err != nil {
return volumes, err
}
err = json.NewDecoder(resp.body).Decode(&volumes)
ensureReaderClosed(resp)
return volumes, err
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:21,代码来源:volume_list.go
示例9: getNetworkIDByName
func getNetworkIDByName(c *check.C, name string) string {
var (
v = url.Values{}
filterArgs = filters.NewArgs()
)
filterArgs.Add("name", name)
filterJSON, err := filters.ToParam(filterArgs)
c.Assert(err, checker.IsNil)
v.Set("filters", filterJSON)
status, body, err := sockRequest("GET", "/networks?"+v.Encode(), nil)
c.Assert(status, checker.Equals, http.StatusOK)
c.Assert(err, checker.IsNil)
nJSON := []types.NetworkResource{}
err = json.Unmarshal(body, &nJSON)
c.Assert(err, checker.IsNil)
c.Assert(len(nJSON), checker.Equals, 1)
return nJSON[0].ID
}
开发者ID:dfilion,项目名称:docker,代码行数:21,代码来源:docker_api_network_test.go
示例10: TaskList
// TaskList returns the list of tasks.
func (cli *Client) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
query := url.Values{}
if options.Filter.Len() > 0 {
filterJSON, err := filters.ToParam(options.Filter)
if err != nil {
return nil, err
}
query.Set("filters", filterJSON)
}
resp, err := cli.get(ctx, "/tasks", query, nil)
if err != nil {
return nil, err
}
var tasks []swarm.Task
err = json.NewDecoder(resp.body).Decode(&tasks)
ensureReaderClosed(resp)
return tasks, err
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:23,代码来源:task_list.go
示例11: watchEvents
func (b *Box) watchEvents() {
const dieEvent = "die"
since := time.Now()
sleep := time.Second
maxSleep := time.Second * 32
filterArgs := filters.NewArgs()
filterArgs.Add("event", dieEvent)
filterArgs.Add("label", isolateDockerLabel)
fltrs, _ := filters.ToParam(filterArgs)
var eventResponse struct {
Status string `json:"status"`
ID string `json:"id"`
Time int64 `json:"time"`
}
logger := apexctx.GetLogger(b.ctx)
for {
eventsOptions := types.EventsOptions{
Since: strconv.FormatInt(since.Unix(), 10),
Filters: filterArgs,
}
logger.Infof("listening Docker events since %s with filters %s", eventsOptions.Since, fltrs)
resp, err := b.client.Events(b.ctx, eventsOptions)
switch err {
case nil:
sleep = time.Second
decoder := json.NewDecoder(resp)
for {
if err = decoder.Decode(&eventResponse); err != nil {
logger.WithError(err).Error("unable to decode Docker events")
resp.Close()
break
}
// Save timestamp of the latest received event
since = time.Unix(eventResponse.Time, 0)
switch eventResponse.Status {
case dieEvent:
logger.WithField("id", eventResponse.ID).Info("container has died")
var p *process
b.muContainers.Lock()
p, ok := b.containers[eventResponse.ID]
delete(b.containers, eventResponse.ID)
b.muContainers.Unlock()
if ok {
p.remove()
} else {
// NOTE: it could be orphaned worker from our previous launch
logger.WithField("id", eventResponse.ID).Warn("unknown container will be removed")
containerRemove(b.client, b.ctx, eventResponse.ID)
}
default:
logger.WithField("status", eventResponse.Status).Warn("unknown status")
}
}
case context.Canceled, context.DeadlineExceeded:
logger.Info("event listenening has been cancelled")
return
default:
// backoff
sleep *= 2
if sleep > maxSleep {
sleep = maxSleep
}
logger.WithError(err).Warnf("unable to listen events. Sleep %s", sleep)
time.Sleep(sleep)
}
}
}
开发者ID:terrible-broom,项目名称:stout,代码行数:79,代码来源:box.go
注:本文中的github.com/docker/engine-api/types/filters.ToParam函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论