selfexec

package
v0.0.0-...-978d0fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package selfexec embeds a pact document into an executable and reads it back.

Format (appended to the binary):

[ pact binary bytes          ]
[ document content (UTF-8)   ]
[ 8 bytes: magic "PACTDOC1"  ]
[ 8 bytes: content length (uint64 little-endian) ]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasAllPlatforms

func HasAllPlatforms() bool

HasAllPlatforms reports whether all supported platform binaries are embedded. True only when built with -tags with_platforms (i.e. 'make dist').

func InstallAndRegister

func InstallAndRegister(exePath string)

InstallAndRegister makes pact durable on this machine: it copies the running binary into the per-OS install location (so pact survives the downloaded file being deleted) and registers the installed copy as the default editor for .pact files. Called in the background on every regular (non self-executing) startup; cheap when everything is already in place.

func InstallCopy

func InstallCopy(exePath, home string) string

InstallCopy ensures the durable copy exists and matches the running binary, refreshing it after an upgrade. If the running binary carries embedded binaries for other platforms (dist build), it also updates those in their respective home-directory install locations.

It returns the path registration should point at: the installed copy for the current platform when available, the running binary when installing failed.

func Read

func Read(path string) (string, bool)

Read checks the file at path for an embedded pact document. Returns the document content and true if found.

func ReplaceFile

func ReplaceFile(path string, data []byte, perm os.FileMode) error

func UnderTempDir

func UnderTempDir(path string) bool

func WriteForPlatform

func WriteForPlatform(goos, goarch, content, outPath string) error

WriteForPlatform saves the document as a self-contained executable for the given goos/goarch. Uses an embedded pre-compiled binary when available (dist build), otherwise falls back to the running binary for the current platform.

For darwin, outPath must end with ".app" when creating a new bundle; the function creates the full .app directory structure with icon and launcher. When called with a plain path (e.g. during post-sign self-overwrite inside an existing bundle), it writes a plain binary file.

func WritePact

func WritePact(content, outPath string) error

WritePact saves the document content as XML-based .pact data readable by selfexec.Read. content may be a plain-text pact body or a pre-built pact XML document.

func WriteZip

func WriteZip(content, outPath string) error

WriteZip bundles self-executing binaries for all supported platforms into a ZIP archive. Requires a dist build (-tags with_platforms); returns an error otherwise.

Types

This section is empty.

Source Files

  • install.go
  • register.go
  • register_stub.go
  • selfexec.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL