gogogo

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package gogogo creates projects from tar-based templates.

Templates may use {{key}} and __key__ placeholders in text files. Binary files are copied byte-for-byte without placeholder substitution.

Index

Examples

Constants

View Source
const DefaultRepository = "bcomnes/go-template#master"

DefaultRepository is the GitHub template used when no repository is configured.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Parameters contains placeholder values.
	// The name parameter defaults to the destination directory name.
	Parameters map[string]string
}

Options controls project creation.

type Project

type Project struct {
	Name        string
	Destination string
}

Project describes a created project.

func Create

func Create(ctx context.Context, destination string, archive io.Reader, options Options) (Project, error)

Create extracts a tar or gzip-compressed tar template into destination.

The archive must contain a common top-level directory, which Create strips. Placeholder substitution is applied only to text files.

Example
var archive bytes.Buffer
writer := tar.NewWriter(&archive)
content := []byte("# __name__\n")
_ = writer.WriteHeader(&tar.Header{
	Name:     "template/README.md",
	Mode:     0o644,
	Size:     int64(len(content)),
	Typeflag: tar.TypeReg,
})
_, _ = writer.Write(content)
_ = writer.Close()

parent, _ := os.MkdirTemp("", "gogogo-example-")
defer os.RemoveAll(parent)
destination := filepath.Join(parent, "example")
project, _ := gogogo.Create(context.Background(), destination, bytes.NewReader(archive.Bytes()), gogogo.Options{})
readme, _ := os.Open(filepath.Join(project.Destination, "README.md"))
defer readme.Close()

fmt.Println(project.Name)
_, _ = io.Copy(os.Stdout, readme)
Output:
example
# example

type Repository

type Repository struct {
	User   string `json:"user"`
	Repo   string `json:"repo"`
	Branch string `json:"branch"`
}

Repository identifies a GitHub repository and branch.

func ParseRepository

func ParseRepository(value string) (Repository, error)

ParseRepository parses user/repo, Git URL, and optional #branch forms.

func (Repository) ArchiveURL

func (r Repository) ArchiveURL() string

ArchiveURL returns the GitHub tarball URL for the repository branch.

func (Repository) String

func (r Repository) String() string

String returns the canonical user/repo#branch representation.

Jump to

Keyboard shortcuts

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