本文整理汇总了Golang中github.com/docker/containerd/api/grpc/types.APIClient类的典型用法代码示例。如果您正苦于以下问题:Golang APIClient类的具体用法?Golang APIClient怎么用?Golang APIClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了APIClient类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: containerEvents
func containerEvents(c types.APIClient, container string) <-chan *types.Event {
evChan := make(chan *types.Event)
ts := time.Now()
go func() {
for {
tsp, err := ptypes.TimestampProto(ts)
if err != nil {
close(evChan)
return
}
events, err := c.Events(netcontext.Background(), &types.EventsRequest{Timestamp: tsp})
if err != nil {
fmt.Printf("c.Events error: %v", err)
// TODO try to find a way to kill the process ?
close(evChan)
return
}
for {
e, err := events.Recv()
if err != nil {
time.Sleep(1 * time.Second)
break
}
ts, err = ptypes.Timestamp(e.Timestamp)
if e.Id == container {
evChan <- e
}
}
}
}()
return evChan
}
示例2: waitForExit
func waitForExit(c types.APIClient, events types.API_EventsClient, id, pid string, closer func()) {
timestamp := time.Now()
for {
e, err := events.Recv()
if err != nil {
if grpc.ErrorDesc(err) == transport.ErrConnClosing.Desc {
closer()
os.Exit(128 + int(syscall.SIGHUP))
}
time.Sleep(1 * time.Second)
tsp, err := ptypes.TimestampProto(timestamp)
if err != nil {
closer()
fmt.Fprintf(os.Stderr, "%s", err.Error())
os.Exit(1)
}
events, _ = c.Events(netcontext.Background(), &types.EventsRequest{Timestamp: tsp})
continue
}
timestamp, err = ptypes.Timestamp(e.Timestamp)
if e.Id == id && e.Type == "exit" && e.Pid == pid {
closer()
os.Exit(int(e.Status))
}
}
}
示例3: worker
func worker(client types.APIClient) {
defer group.Done()
for id := range jobs {
if _, err := client.CreateContainer(netcontext.Background(), &types.CreateContainerRequest{
Id: id,
BundlePath: bundle,
}); err != nil {
logrus.Error(err)
}
}
}
示例4: resize
func resize(id, pid string, c types.APIClient) error {
ws, err := term.GetWinsize(os.Stdin.Fd())
if err != nil {
return err
}
if _, err := c.UpdateProcess(netcontext.Background(), &types.UpdateProcessRequest{
Id: id,
Pid: "init",
Width: uint32(ws.Width),
Height: uint32(ws.Height),
}); err != nil {
return err
}
return nil
}
示例5: waitForExit
func waitForExit(c types.APIClient, events types.API_EventsClient, id, pid string, closer func()) {
timestamp := uint64(time.Now().Unix())
for {
e, err := events.Recv()
if err != nil {
time.Sleep(1 * time.Second)
events, _ = c.Events(netcontext.Background(), &types.EventsRequest{Timestamp: timestamp})
continue
}
timestamp = e.Timestamp
if e.Id == id && e.Type == "exit" && e.Pid == pid {
closer()
os.Exit(int(e.Status))
}
}
}
示例6: resizeTty
func resizeTty(c types.APIClient, container, process string) {
ws, err := term.GetWinsize(os.Stdin.Fd())
if err != nil {
fmt.Printf("Error getting size: %s", err.Error())
return
}
if _, err = c.UpdateProcess(netcontext.Background(), &types.UpdateProcessRequest{
Id: container,
Pid: process,
Width: uint32(ws.Width),
Height: uint32(ws.Height),
}); err != nil {
fmt.Printf("set winsize failed, %v\n", err)
}
}