Created
June 10, 2016 01:33
-
-
Save yifan-gu/220c8458a2b28f91f166daabc06f5589 to your computer and use it in GitHub Desktop.
testlog.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"io" | |
"os" | |
"github.com/coreos/rkt/api/v1alpha" | |
"golang.org/x/net/context" | |
"google.golang.org/grpc" | |
) | |
func main() { | |
lines := flag.Int("lines", 0, "tail lines") | |
flag.Parse() | |
conn, err := grpc.Dial("localhost:15441", grpc.WithInsecure()) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
c := v1alpha.NewPublicAPIClient(conn) | |
defer conn.Close() | |
podResp, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{}) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
for _, p := range podResp.Pods { | |
fmt.Printf("Pod %q state %q.\n", p.Id, p.State) | |
logsResp, err := c.GetLogs(context.Background(), &v1alpha.GetLogsRequest{ | |
PodId: p.Id, | |
Follow: false, | |
AppName: p.Apps[0].Name, | |
Lines: int32(*lines), | |
}) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
for { | |
resp, err := logsResp.Recv() | |
if err == io.EOF { | |
fmt.Println("EOF") | |
break | |
} | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
for _, l := range resp.Lines { | |
fmt.Println(l) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment