bespoke

package module
v0.0.0-...-69b81fd Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2015 License: MIT Imports: 11 Imported by: 0

README

bespoke

GoDoc

Package bespoke provides a way to create custom binaries: files that are executable that also contain additional data. The data can either be a key-value map or an arbitrary file.

Motivation

A common use for the Go language is creating command-line tools. As a concrete example, consider a web application that allows its users to download a command-line client to interact with it. The client may need to be configured with such things as the user name or an access token. Using bespoke you can create a binary that is specifically configured for each user who downloads it.

See the documentation for more information.

Example

This package lets you do things like this:

$ curl http://localhost:6060/calvin > hello_calvin
$ chmod +x hello_calvin; ./hello_calvin
hello calvin

$ curl http://localhost:6060/hobbes > hello_hobbes
$ chmod +x hello_hobbes; ./hello_hobbes
hello hobbes

Contributing

Feature requests, pull requests, questions and comments are welcome!

Tweet at me: @vikasgorur

Documentation

Overview

Package bespoke provides a way to create custom binaries: files that are executable that also contain additional data. The data can either be a key-value map or an arbitrary file.

Motivation

A common use for the Go language is creating command-line tools. As a concrete example, consider a web application that allows its users to download a command-line client to interact with it. The client may need to be configured with such things as the user name or an access token. Using bespoke you can create a binary that is specifically configured for each user who downloads it.

Example

See documentation for examples/server for a simple HTTP server that serves bespoke binaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractMap

func ExtractMap(filePath string) error

ExtractMap extracts the map[string]string that was packaged with the currently executing binary. The map is written at filePath as a JSON file.

func Map

func Map() (map[string]string, error)

Map returns the map[string]string that was packaged with the currently executing binary. It throws an error if this is not a bespoke binary.

func ReadFile

func ReadFile(name string) ([]byte, error)

ReadFile reads the given file that was packaged with the currently executing binary. It throws an error if this is not a bespoke binary or if the named file does not exist.

Types

type Bespoke

type Bespoke struct {
	// contains filtered or unexported fields
}

Bespoke represents a packaged bespoke binary. It is created by the functions bespoke.WithMap() and bespoke.WithFile(). It acts as an io.Reader and the contents of the bespoke binary can be accessed through Read().

func WithFile

func WithFile(exe io.Reader, filePath string) (*Bespoke, error)

WithFile creates a bespoke binary from the executable exe and the given file. The executable can access the file by calling bespoke.ReadFile()

func WithMap

func WithMap(exe io.Reader, data map[string]string) (*Bespoke, error)

WithMap creates a bespoke binary from the executable exe and the given map. The executable can access the map by calling bespoke.Map()

func (*Bespoke) Read

func (b *Bespoke) Read(p []byte) (int, error)

Read reads the next len(p) bytes from the buffer or until the bespoke binary is drained. The return value n is the number of bytes read. If the binary has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.

Directories

Path Synopsis
Command bespoke provides a way to create bespoke binaries.
Command bespoke provides a way to create bespoke binaries.
examples
hello
Command hello is a simple example of a bespoke binary.
Command hello is a simple example of a bespoke binary.
server
Command server is a simple HTTP server that demonstrates usage of the bespoke package.
Command server is a simple HTTP server that demonstrates usage of the bespoke package.

Jump to

Keyboard shortcuts

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