next

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

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

Go to latest
Published: Sep 12, 2016 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package web is a lightweight web framework for Go. It's ideal for writing simple, performant backend web services.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	DuoHead       = 0xEF
	DuoSec        = 0x01
	DuoMaxContent = 2 << 10
)
View Source
const (
	// Bits or'ed together to control what's printed. There is no control over the
	// order they appear (the order listed here) or the format they present (as
	// described in the comments).  A colon appears after these items:
	//	2009/0123 01:23:23.123123 /a/b/c/d.go:23: message
	Ldate         = 1 << iota     // the date: 2009/0123
	Ltime                         // the time: 01:23:23
	Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                     // full file name and line number: /a/b/c/d.go:23
	Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
	Lmodule                       // module name
	Llevel                        // level: 0(Debug), 1(Info), 2(Warn), 3(Error), 4(Panic), 5(Fatal)
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
	Ldefault      = Lmodule | Llevel | Lshortfile | LstdFlags
)

These flags define which text to prefix to each log entry generated by the Logger.

View Source
const (
	Ldebug = iota
	Linfo
	Lwarn
	Lerror
	Lpanic
	Lfatal
)
View Source
const (
	TcpHead       = 0xAA
	TcpTail       = 0x0A
	TcpMaxContent = 2 << 10
)
View Source
const VERSION = "0.0.1"

Variables

View Source
var Std = New(os.Stderr, "", Ldefault)

Functions

func Close

func Close()

Close stops the main server.

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Delete

func Delete(route string, handler interface{})

Delete adds a handler for the 'DELETE' http method in the main server.

func Error

func Error(v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func Fatalln

func Fatalln(v ...interface{})

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func Flags

func Flags() int

Flags returns the output flags for the standard logger.

func Get

func Get(route string, handler interface{})

Get adds a handler for the 'GET' http method in the main server.

func GetOutputLevel

func GetOutputLevel() int

func Handler

func Handler(route string, method string, httpHandler http.Handler)

Adds a custom handler. Only for webserver mode. Will have no effect when running as FCGI or SCGI.

func Info

func Info(v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func Match

func Match(method string, route string, handler interface{})

Match adds a handler for an arbitrary http method in the main server.

func Md5

func Md5(str, salt string) string

func MiddlewareDuo

func MiddlewareDuo(handler interface{})

Add a plugin

func MiddlewareTcp

func MiddlewareTcp(handler interface{})

Add a plugin

func NewCookie

func NewCookie(name string, value string, age int64) *http.Cookie

NewCookie is a helper method that returns a new http.Cookie object. Duration is specified in seconds. If the duration is zero, the cookie is permanent. This can be used in conjunction with ctx.SetCookie.

func Panic

func Panic(v ...interface{})

Panic is equivalent to Print() followed by a call to panic().

func Panicf

func Panicf(format string, v ...interface{})

Panicf is equivalent to Printf() followed by a call to panic().

func Panicln

func Panicln(v ...interface{})

Panicln is equivalent to Println() followed by a call to panic().

func Post

func Post(route string, handler interface{})

Post adds a handler for the 'POST' http method in the main server.

func Prefix

func Prefix() string

Prefix returns the output prefix for the standard logger.

func Print

func Print(v ...interface{})

Print calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(format string, v ...interface{})

Printf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Println

func Println(v ...interface{})

Println calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println.

func Process

func Process(c http.ResponseWriter, req *http.Request)

Process invokes the main server's routing system.

func Put

func Put(route string, handler interface{})

Put adds a handler for the 'PUT' http method in the main server.

func Rand

func Rand(n int, letters []rune) string

func RandNum

func RandNum(n int) string

func RandStr

func RandStr(n int) string

func Run

func Run(addr string)

Run starts the web application and serves HTTP requests for the main server.

func RunDuo

func RunDuo(addr string)

------------- Run starts the web application and serves Tcp service for the main server.

func RunTLS

func RunTLS(addr string, config *tls.Config)

RunTLS starts the web application and serves HTTPS requests for the main server.

func RunTcp

func RunTcp(addr string)

Run starts the web application and serves Tcp service for the main server.

func SetFlags

func SetFlags(flag int)

SetFlags sets the output flags for the standard logger.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger.

func SetOutputLevel

func SetOutputLevel(lvl int)

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets the output prefix for the standard logger.

func Slug

func Slug(s string, sep string) string

Slug is a helper function that returns the URL slug for string s. It's used to return clean, URL-friendly strings that can be used in routing.

func Stack

func Stack(v ...interface{})

func UUID

func UUID() string

func Urlencode

func Urlencode(data map[string]string) string

Urlencode is a helper method that converts a map into URL-encoded form data. It is a useful when constructing HTTP POST requests.

func Via

func Via(route string, handler interface{})

Post adds a handler for the 'POST' http method in the main server.

func ViaDuo

func ViaDuo(route string, handler interface{})

Add a handler for tcp method in the main server.

func ViaTcp

func ViaTcp(route string, handler interface{})

Add a handler for tcp method in the main server.

func Warn

func Warn(v ...interface{})

func Warnf

func Warnf(format string, v ...interface{})

Types

type Config

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

Usage:

import "github.com/api4me/next"

conf := next.Config{}

func NewConfig

func NewConfig() *Config

func (*Config) Bool

func (cfg *Config) Bool(key string) bool

Bool returns the string value for given key. val := conf.Get('redis.key')

func (*Config) Int

func (cfg *Config) Int(key string) int

Bool returns the string value for given key. val := conf.Get('redis.key')

func (*Config) Load

func (cfg *Config) Load(name string) (*Config, error)

func (*Config) Read

func (cfg *Config) Read(content []byte) (*Config, error)

func (*Config) Set

func (cfg *Config) Set(key, val string)

String returns the string value for given key. cfg, err := conf.Set('redis.key', 'key123')

func (*Config) String

func (cfg *Config) String(key string) string

String returns the string value for given key. val := conf.Get('redis.key')

type Context

type Context struct {
	Request *http.Request
	Params  map[string]string
	Server  *Server
	http.ResponseWriter
}

A Context object is created for every incoming HTTP request, and is passed to handlers as an optional first argument. It provides information about the request, including the http.Request object, the GET and POST params, and acts as a Writer for the response.

func (*Context) Abort

func (ctx *Context) Abort(status int, body string)

Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.

func (*Context) ClientIp

func (ctx *Context) ClientIp() (string, error)

func (*Context) ContentType

func (ctx *Context) ContentType(val string) string

ContentType sets the Content-Type header for an HTTP response. For example, ctx.ContentType("json") sets the content-type to "application/json" If the supplied value contains a slash (/) it is set as the Content-Type verbatim. The return value is the content type as it was set, or an empty string if none was found.

func (*Context) Forbidden

func (ctx *Context) Forbidden()

Forbidden writes a 403 HTTP response

func (*Context) GetBasicAuth

func (ctx *Context) GetBasicAuth() (string, string, error)

GetBasicAuth is a helper method of *Context that returns the decoded user and password from the *Context's authorization header

func (*Context) GetCookieSig

func (ctx *Context) GetCookieSig(key string, val []byte, timestamp string) string

func (*Context) GetSecureCookie

func (ctx *Context) GetSecureCookie(name string) (string, bool)

func (*Context) NotFound

func (ctx *Context) NotFound(message string)

NotFound writes a 404 HTTP response

func (*Context) NotModified

func (ctx *Context) NotModified()

Notmodified writes a 304 HTTP response

func (*Context) SetCookie

func (ctx *Context) SetCookie(cookie *http.Cookie)

SetCookie adds a cookie header to the response.

func (*Context) SetHeader

func (ctx *Context) SetHeader(hdr string, val string, unique bool)

SetHeader sets a response header. If `unique` is true, the current value of that header will be overwritten . If false, it will be appended.

func (*Context) SetSecureCookie

func (ctx *Context) SetSecureCookie(name string, val string, age int64)

func (*Context) Unauthorized

func (ctx *Context) Unauthorized()

Unauthorized writes a 401 HTTP response

func (*Context) WriteJSON

func (ctx *Context) WriteJSON(code, msg string, data ...interface{})

WriteJSON writes json data into the response object.

func (*Context) WriteString

func (ctx *Context) WriteString(content string)

WriteString writes string data into the response object.

func (*Context) WriteXml

func (ctx *Context) WriteXml(content string)

WriteXml writes string data into the response object.

type Duo

type Duo struct {
	Conn   map[string]*net.TCPConn
	Config *Config
	Logger *log.Logger
	// contains filtered or unexported fields
}

func AppDuo

func AppDuo() *Duo

Default Duo server

func NewDuo

func NewDuo() *Duo

func (*Duo) Fd

func (t *Duo) Fd(conn *net.TCPConn) string

Get the integer Unix file descriptor referencing the open file

func (*Duo) Middleware

func (t *Duo) Middleware(handler interface{})

Post adds a handler for the 'Via' TCP method for tcp.

func (*Duo) Pack

func (t *Duo) Pack(w io.Writer, data []byte) error

Pack is a utility function to read from the supplied Writer according to the Next protocol spec:

EF01[x][x][x][x][x][x][x][x][x]
    |  | (binary)          |
    |1-byte                | 1-byte
  ---------------------------
head size       data        crc

func (*Duo) Pipe

func (t *Duo) Pipe(conn *net.TCPConn)

func (*Duo) Run

func (t *Duo) Run(addr string)

func (*Duo) Unpack

func (t *Duo) Unpack(r io.Reader) ([]byte, error)

Unpack is a utility function to read from the supplied Reader according to the Next protocol spec:

EF01[x][x][x][x][x][x][x][x][x]
    |  | (binary)          |
    |1-byte                | 1-byte
  ---------------------------
head size       data        crc

func (*Duo) Via

func (t *Duo) Via(route string, handler interface{})

Post adds a handler for the 'Via' TCP method for tcp.

func (*Duo) Write

func (t *Duo) Write(conn *net.TCPConn, code byte, data ...[]byte)

type DuoContext

type DuoContext struct {
	Method byte
	Params []byte
	Duo    *Duo
	Fd     string
	// contains filtered or unexported fields
}

-------- Duo Context --------

func (*DuoContext) Write

func (ctx *DuoContext) Write(out []byte)

Writes data into the response object.

type Json

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

func NewJson

func NewJson() *Json

New returns a pointer to a new, empty `Json` object

func (*Json) Array

func (j *Json) Array() ([]interface{}, error)

Array type asserts to an `array`

func (*Json) Bool

func (j *Json) Bool() (bool, error)

Bool type asserts to `bool`

func (*Json) Bytes

func (j *Json) Bytes() ([]byte, error)

Bytes type asserts to `[]byte`

func (*Json) CheckGet

func (j *Json) CheckGet(key string) (*Json, bool)

CheckGet returns a pointer to a new `Json` object and a `bool` identifying success or failure

useful for chained operations when success is important:

if data, ok := js.Get("top_level").CheckGet("inner"); ok {
    log.Println(data)
}

func (*Json) Del

func (j *Json) Del(key string)

Del modifies `Json` map by deleting `key` if it is present.

func (*Json) Encode

func (j *Json) Encode() ([]byte, error)

Encode returns its marshaled data as `[]byte`

func (*Json) EncodePretty

func (j *Json) EncodePretty() ([]byte, error)

EncodePretty returns its marshaled data as `[]byte` with indentation

func (*Json) Float64

func (j *Json) Float64() (float64, error)

Float64 coerces into a float64

func (*Json) Get

func (j *Json) Get(key string) *Json

Get returns a pointer to a new `Json` object for `key` in its `map` representation

useful for chaining operations (to traverse a nested JSON):

js.Get("top_level").Get("dict").Get("value").Int()

func (*Json) GetIndex

func (j *Json) GetIndex(index int) *Json

GetIndex returns a pointer to a new `Json` object for `index` in its `array` representation

this is the analog to Get when accessing elements of a json array instead of a json object:

js.Get("top_level").Get("array").GetIndex(1).Get("key").Int()

func (*Json) GetPath

func (j *Json) GetPath(branch ...string) *Json

GetPath searches for the item as specified by the branch without the need to deep dive using Get()'s.

js.GetPath("top_level", "dict")

func (*Json) Int

func (j *Json) Int() (int, error)

Int coerces into an int

func (*Json) Int64

func (j *Json) Int64() (int64, error)

Int64 coerces into an int64

func (*Json) Interface

func (j *Json) Interface() interface{}

Interface returns the underlying data

func (*Json) Load

func (j *Json) Load(body []byte) (*Json, error)

Load returns a pointer to a new `Json` object after unmarshaling `body` bytes

func (*Json) Map

func (j *Json) Map() (map[string]interface{}, error)

Map type asserts to `map`

func (*Json) MarshalJSON

func (j *Json) MarshalJSON() ([]byte, error)

Implements the json.Marshaler interface.

func (*Json) MustArray

func (j *Json) MustArray(args ...[]interface{}) []interface{}

MustArray guarantees the return of a `[]interface{}` (with optional default)

useful when you want to interate over array values in a succinct manner:

for i, v := range js.Get("results").MustArray() {
	fmt.Println(i, v)
}

func (*Json) MustBool

func (j *Json) MustBool(args ...bool) bool

MustBool guarantees the return of a `bool` (with optional default)

useful when you explicitly want a `bool` in a single value return context:

myFunc(js.Get("param1").MustBool(), js.Get("optional_param").MustBool(true))

func (*Json) MustFloat64

func (j *Json) MustFloat64(args ...float64) float64

MustFloat64 guarantees the return of a `float64` (with optional default)

useful when you explicitly want a `float64` in a single value return context:

myFunc(js.Get("param1").MustFloat64(), js.Get("optional_param").MustFloat64(5.150))

func (*Json) MustInt

func (j *Json) MustInt(args ...int) int

MustInt guarantees the return of an `int` (with optional default)

useful when you explicitly want an `int` in a single value return context:

myFunc(js.Get("param1").MustInt(), js.Get("optional_param").MustInt(5150))

func (*Json) MustInt64

func (j *Json) MustInt64(args ...int64) int64

MustInt64 guarantees the return of an `int64` (with optional default)

useful when you explicitly want an `int64` in a single value return context:

myFunc(js.Get("param1").MustInt64(), js.Get("optional_param").MustInt64(5150))

func (*Json) MustMap

func (j *Json) MustMap(args ...map[string]interface{}) map[string]interface{}

MustMap guarantees the return of a `map[string]interface{}` (with optional default)

useful when you want to interate over map values in a succinct manner:

for k, v := range js.Get("dictionary").MustMap() {
	fmt.Println(k, v)
}

func (*Json) MustString

func (j *Json) MustString(args ...string) string

MustString guarantees the return of a `string` (with optional default)

useful when you explicitly want a `string` in a single value return context:

myFunc(js.Get("param1").MustString(), js.Get("optional_param").MustString("my_default"))

func (*Json) MustStringArray

func (j *Json) MustStringArray(args ...[]string) []string

MustStringArray guarantees the return of a `[]string` (with optional default)

useful when you want to interate over array values in a succinct manner:

for i, s := range js.Get("results").MustStringArray() {
	fmt.Println(i, s)
}

func (*Json) MustUint64

func (j *Json) MustUint64(args ...uint64) uint64

MustUInt64 guarantees the return of an `uint64` (with optional default)

useful when you explicitly want an `uint64` in a single value return context:

myFunc(js.Get("param1").MustUint64(), js.Get("optional_param").MustUint64(5150))

func (*Json) Set

func (j *Json) Set(key string, val interface{})

Set modifies `Json` map by `key` and `value` Useful for changing single key/value in a `Json` object easily.

func (*Json) SetPath

func (j *Json) SetPath(branch []string, val interface{})

SetPath modifies `Json`, recursively checking/creating map keys for the supplied path, and then finally writing in the value

func (*Json) String

func (j *Json) String() (string, error)

String type asserts to `string`

func (*Json) StringArray

func (j *Json) StringArray() ([]string, error)

StringArray type asserts to an `array` of `string`

func (*Json) Uint64

func (j *Json) Uint64() (uint64, error)

Uint64 coerces into an uint64

func (*Json) UnmarshalJSON

func (j *Json) UnmarshalJSON(p []byte) error

Implements the json.Unmarshaler interface.

type Logger

type Logger struct {
	Level int
	// contains filtered or unexported fields
}

A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.

func New

func New(out io.Writer, prefix string, flag int) *Logger

New creates a new Logger. The out variable sets the destination to which log data will be written. The prefix appears at the beginning of each generated log line. The flag argument defines the logging properties.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf is equivalent to l.Printf() followed by a call to os.Exit(1).

func (*Logger) Fatalln

func (l *Logger) Fatalln(v ...interface{})

Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).

func (*Logger) Flags

func (l *Logger) Flags() int

Flags returns the output flags for the logger.

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

func (*Logger) Output

func (l *Logger) Output(reqId string, lvl int, calldepth int, s string) error

Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.

func (*Logger) Panic

func (l *Logger) Panic(v ...interface{})

Panic is equivalent to l.Print() followed by a call to panic().

func (*Logger) Panicf

func (l *Logger) Panicf(format string, v ...interface{})

Panicf is equivalent to l.Printf() followed by a call to panic().

func (*Logger) Panicln

func (l *Logger) Panicln(v ...interface{})

Panicln is equivalent to l.Println() followed by a call to panic().

func (*Logger) Prefix

func (l *Logger) Prefix() string

Prefix returns the output prefix for the logger.

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Print.

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

Printf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Println

func (l *Logger) Println(v ...interface{})

Println calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Println.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int)

