gonzo

package module
v0.0.0-...-9a491fe Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: MIT Imports: 6 Imported by: 21

README

Heads up! Gonzo is being polished at this stage so some APIs may change.

Gonzo GoDoc

File Processing Framework based on Go Pipelines.

Design

Gonzo is made up of File, Context, Stages, and Pipes.

File

File is an interface that mimics os.File with some additional APIs.

Pipes

Pipe holde a channel of files, a context for logging and deadlines, and a simple interface to pass files through a Stage.

Stages

Stages are where files are handled for processing.

Currently the follow stages are implemented, but writing new stages are supper simple.

ace Compile Ace templates.
archive/tar Work with tar archives.
archive/zip Work with zip Archives.
css Minify CSS
filter A collection of stages for filtering files.
fs Read and Write from Disk.
gcss Compile gcss to css.
gin A Go Server livereload utlity.
github Grab files from github.
html Minify HTML
js Minify JavaScript
livereload Livereload
passthrough Pass files through any executable.
resources go-resources binding.
s3 Put files to S3.
scss Compile SCSS to CSS.
util Some helpful utlites.
watch Watch files for change.
web Grab files from any URL.

Example

To compile scss files, minify the output, write it to disk, lifereload in browser, and upload it to Amazon S3, this all you need:

s3conf := s3.Config{
	AccessKey: os.Getenv("S3_ACCESSKEY"),
	SecretKey: os.Getenv("S3_SECRETE"),
	Name:      os.Getenv("S3_NAME"),
	Region:    s3.APSoutheast2,
	Perm:      s3.PublicRead,
}

lr := livereload.New(livereload.Config{LiveCSS: true})

err := s.Src(context.Background(), "app/style.scss").Then(
	util.Trim("app"),
	scss.Compile(),
	css.Minify(),
	fs.Dest("./public/assets/"),
	lr.Reload(),
	s3.Put(s3conf),
)
//Handle any _fatal_ error.

TODO:

  • Finish this document.
  • Add tests

Documentation

Overview

Package gonzo is a file-processing Framework based on Go [Pipelines](http://blog.golang.org/pipelines) concept.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File interface {
	io.ReadCloser
	Stat() (os.FileInfo, error)
	FileInfo() FileInfo
}

File is the virtual-file API used by Gonzo. This method `State` is provided for interoperability with os.File, so consider using the following interface for a Gonzo and os.File compatiable API

type File interface {
  io.ReadCloser
  Stat() (os.FileInfo, error)
}

func NewFile

func NewFile(rc io.ReadCloser, fi FileInfo) File

NewFile returns a file using the provided io.ReadCloser and FileInfo.

type FileInfo

type FileInfo interface {
	Name() string
	Size() int64
	Mode() os.FileMode
	ModTime() time.Time
	IsDir() bool
	Sys() interface{}

	Base() string

	SetName(string)
	SetSize(int64)
	SetMode(os.FileMode)
	SetModTime(time.Time)
	SetIsDir(bool)

	SetBase(string)
}

FileInfo is a mutuable superset of os.FileInfo with the additon of "Base"

func FileInfoFrom

func FileInfoFrom(fi os.FileInfo) FileInfo

FileInfoFrom createa a FileInfo from an os.FileInfo. Useful when working with os.File or other APIs that mimics http.FileSystem.

func NewFileInfo

func NewFileInfo() FileInfo

NewFileInfo create a new empty FileInfo.

type Pipe

type Pipe interface {
	Context() context.Context
	Files() <-chan File
	Pipe(stages ...Stage) Pipe
	Then(stages ...Stage) error
	Wait() error
}

Pipe handles stages and talks to other pipes.

func NewPipe

func NewPipe(ctx context.Context, files <-chan File) Pipe

NewPipe returns a pipe using the context provided and channel of files. If you don't need a context, use context.Background()

type Stage

type Stage func(context.Context, <-chan File, chan<- File) error

Stage is a function that takes a context, a channel of files to read and an output chanel. There is no correlation between a stages input and output, a stage may decided to pass the same files after transofrmation or generate new files based on the input or drop files.

A stage must not close the output channel based on the simple "Don't close it if you don't own it" principle. A stage must either pass on a file or call the `Close` method on it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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