webapp

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Common
	ErrBadRequest = NewWebError(http.StatusBadRequest, "Bad request")
	ErrNotNull    = NewWebError(http.StatusBadRequest, "Null value")
	ErrPrimaryKey = NewWebError(http.StatusForbidden, "Primarykey voilated")
	ErrUnique     = NewWebError(http.StatusForbidden, "Value should be unique")
	ErrNotFound   = NewWebError(http.StatusNotFound, "Not found")
	// Project
	ErrProjectID            = NewWebError(http.StatusBadRequest, "Bad project id")
	ErrProjectNameEmpty     = NewWebError(http.StatusBadRequest, "Empty project name")
	ErrProjectNameTooLong   = NewWebError(http.StatusBadRequest, "Project name too long")
	ErrProjectNotFound      = NewWebError(http.StatusNotFound, "Project not found")
	ErrDuplicateProjectName = NewWebError(http.StatusForbidden, "Duplicate project name")
	ErrDuplicateProjectUser = NewWebError(http.StatusForbidden, "Duplicate user to project")
	ErrProjectUniversalUser = NewWebError(http.StatusForbidden, "Cannot add universal user to project")
	// User
	ErrUserID            = NewWebError(http.StatusBadRequest, "Bad user id")
	ErrUserNameEmpty     = NewWebError(http.StatusBadRequest, "Empty user name")
	ErrUserNameTooLong   = NewWebError(http.StatusBadRequest, "User name too long")
	ErrUserEmail         = NewWebError(http.StatusBadRequest, "Bad user email")
	ErrUserEmailEmpty    = NewWebError(http.StatusBadRequest, "Empty user email")
	ErrUserPhone         = NewWebError(http.StatusBadRequest, "Bad user phone format")
	ErrUserPhoneLen      = NewWebError(http.StatusBadRequest, "Bad user phone length")
	ErrUserNotFound      = NewWebError(http.StatusNotFound, "User not found")
	ErrDuplicateUserName = NewWebError(http.StatusForbidden, "Duplicate user name")
	// Rule
	ErrRuleID                   = NewWebError(http.StatusBadRequest, "Bad rule id")
	ErrRulePattern              = NewWebError(http.StatusBadRequest, "Bad rule pattern")
	ErrRulePatternEmpty         = NewWebError(http.StatusBadRequest, "Empty rule pattern")
	ErrRulePatternTooLong       = NewWebError(http.StatusBadRequest, "Rule pattern too long")
	ErrRulePatternContainsSpace = NewWebError(http.StatusBadRequest, "Space found in rule pattern")
	ErrRuleWhen                 = NewWebError(http.StatusBadRequest, "Bad rule condition")
	ErrDuplicateRulePattern     = NewWebError(http.StatusForbidden, "Duplicate rule pattern")
	ErrRuleNotFound             = NewWebError(http.StatusNotFound, "Rule not found")
	ErrRuleNoCondition          = NewWebError(http.StatusBadRequest, "No condition specified")
	ErrRuleThresholdMaxRequired = NewWebError(http.StatusBadRequest, "ThresholdMax is required")
	ErrRuleThresholdMinRequired = NewWebError(http.StatusBadRequest, "ThresholdMin is required")
	// Metric
	ErrMetricNotFound = NewWebError(http.StatusNotFound, "Metric not found")
)

Errors

Functions

func Init

func Init(c *config.Config, d *storage.DB)

Init globals.

func RequestBind

func RequestBind(r *http.Request, v interface{}) error

RequestBind binds request data into value.

func ResponseError

func ResponseError(w http.ResponseWriter, err *WebError) error

ResponseError writes WebError as response.

func ResponseJSON

func ResponseJSON(w http.ResponseWriter, code int, v interface{}) error

ResponseJSON encodes value to json and write as response.

func ResponseJSONOK

func ResponseJSONOK(w http.ResponseWriter, v interface{}) error

ResponseJSONOK writes ok response.

func Start

func Start(c *config.Config, d *storage.DB)

Start http server.

Types

type WebError

type WebError struct {
	// HTTP status code
	Code int `json:"code"`
	// Message
	Msg string `json:"msg"`
}

WebError is errors for web operations.

func NewUnexceptedWebError

func NewUnexceptedWebError(err error) *WebError

NewUnexceptedWebError returns an unexcepted WebError.

func NewWebError

func NewWebError(code int, text string) *WebError

NewWebError creates a WebError.

func (*WebError) Error

func (err *WebError) Error() string

Error returns the string format of the WebError.

Jump to

Keyboard shortcuts

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