webapp

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2017 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package webapp implements a simple http web server to visualize detection results and to manage alert rules.

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")
	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")
	ErrProjectUniversalWebHook = NewWebError(http.StatusForbidden, "Cannot add universal webhook to project")
	ErrDuplicateProjectWebHook = NewWebError(http.StatusForbidden, "Duplicate webhook to project")

	// User
	ErrUserID            = NewWebError(http.StatusBadRequest, "Bad user id")
	ErrUserNotFound      = NewWebError(http.StatusNotFound, "User not found")
	ErrDuplicateUserName = NewWebError(http.StatusForbidden, "Duplicate user name")

	// WebHook
	ErrWebHookID            = NewWebError(http.StatusBadRequest, "Bad webhook id")
	ErrWebHookNotFound      = NewWebError(http.StatusNotFound, "WebHook not found")
	ErrDuplicateWebHookName = NewWebError(http.StatusForbidden, "Duplicate webhook name")

	// Rule
	ErrRuleID               = NewWebError(http.StatusBadRequest, "Bad rule id")
	ErrDuplicateRulePattern = NewWebError(http.StatusForbidden, "Duplicate rule pattern")
	ErrRuleNotFound         = NewWebError(http.StatusNotFound, "Rule not found")
	ErrRuleNoCondition      = NewWebError(http.StatusBadRequest, "No condition specified")
	ErrRuleNoComment        = NewWebError(http.StatusBadRequest, "No rule comment")
	ErrRuleCommentNotValid  = NewWebError(http.StatusBadRequest, "Rule comment is not valid, empty?")
	ErrRuleUpdateFailed     = NewWebError(http.StatusBadRequest, "Failed to update rule")
	// Metric
	ErrMetricNotFound = NewWebError(http.StatusNotFound, "Metric not found")
	// Event
	ErrEventPast      = NewWebError(http.StatusBadRequest, "Bad event time past")
	ErrEventTimeRange = NewWebError(http.StatusBadRequest, "Bad event time range")
)

Errors

Functions

func Init

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

Init globals.

func Logger added in v0.2.5

func Logger(handler http.Handler) http.Handler

Logger output webapp visited infomation

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, f *filter.Filter)

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 NewValidationWebError added in v0.0.7

func NewValidationWebError(err error) *WebError

NewValidationWebError creates a validation WebError from error.

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