app

package
v0.0.0-...-aaac7d5 Latest Latest
Warning

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

Go to latest
Published: May 6, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest          = NewStatusError(http.StatusBadRequest, "bad request")
	ErrNotFound            = NewStatusError(http.StatusNotFound, "not found")
	ErrMethodNotAllowed    = NewStatusError(http.StatusMethodNotAllowed, "method not allowed")
	ErrInternalServerError = NewStatusError(http.StatusInternalServerError, "internal server error")

	ErrBucketNotFound = errors.New("Bucket not found")
)

definded error

View Source
var Db *dbHelper

Db is a single instance of dbHelper

Functions

func HandleRestful

func HandleRestful(pattern string, fn func() IController)

func InitDb

func InitDb(dbPath string) error

func Log

func Log(lv LogLevel, e interface{})

func ResetController

func ResetController(c IController, w http.ResponseWriter, r *http.Request)

func Run

func Run(cfg Config)

Run is a function named Run

Types

type ApiStatusError

type ApiStatusError struct {
	*StatusError
}

func NewApiStatusError

func NewApiStatusError(status int, message string) *ApiStatusError

type Config

type Config struct {
	// User defined
	Port   string
	DbPath string

	// App need
	Routers map[string]func() IController
}

Config is a struct named Config

type Controller

type Controller struct {
	W http.ResponseWriter
	R *http.Request
	// contains filtered or unexported fields
}

Controller is a struct named Controller

func (*Controller) Delete

func (this *Controller) Delete() error

func (*Controller) Get

func (this *Controller) Get() error

func (*Controller) JsonRender

func (this *Controller) JsonRender(status int, message string, data interface{}) error

func (*Controller) JsonSuccess

func (this *Controller) JsonSuccess(data interface{}) error

func (*Controller) MethodNotAllowed

func (this *Controller) MethodNotAllowed() error

func (*Controller) ParseJsonBody

func (this *Controller) ParseJsonBody(data interface{}) (err error)

func (*Controller) Post

func (this *Controller) Post() error

func (*Controller) Put

func (this *Controller) Put() error

func (*Controller) QueryGet

func (this *Controller) QueryGet(key string) string

func (*Controller) Reset

func (this *Controller) Reset(w http.ResponseWriter, r *http.Request)

Reset reset controller for handle one request

type IController

type IController interface {
	// reset rw of one context
	Reset(http.ResponseWriter, *http.Request)

	// RESTful
	Get() error
	Post() error
	Put() error
	Delete() error
}

IController is a interface named IController

type LogLevel

type LogLevel int
const (
	LOG_LV_SUCC LogLevel = iota
	LOG_LV_INFO
	LOG_LV_FAIL
)

type Model

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

func NewModel

func NewModel(bucket string) *Model

func (*Model) Delete

func (this *Model) Delete(key string) (err error)

func (*Model) Get

func (this *Model) Get(key string, data interface{}) (ok bool, err error)

func (*Model) Keys

func (this *Model) Keys() (keys []string, err error)

func (*Model) Put

func (this *Model) Put(key string, data interface{}) (err error)

type StatusError

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

func NewStatusError

func NewStatusError(status int, message string) *StatusError

func (*StatusError) Error

func (this *StatusError) Error() string

func (*StatusError) NewMessage

func (this *StatusError) NewMessage(message interface{}) *StatusError

func (*StatusError) NewMessageSpf

func (this *StatusError) NewMessageSpf(args ...interface{}) *StatusError

Jump to

Keyboard shortcuts

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