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")
}
Output:
Index ¶
- func CleanAppName(name string) string
- func ExtractAppNameFromPath(execPath string) string
- func InferBundleID(appName string) string
- func InferFallbackBundleID(appName string) string
- func LimitAppNameLength(name string, maxLength int) string
- func ModulePathToBundleID(modulePath, appName string) string
- func SanitizeBundleID(bundleID string) string
- func SanitizeComponent(component string) string
- func ValidateAppName(name string) error
- func ValidateBundleID(bundleID string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanAppName ¶
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 ¶
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 ¶
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 ¶
inferFallbackBundleID creates a bundle ID when no module info is available. It creates a reasonable default based on the user's system.
func LimitAppNameLength ¶
LimitAppNameLength truncates an app name to a reasonable length, reserving space for the .app extension.
func ModulePathToBundleID ¶
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 ¶
SanitizeBundleID ensures the bundle ID follows proper conventions. Bundle IDs should only contain alphanumeric characters, hyphens, and periods.
func SanitizeComponent ¶
sanitizeComponent cleans a single bundle ID component.
func ValidateAppName ¶
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 ¶
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.