dirty

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

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

Go to latest
Published: Oct 7, 2015 License: BSD-2-Clause-Views Imports: 4 Imported by: 0

README

dirtymartini

Martini is a great Go(lang) library for creating web-related software. A part of what makes it great is that it is very clean and contains few features, making it easy to read and understand the source code. However, to increase productivity and promote code reuse in my projects I wanted to dirty my Martini up a bit. This is my Dirty Martini library which adds some useful features to the Martini library that fits my purposes.

Examples

package main

import (
	"github.com/go-martini/martini"
	"github.com/kristoiv/dirtymartini"
	"github.com/martini-contrib/render"
)

func main() {
	d := dirty.Classic()
	d.Use(render.Renderer())
	d.Group("/api", Routes)
	d.Run()
}

func Routes(router martini.Router) {
	router.Get("/", IndexAction).Name("/api")
	router.Get("/welcome/(?P<name>[a-zA-Z]+)", WelcomeAction).Name("/api/welcome")
}

func IndexAction(helper dirty.Helper, r render.Render) {
	r.JSON(200, map[string]interface{}{
		"Self":    helper.URLFor("/api"),
		"Welcome": helper.URLFor("/api/welcome", "<Test>"),
	})
}

func WelcomeAction(helper dirty.Helper, r render.Render, params martini.Params) {
	name := params["name"]
	r.JSON(200, map[string]interface{}{
		"Message": "Welcome to the API " + name,
		"Self":    helper.URLFor("/api/welcome", name),
	})
}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HelperMiddleware

func HelperMiddleware() func(c martini.Context, routes martini.Routes, req *http.Request)

Types

type ClassicDirty

type ClassicDirty struct {
	*Dirty
	Router
}

func Classic

func Classic() *ClassicDirty

func ClassicWithFallback

func ClassicWithFallback(fallback, exclude string) *ClassicDirty

type Dirty

type Dirty struct {
	*martini.Martini
	// contains filtered or unexported fields
}

func New

func New() *Dirty

func (*Dirty) SetLoggerPrefix

func (d *Dirty) SetLoggerPrefix(name string)

type Helper

type Helper interface {
	URLFor(name string, params ...interface{}) string
}

type Router

type Router interface {
	martini.Router
}

func NewRouter

func NewRouter() Router

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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