Help us shape the future of Go! Take the 2026 Go Developer Survey

slug

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: MPL-2.0 Imports: 10 Imported by: 26

README

go-slug

Build Status GitHub license GoDoc Go Report Card GitHub issues

Package go-slug offers functions for packing and unpacking Terraform Enterprise compatible slugs. Slugs are gzip compressed tar files containing Terraform configuration files.

Installation

Installation can be done with a normal go get:

go get -u github.com/hashicorp/go-slug

Documentation

For the complete usage of go-slug, see the full package docs.

Example

Packing or unpacking a slug is pretty straight forward as shown in the following example:

package main

import (
	"bytes"
	"io/ioutil"
	"log"
	"os"

	slug "github.com/hashicorp/go-slug"
)

func main() {
	// First create a buffer for storing the slug.
	buf := bytes.NewBuffer(nil)

	// Then call the Pack function with a directory path containing the
	// configuration files and an io.Writer to write the slug to.
	if _, err := slug.Pack("testdata/archive-dir", buf, false); err != nil {
		log.Fatal(err)
	}

	// Create a directory to unpack the slug contents into.
	dst, err := ioutil.TempDir("", "slug")
	if err != nil {
		log.Fatal(err)
	}
	defer os.RemoveAll(dst)

	// Unpacking a slug is done by calling the Unpack function with an
	// io.Reader to read the slug from and a directory path of an existing
	// directory to store the unpacked configuration files.
	if err := slug.Unpack(buf, dst); err != nil {
		log.Fatal(err)
	}
}

Issues and Contributing

If you find an issue with this package, please report an issue. If you'd like, we welcome any contributions. Fork this repository and submit a pull request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unpack

func Unpack(r io.Reader, dst string) error

Unpack is used to read and extract the contents of a slug to the dst directory. Symlinks within the slug are supported, provided their targets are relative and point to paths within the destination directory.

Types

type Meta

type Meta struct {
	// The list of files contained in the slug.
	Files []string

	// Total size of the slug in bytes.
	Size int64
}

Meta provides detailed information about a slug.

func Pack

func Pack(src string, w io.Writer, dereference bool) (*Meta, error)

Pack creates a slug from a src directory, and writes the new slug to w. Returns metadata about the slug and any errors.

When dereference is set to true, symlinks with a target outside of the src directory will be dereferenced. When dereference is set to false symlinks with a target outside the src directory are omitted from the slug.

Jump to

Keyboard shortcuts

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