stubfilegenerator

package module
v0.0.0-...-fb60bac Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: MIT Imports: 20 Imported by: 2

README

go-stubfilegenerator utility

license

Stub file generator written in golang

Features

  • Creates text files (txt, csv xml, css, js..)
  • Creates images (jpg, gif, png)
  • Creates documents (pdf, rtf, doc)
  • Creates archives (zip, tar, tar.bz2, tar.gz)

Usage

Install: go get -u github.com/webdevops/go-stubfilegenerator

package main

import (
	"github.com/webdevops/go-stubfilegenerator"
)

func main() {
	stubgen := stubfilegenerator.NewStubGenerator()
	stubgen.Generate("example/foo.txt")
	stubgen.Generate("example/foo.csv")
	stubgen.Generate("example/foo.xml")
	stubgen.Generate("example/foo.gif")
	stubgen.Generate("example/foo.png")
	stubgen.Generate("example/foo.jpg")

	stubgen.Image.Width = 1000
	stubgen.Image.Height = 1000
	stubgen.Generate("example/big.jpg")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

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

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type StubGenerator

type StubGenerator struct {
	// Variable map for search&replace inside Text fields or files
	TemplateVariables map[string]string
	Image             struct {
		// Background color of generated image
		BackgroundColor color.RGBA
		// Font color (for inserted text)
		FontColor color.RGBA
		// Font (for inserted text)
		Font *basicfont.Face
		// Font line height
		FontLineHeight int
		// Number of colors for palette (GIF)
		NumColors int
		// Quality (JPG)
		Quality int
		// Width of image
		Width int
		// Height of image
		Height int
		// Lines of text which will be written inside the image
		Text []string
	}
	// Overwrite existing files
	Overwrite bool
	// contains filtered or unexported fields
}

func NewStubGenerator

func NewStubGenerator() StubGenerator

Constructor Will init sane defaults

func (*StubGenerator) Clone

func (config *StubGenerator) Clone() StubGenerator

Clone stub genetator

func (*StubGenerator) Generate

func (config *StubGenerator) Generate(path string) error

generate one stub file, path will specify type and destination

func (*StubGenerator) SetRootPath

func (config *StubGenerator) SetRootPath(path string) error

Set root path of file generation This root path also makes sure that no files are generated outside of this directory

Jump to

Keyboard shortcuts

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