Difference between revisions of "CRIT (Go library)"
Prajwal S N (talk | contribs) m (Fix broken link) |
Prajwal S N (talk | contribs) m (Fix indents) |
||
Line 21: | Line 21: | ||
* Boolean to generate indented and multi-line JSON output | * Boolean to generate indented and multi-line JSON output | ||
* Boolean to skip payload data | * Boolean to skip payload data | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
The below operations are provided by the service. | The below operations are provided by the service. | ||
− | < | + | <pre> |
− | + | Decode() (*CriuImage, error) | |
− | + | Info() (*CriuImage, error) | |
− | + | Parse() (*CriuImage, error) | |
− | + | Encode(*CriuImage) error | |
− | + | ExplorePs() (*PsTree, error) | |
− | + | ExploreFds() ([]*Fd, error) | |
− | + | ExploreMems() ([]*MemMap, error) | |
− | + | ExploreRss() ([]*RssMap, error) | |
− | </ | + | </pre> |
Documentation about the types and methods provided by the library can be found [https://pkg.go.dev/github.com/checkpoint-restore/go-criu/v5/crit here]. | Documentation about the types and methods provided by the library can be found [https://pkg.go.dev/github.com/checkpoint-restore/go-criu/v5/crit here]. | ||
Line 52: | Line 42: | ||
'''example.go''' | '''example.go''' | ||
− | < | + | <pre> |
package main | package main | ||
Line 77: | Line 67: | ||
fmt.Println("Image version is ", imgVersion) | fmt.Println("Image version is ", imgVersion) | ||
} | } | ||
− | </ | + | </pre> |
== Difference between Go and Python CLI == | == Difference between Go and Python CLI == | ||
* The Go CLI uses JSON as the standard output format for all commands, whereas the Python CLI uses custom formats for <code>crit explore</code>. This results in different outputs for the same command, although the content remains the same. | * The Go CLI uses JSON as the standard output format for all commands, whereas the Python CLI uses custom formats for <code>crit explore</code>. This results in different outputs for the same command, although the content remains the same. | ||
− | * The Go JSON output uses camelCased field names, whereas the Python CLI JSON output uses snake_case field names. | + | * The Go JSON output uses <code>camelCased</code> field names, whereas the Python CLI JSON output uses <code>snake_case</code> field names. |
[[Category: Images]] | [[Category: Images]] | ||
[[Category: API]] | [[Category: API]] | ||
[[Category: Go]] | [[Category: Go]] |
Revision as of 09:00, 12 August 2022
go-criu provides a Go library based on CRIT. It supports encoding, decoding, and modification of CRIU images natively within Go code. It also ships with a CLI tool similar to the Python variant (not completely identical, see #Difference between Go and Python CLI).
Usage
You can import the package into your Go project and use it like below:
import "github.com/checkpoint-restore/go-criu/v6/crit"
To build the CLI tool, run make bin/crit
in the crit/
directory.
Operations
Every operation requires a CRIT service instance. This can be created in two ways:
New()
: Create a new service to use within a Go program. It does not support reading from stdin or printing to stdout, and is meant to be used purely non-interactively.NewCli()
: Create a new service to use as a CLI. It supports reading from stdin and printing to stdout if no file paths are provided, and can be used interactively.
Both functions take the same parameters:
- Path of the input file
- Path of the output file
- Path of the input directory (for `crit explore`)
- Boolean to generate indented and multi-line JSON output
- Boolean to skip payload data
The below operations are provided by the service.
Decode() (*CriuImage, error) Info() (*CriuImage, error) Parse() (*CriuImage, error) Encode(*CriuImage) error ExplorePs() (*PsTree, error) ExploreFds() ([]*Fd, error) ExploreMems() ([]*MemMap, error) ExploreRss() ([]*RssMap, error)
Documentation about the types and methods provided by the library can be found here.
Examples
Here is a simple example of decoding inventory.img
and printing the image version:
example.go
package main import ( "fmt" "github.com/checkpoint-restore/go-criu/v6/crit" "github.com/checkpoint-restore/go-criu/v6/crit/images" ) func main() { c := crit.New( "inventory.img", /* input path */ "", /* output path */ "", /* input dir path (for Explore*()) */ false, /* indenting for JSON */ false, /* no payload */ ) img, err := c.Decode() if err != nil { fmt.Println("Error: ", err) } imgVersion := img.(*images.InventoryEntry).GetImgVersion() fmt.Println("Image version is ", imgVersion) }
Difference between Go and Python CLI
- The Go CLI uses JSON as the standard output format for all commands, whereas the Python CLI uses custom formats for
crit explore
. This results in different outputs for the same command, although the content remains the same. - The Go JSON output uses
camelCased
field names, whereas the Python CLI JSON output usessnake_case
field names.