SetFlags sets the output flags for the logger.

func (*Logger) SetOutputLevel

func (l *Logger) SetOutputLevel(lvl int)

SetOutputLevel sets the output level for the logger.

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string)

SetPrefix sets the output prefix for the logger.

func (*Logger) Stack

func (l *Logger) Stack(v ...interface{})

func (*Logger) Stat

func (l *Logger) Stat() (stats []int64)

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

type MongoDB

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

func NewMongoDB

func NewMongoDB() *MongoDB

func (*MongoDB) Close

func (mongo *MongoDB) Close()

func (*MongoDB) InsertOrUpdate

func (mongo *MongoDB) InsertOrUpdate(collection string, buziKey string, buziValue interface{}, d interface{}, result interface{}) error

func (*MongoDB) Open

func (mongo *MongoDB) Open(url string, db string)

func (*MongoDB) Session

func (mongo *MongoDB) Session() *mgo.Session

type Mysql

type Mysql struct {
	Db *sql.DB
	Tx *sql.Tx
}

func NewMysql

func NewMysql() *Mysql

func (*Mysql) Begin

func (mysql *Mysql) Begin()

func (*Mysql) Close

func (mysql *Mysql) Close()

func (*Mysql) Commit

func (mysql *Mysql) Commit() error

func (*Mysql) Exec

func (mysql *Mysql) Exec(table, dml string, args ...interface{}) (interface{}, error)

DML for tabel, insert update delete operation. usage: mysql.Exec("users", "add", &addData) mysql.Exec("users", "up", &upData, &where) mysql.Exec("users", "del", &where)

func (*Mysql) Open

func (mysql *Mysql) Open(dsn string)

func (*Mysql) Ping

func (mysql *Mysql) Ping() error

func (*Mysql) Query

func (mysql *Mysql) Query(args ...interface{}) ([]interface{}, error)

func (*Mysql) Rollback

func (mysql *Mysql) Rollback() error

func (*Mysql) Row

func (mysql *Mysql) Row(args ...interface{}) (interface{}, error)

type Nsq

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

func NewNsq

func NewNsq() *Nsq

func (*Nsq) Open

func (n *Nsq) Open(addr string)

func (*Nsq) Publish

func (n *Nsq) Publish(topicName string, message []byte) error

func (*Nsq) Subscribe

func (n *Nsq) Subscribe(topicName, channelName string, hander nsq.HandlerFunc) error

type NsqMessage

type NsqMessage struct {
	*nsq.Message
}

type Redis

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

func NewRedis

func NewRedis() *Redis

func (*Redis) Bool

func (r *Redis) Bool(cmd string, args ...interface{}) (bool, error)

func (*Redis) Do

func (r *Redis) Do(cmd string, args ...interface{}) (interface{}, error)

func (*Redis) Int64

func (r *Redis) Int64(cmd string, args ...interface{}) (int64, error)

func (*Redis) Pool

func (r *Redis) Pool(server string, pwd ...interface{})

func (*Redis) String

func (r *Redis) String(cmd string, args ...interface{}) (string, error)

func (*Redis) StringMap

func (r *Redis) StringMap(cmd string, args ...interface{}) (map[string]string, error)

func (*Redis) Strings

func (r *Redis) Strings(cmd string, args ...interface{}) ([]string, error)

type Route

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

type Routes

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

func NewRoutes

func NewRoutes() *Routes

func (*Routes) Add

func (rs *Routes) Add(r string, method string, handler interface{})

func (*Routes) Match

func (s *Routes) Match(r, method string) *Route

type Server

type Server struct {
	Config *Config

	Logger *log.Logger
	Env    map[string]interface{}
	// contains filtered or unexported fields
}

func App

func App() *Server

Default server

func NewServer

func NewServer() *Server

func (*Server) Close

func (s *Server) Close()

Close stops server s.

func (*Server) Delete

func (s *Server) Delete(route string, handler interface{})

Delete adds a handler for the 'DELETE' http method for server s.

