husky

package module
v0.0.0-...-0e6234f Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2015 License: MIT Imports: 18 Imported by: 2

README

Husky

A Simple Router, HTTP, utility for golang

Installation

Use go get command:

go get github.com/ysugimoto/husky

Usage

Import and create app, and bind routes like Sinatra:

package main

import "github.com/ysugimoto/husky"


func main() {
    // create app
    app := husky.NewApp()

    // bind routes as you need
    app.Get("/", func(disp *husky.Dispatcher) {
        disp.Output.SetStatus(200)
        disp.Output.SetHeader("Content-Type", "text/plain")
        disp.Output.Send("Hello, Husky!")
    });
    ...

    // start server
    app.Serve()
}

That's all.

Configuration

Make config.yml at current directory (e.g main.go) to override config and write:

# listen address
host: 127.0.0.1

# listen port
port: 8888

# listen path
path: /

Will listen 127.0.0.1:8888.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewApp

func NewApp() *app

func NewWebSocketHandler

func NewWebSocketHandler(handler HuskyWebSocketHandler) websocket.Handler

Types

type Arguments

type Arguments struct {
	Commands []string
	Options  map[string]interface{}
	Aliases  map[string]aliasOption
}

func NewArguments

func NewArguments() *Arguments

func (*Arguments) Alias

func (a *Arguments) Alias(flag string, value string, defaultValue interface{})

func (*Arguments) GetCommandAt

func (a *Arguments) GetCommandAt(index int) (v string, ok bool)

func (*Arguments) GetCommandSize

func (a *Arguments) GetCommandSize() int

func (*Arguments) GetCommands

func (a *Arguments) GetCommands() []string

func (*Arguments) GetOption

func (a *Arguments) GetOption(sign string) (v interface{}, ok bool)

func (*Arguments) Parse

func (a *Arguments) Parse(args []string)

type Config

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

func NewConfig

func NewConfig() *Config

func (*Config) Get

func (c *Config) Get(key string) (interface{}, bool)

func (*Config) Set

func (c *Config) Set(key string, value interface{})

type Database

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

func NewDb

func NewDb(dsn string) *Database

func (*Database) AllQuery

func (d *Database) AllQuery() string

func (*Database) EnableLog

func (d *Database) EnableLog(enable bool)

func (*Database) Get

func (d *Database) Get(table string) (rows *sql.Rows, err error)

func (*Database) GetRow

func (d *Database) GetRow(table string) (row *sql.Row)

func (*Database) Insert

func (d *Database) Insert(table string, values map[string]interface{}) (result sql.Result, err error)

func (*Database) IsTrans

func (d *Database) IsTrans() bool

func (*Database) LastQuery

func (d *Database) LastQuery() string

func (*Database) Limit

func (d *Database) Limit(limit int) *Database

func (*Database) Offset

func (d *Database) Offset(offset int) *Database

func (*Database) Query

func (d *Database) Query(query string, bind ...interface{}) (rows *sql.Rows, err error)

func (*Database) QueryRow

func (d *Database) QueryRow(query string, bind ...interface{}) (rows *sql.Row)

func (*Database) Select

func (d *Database) Select(columns ...string) *Database

func (*Database) TransBegin

func (d *Database) TransBegin()

func (*Database) TransCommit

func (d *Database) TransCommit()

func (*Database) TransRollback

func (d *Database) TransRollback()

func (*Database) Update

func (d *Database) Update(table string, values map[string]interface{}) (result sql.Result, err error)

func (*Database) Where

func (d *Database) Where(field, operator string, bind interface{}) *Database

type Dispatcher

type Dispatcher struct {
	Input  *Input
	Output *Output
}

func NewDispatcher

func NewDispatcher(res http.ResponseWriter, req *http.Request) *Dispatcher

type HuskyHandler

type HuskyHandler func(dispatcher *Dispatcher)

type HuskyWebSocketHandler

type HuskyWebSocketHandler func(dispatcher *WebSocketDispatcher)

type Input

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

func NewInput

func NewInput(req *http.Request) *Input

func (*Input) Get

func (i *Input) Get(key string) string

func (*Input) GetRequest

func (i *Input) GetRequest() *http.Request

type Output

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

func NewOutput

func NewOutput(res http.ResponseWriter) *Output

func (*Output) IsHeadersSent

func (o *Output) IsHeadersSent() bool

func (*Output) Send

func (o *Output) Send(out interface{})

func (*Output) SendHeader

func (o *Output) SendHeader() *Output

func (*Output) SendJSON

func (o *Output) SendJSON(out interface{})

func (*Output) SetHeader

func (o *Output) SetHeader(key, value string) *Output

func (*Output) SetStatus

func (o *Output) SetStatus(code int) *Output

type Router

type Router struct {
	Routes     []*RouterInfo
	WebSockets []*WebSocketInfo
}

func NewRouter

func NewRouter() *Router

func (*Router) Bind

func (r *Router) Bind(method, route string, handler HuskyHandler)

func (*Router) BindWebSocket

func (r *Router) BindWebSocket(route string, handler HuskyWebSocketHandler)

func (*Router) FindDispatcher

func (r *Router) FindDispatcher(method, path string) (dispatcher *RouterInfo, notFound bool)

func (*Router) Send404

func (r *Router) Send404(res http.ResponseWriter, req *http.Request)

func (*Router) SendDefault404

func (r *Router) SendDefault404(res http.ResponseWriter, req *http.Request)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(res http.ResponseWriter, req *http.Request)

type RouterInfo

type RouterInfo struct {
	Method  []byte
	Route   string
	Handler HuskyHandler
}

type Server

type Server struct {
	Address string
	Port    int
	Path    string
}

func NewServer

func NewServer() *Server

func (*Server) Listen

func (s *Server) Listen(config *Config, router *Router)

type WebSocketDispatcher

type WebSocketDispatcher struct {
	Id        string
	OnMessage func(msg string)
	OnOpen    func()
	OnClose   func()
	// contains filtered or unexported fields
}

func NewWebSocketDispatcher

func NewWebSocketDispatcher(ws *websocket.Conn) *WebSocketDispatcher

func (*WebSocketDispatcher) Broadcast

func (w *WebSocketDispatcher) Broadcast(message []byte, ignores ...string) (err error)

func (*WebSocketDispatcher) Close

func (w *WebSocketDispatcher) Close()

func (*WebSocketDispatcher) Send

func (w *WebSocketDispatcher) Send(message []byte) (err error)

type WebSocketInfo

type WebSocketInfo struct {
	Route   string
	Handler websocket.Handler
}

type WebSocketManager

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

Jump to

Keyboard shortcuts

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