Skip to content

Instantly share code, notes, and snippets.

@jdolitsky
Created September 2, 2022 14:19
Show Gist options
  • Save jdolitsky/eaaae0f4ab8f3a9d3c95ab0727f31001 to your computer and use it in GitHub Desktop.
Save jdolitsky/eaaae0f4ab8f3a9d3c95ab0727f31001 to your computer and use it in GitHub Desktop.
Parse an apk with Go
package main
import (
"fmt"
"os"
apkrepo "gitlab.alpinelinux.org/alpine/go/repository"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: go run main.go <path_to_apk>")
os.Exit(1)
}
f, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
defer f.Close()
apk, err := apkrepo.ParsePackage(f)
if err != nil {
panic(err)
}
fmt.Printf("Name: %s\n", apk.Name)
fmt.Printf("Version: %s\n", apk.Version)
fmt.Printf("Arch: %s\n", apk.Arch)
fmt.Printf("Desc: %s\n", apk.Description)
fmt.Printf("Checksum: %s\n", apk.ChecksumString())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment