results

package module
v0.0.0-...-2b31046 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2014 License: MIT Imports: 6 Imported by: 0

README

GOLANG project template

This is my personal GOLANG project template. It is built with these goals in mind:

  • Everything should be local to the development folder as much as is possible without resorting to ugly hacks.

  • 1-step build or test without any special setup after any git clone on a newly minted machine except for installing the go compiler itself.

  • Do not rely on global GOPATH and yet still allows you to check your entire source folder in as if you would a normal go program inside one. This makes your repository plays well with other go coders who will surely be using the global GOPATH convention.

Getting Started

Run this one-liner to dump the repository content into current directory.

curl -L https://github.com/chakrit/go-scratch/archive/master.tar.gz | tar -xzv --strip 1

Or a full setup for a new project:

mkdir your-new-shiny-project    # Make a new shiny folder for your new project.
cd your-new-shiny-project       # Get into the folder first, of course.
git init                        # Or not, doesn't matter.

# Download the scratch template
curl -L https://github.com/chakrit/go-scratch/archive/master.tar.gz | tar -xzv --strip 1

git add .
git commit -m "Initialize GOLANG project. (github.com/chakrit/go-scratch)"

Makefile

Everything is done through the Makefile for convenience. A wrapper script ./go is also provided that invokes go with GOPATH sets to the local .go folder.

Makefile tasks defaults to test. The all task is simply an alias for the build task. All common tasks you'd do with go is given the same name in the Makefile so go vet is, through the Makefile, make vet or via the wrapper script ./go vet.

Dependencies

Dependencies are handled implicitly and automatically as you run tasks that involve import paths thanks to the powerful go get command.

Specifically, make deps and make test-deps will download the dependencies into place and subsequent make test or make build will automaticaly compiles the downloaded dependencies as needed.

The initial main.go file provided with this project contains some dependencies as well as tests (and test dependencies) to demonstrate this.

Subpackages

This template supports multiple packages development inside a single folder out of the box. You are, however, required to list all the subpackage paths inside the Makefile PKG variable as automatically detecting them is tricky and error prone.

For example, if you have a context subpackage, edit the PKG line like so:

PKG := . ./context

... or if you have nothing in the root folder and only subpackages uno dos and tres:

PKG := ./uno ./dos ./tres

Example

Here's a sample output of what happens when you simply cloned this repository and issue make:

$ make
/Users/chakrit/Documents/go-scratch/go get -d -t .
/Users/chakrit/Documents/go-scratch/go test .
ok    _/Users/chakrit/Documents/go-scratch0.010s

Silent run

Uses make's -s flag to prevent make from echoing commands (useful for reducing clutter to standard output.)

$ make -s
ok      _/Users/chakrit/Documents/go-scratch    0.011s

LICENSE

WTFPL

TODO:

  • Package the curl installation into a script.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Defer

func Defer(resolve z.Action) z.Result

func Dud

func Dud() z.Result

func Http

func Http(code int, header string, values ...string) z.Result

func Json

func Json(code int, object interface{}) z.Result

func PermanentRedirect

func PermanentRedirect(url string, args ...interface{}) z.Result

func Redirect

func Redirect(url string, args ...interface{}) z.Result

TODO: Properly url-escape and query-escape formatted things.

Otherwise doc the assumption that the url is safe (since this is mostly used
to format model ids into the string anyway.)

func RenderFunc

func RenderFunc(render func(c *z.Context) error) z.Result

func String

func String(code int, str string, args ...interface{}) z.Result

func View

func View(view v.View, data interface{}) z.Result

Types

type Controller

type Controller struct{}

Vanilla mixin for convenience to add to your controller to get simpler access to result building methods.

func (*Controller) Defer

func (c *Controller) Defer(resolve z.Action) z.Result

func (*Controller) Dud

func (c *Controller) Dud() z.Result

func (*Controller) Http

func (c *Controller) Http(code int, header string, values ...string) z.Result

func (*Controller) Json

func (c *Controller) Json(code int, object interface{}) z.Result

func (*Controller) PermanentRedirect

func (c *Controller) PermanentRedirect(url string, args ...interface{}) z.Result

func (*Controller) Redirect

func (c *Controller) Redirect(url string, args ...interface{}) z.Result

func (*Controller) RenderFunc

func (c *Controller) RenderFunc(render func(c *z.Context) error) z.Result

func (*Controller) Resource

func (c *Controller) Resource() *ResourceRepresentable

func (*Controller) String

func (c *Controller) String(code int, str string, args ...interface{}) z.Result

func (*Controller) View

func (c *Controller) View(view v.View, data interface{}) z.Result

type ResourceRepresentable

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

func Resource

func Resource() *ResourceRepresentable

func (*ResourceRepresentable) Html

func (*ResourceRepresentable) Json

func (*ResourceRepresentable) Mime

func (*ResourceRepresentable) Render

func (b *ResourceRepresentable) Render(c *z.Context) error

func (*ResourceRepresentable) Text

Jump to

Keyboard shortcuts

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