Skip to content

Instantly share code, notes, and snippets.

@dhanush
Last active August 10, 2017 07:25
Show Gist options
  • Save dhanush/70800b7d095a60923c00c56d92f01b97 to your computer and use it in GitHub Desktop.
Save dhanush/70800b7d095a60923c00c56d92f01b97 to your computer and use it in GitHub Desktop.
container_read_with_skip.go
reader, _ := cli.ContainerLogs(context.Background(), containerID, types.ContainerLogsOptions{
ShowStdout: true,
Follow: true,
})
defer reader.Close()
//read the first 8 bytes to ignore the HEADER part from docker container logs
p := make([]byte, 8)
reader.Read(p)
content, _ := ioutil.ReadAll(reader)
var codeOutput MyJSONStruct
if err := json.NewDecoder(strings.NewReader(string(content))).Decode(&codeOutput); err != nil {
//handle error
}
//set some other value in struct
codeOutput.ContainerID = containerID
@ChristianKniep
Copy link

Can you also share the struct of MyJSONStruct? Or maybe I missinterpret the code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment