Skip to content

Instantly share code, notes, and snippets.

@sitaramshelke
Created November 28, 2023 14:10
Show Gist options
  • Save sitaramshelke/f7b498d331f85079e7e652ba86d50873 to your computer and use it in GitHub Desktop.
Save sitaramshelke/f7b498d331f85079e7e652ba86d50873 to your computer and use it in GitHub Desktop.
Snippet for self updatable go binaries
// Code snippet: To extract executable
func getExecutableFromAsset(assetId AssetId, format AssetFormat) ([]byte, error) {
buff, err := downloadAssetFromID(assetId)
if format == Zip {
zipReader, err := zip.NewReader(bytes.NewReader(buff.Bytes()), int64(buff.Len()))
// Zip reader logic
} else if format == Tar {
gzipReader, err := gzip.NewReader(buff)
tarReader := tar.NewReader(gzipReader)
}
return nil, fmt.Errorf("executable not found in archive")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment