Skip to content

🧰 ComposerUtils

pkg/composerutils is the basic utility set of Composer Skills, providing file system operations, HTTP downloads, mock interfaces, and test utilities. It is reused by pkg/composer, pkg/installer, and other modules, and can also be used independently.

Submodules

SubmodulePackage PathDescription
📁 File Systempkg/composerutils (fs.go)Write permission check, directory creation, file write
🌐 HTTP Downloadpkg/composerutils (http.go)File download with proxy/timeout
🎭 Mock Interfacespkg/composerutils/mockCommand execution, file system, download, runtime mocks
🧪 Test Utilitiespkg/composerutils (test_utils.go)Temporary directory, file assertions

Quick Example

go
package main

import (
	"fmt"
	"github.com/scagogogo/composer-skills/pkg/composerutils"
)

func main() {
	dir := "/tmp/my-app"

	// Ensure directory exists
	if err := composerutils.EnsureDirectoryExists(dir); err != nil {
		panic(err)
	}

	// Check write permission
	if err := composerutils.CheckWritePermission(dir); err != nil {
		fmt.Printf("No write permission: %v\n", err)
	}

	// Write file
	content := []byte(`{"name": "my/project"}`)
	_ = composerutils.CreateFileWithContent(dir+"/composer.json", content, 0644)
}

Design Goals

  • Thin and reliable: Only wraps most common system operations, avoiding reinventing the wheel.
  • Testable: Provides interface-based mocks through mock sub-package, making unit testing easy for upper modules.
  • Cross-platform: Based on standard library os/net/http, naturally cross-platform.

See each sub-document: File System · HTTP Download · Mock Interfaces · Test Utilities.

Released under the MIT License