func (*Server) Get

func (s *Server) Get(route string, handler interface{})

Get adds a handler for the 'GET' http method for server s.

func (*Server) Handler

func (s *Server) Handler(route string, method string, handler http.Handler)

Adds a custom handler. Only for webserver mode. Will have no effect when running as FCGI or SCGI.

func (*Server) Match

func (s *Server) Match(method string, route string, handler interface{})

Match adds a handler for an arbitrary http method for server s.

func (*Server) Post

func (s *Server) Post(route string, handler interface{})

Post adds a handler for the 'POST' http method for server s.

func (*Server) Process

func (s *Server) Process(c http.ResponseWriter, req *http.Request)

Process invokes the routing system for server s

func (*Server) Put

func (s *Server) Put(route string, handler interface{})

Put adds a handler for the 'PUT' http method for server s.

func (*Server) Run

func (s *Server) Run(addr string)

Run starts the web application and serves HTTP requests for s

func (*Server) RunTLS

func (s *Server) RunTLS(addr string, config *tls.Config) error

RunTLS starts the web application and serves HTTPS requests for s.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(c http.ResponseWriter, req *http.Request)

ServeHTTP is the interface method for Go's http server package

func (*Server) SetLogger

func (s *Server) SetLogger(logger *log.Logger)

SetLogger sets the logger for server s

type Tcp

type Tcp struct {
	Conn   map[string]*net.TCPConn
	Config *Config
	Logger *log.Logger
	// contains filtered or unexported fields
}

func AppTcp

func AppTcp() *Tcp

Default Tcp server

func NewTcp

func NewTcp() *Tcp

func (*Tcp) Fd

func (t *Tcp) Fd(conn *net.TCPConn) string

Get the integer Unix file descriptor referencing the open file

func (*Tcp) Middleware

func (t *Tcp) Middleware(handler interface{})

Post adds a handler for the 'Via' TCP method for tcp.

func (*Tcp) Pack

func (t *Tcp) Pack(w io.Writer, data []byte) error

Pack is a utility function to read from the supplied Writer according to the Next protocol spec:

AA[x][x][x][x][x][x][x][x]55
  |  (int32) || (binary)
  |  4-byte  || N-byte
  ------------------------...
    size       data

func (*Tcp) Pipe

func (t *Tcp) Pipe(conn *net.TCPConn)

func (*Tcp) Run

func (t *Tcp) Run(addr string)

func (*Tcp) Unpack

func (t *Tcp) Unpack(r io.Reader) ([]byte, error)

Unpack is a utility function to read from the supplied Reader according to the Next protocol spec:

AA[x][x][x][x][x][x][x][x]55
  |  (int32) || (binary)
  |  4-byte  || N-byte
  ------------------------...
    size       data

func (*Tcp) Via

func (t *Tcp) Via(route string, handler interface{})

Post adds a handler for the 'Via' TCP method for tcp.

func (*Tcp) WriteJSON

func (t *Tcp) WriteJSON(conn *net.TCPConn, code, msg string, data ...interface{})

type TcpContext

type TcpContext struct {
	Method string
	Params map[string]string
	Tcp    *Tcp
	Fd     string
	// contains filtered or unexported fields
}

-------- Tcp Context --------

func (*TcpContext) WriteJSON

func (ctx *TcpContext) WriteJSON(code, msg string, data ...interface{})

WriteJSON writes json data into the response object.

type Xml

type Xml struct {
}

func NewXml

func NewXml() *Xml

New returns a pointer to a new, empty `Json` object

func (*Xml) ToMap

func (x *Xml) ToMap(xmlReader io.Reader) (m map[string]string, err error)

ToMap parses xml reading from xmlReader and returns the first-level sub-node key-value set, if the first-level sub-node contains child nodes, skip it.

func (*Xml) ToXML

func (x *Xml) ToXML(xmlWriter io.Writer, m map[string]string) (err error)

ToXML marshal map[string]string to xmlWriter with xml format, the root node name is xml.

NOTE: This function assumes the key of m map[string]string are legitimate xml name string
that does not contain the required escape character!

Jump to

Keyboard shortcuts

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