bundle

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Example (EnvironmentPrefixes)
package main

import (
	"os"

	"github.com/tmc/macgo/bundle"
)

func main() {
	// Example showing how to use environment variables for prefixes

	// Set app name prefix
	_ = os.Setenv("MACGO_APP_NAME_PREFIX", "Dev-")
	appName := bundle.CleanAppName("MyApp")
	// appName is now "Dev-MyApp"
	_ = appName

	// Set bundle ID prefix
	_ = os.Setenv("MACGO_BUNDLE_ID_PREFIX", "development")
	bundleID := bundle.InferBundleID("MyApp")
	// bundleID now starts with "development." followed by the inferred ID
	_ = bundleID

	// Clean up
	_ = os.Unsetenv("MACGO_APP_NAME_PREFIX")
	_ = os.Unsetenv("MACGO_BUNDLE_ID_PREFIX")
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanAppName

func CleanAppName(name string) string

CleanAppName removes problematic characters from app names. It replaces filesystem-problematic characters with hyphens and removes non-printable ASCII characters.

Environment variable MACGO_APP_NAME_PREFIX can be used to force a prefix on all app names. This is useful for development or organizational requirements.

This function is useful for sanitizing user-provided app names before creating app bundles.

func ExtractAppNameFromPath

func ExtractAppNameFromPath(execPath string) string

ExtractAppNameFromPath extracts a reasonable app name from an executable path. This function removes file extensions and cleans up the filename to create a suitable app name.

func InferBundleID

func InferBundleID(appName string) string

InferBundleID creates a reasonable bundle ID from the Go module path and app name. It uses the module path from build info to create meaningful, unique bundle IDs that reflect the actual Go module and program name.

Environment variable MACGO_BUNDLE_ID_PREFIX can be used to force a prefix on all bundle IDs. This is useful for development or organizational requirements.

Examples:

  • github.com/user/repo + "myapp" -> com.github.user.repo.myapp
  • example.com/project + "tool" -> com.example.project.tool
  • local/project + "app" -> local.project.app
  • With MACGO_BUNDLE_ID_PREFIX="dev": dev.com.github.user.repo.myapp

If no module information is available, it creates a fallback bundle ID based on the user's environment.

func InferFallbackBundleID

func InferFallbackBundleID(appName string) string

inferFallbackBundleID creates a bundle ID when no module info is available. It creates a reasonable default based on the user's system.

func LimitAppNameLength

func LimitAppNameLength(name string, maxLength int) string

LimitAppNameLength truncates an app name to a reasonable length, reserving space for the .app extension.

func ModulePathToBundleID

func ModulePathToBundleID(modulePath, appName string) string

modulePathToBundleID converts a Go module path to a bundle ID format. Examples:

github.com/user/repo -> com.github.user.repo.appname
example.com/project -> com.example.project.appname
local/project -> local.project.appname

func SanitizeBundleID

func SanitizeBundleID(bundleID string) string

SanitizeBundleID ensures the bundle ID follows proper conventions. Bundle IDs should only contain alphanumeric characters, hyphens, and periods.

func SanitizeComponent

func SanitizeComponent(component string) string

sanitizeComponent cleans a single bundle ID component.

func ValidateAppName

func ValidateAppName(name string) error

ValidateAppName checks if an app name is reasonable for macOS. App names should not contain filesystem-problematic characters and should be of reasonable length.

func ValidateBundleID

func ValidateBundleID(bundleID string) error

ValidateBundleID checks if a bundle ID follows Apple's naming conventions. Bundle IDs must use reverse DNS notation and contain only valid characters.

Requirements:

  • Must contain at least one dot (reverse DNS format)
  • Can only contain alphanumeric characters, dots, and hyphens
  • Cannot start or end with dots or hyphens
  • Cannot contain consecutive dots or hyphens
  • Components cannot start with numbers

Types

This section is empty.

Jump to

Keyboard shortcuts

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