statping: Index | Files | Directories

package handlers

import ""

Package handlers contains the HTTP server along with the requests and routes. All HTTP related functions are in this package.

More info on:

// Statping // Copyright (C) 2018. Hunter Long and the project contributors // Written by Hunter Long <> and the project contributors // // // // The licenses for most software and other practical works are designed // to take away your freedom to share and change the works. By contrast, // the GNU General Public License is intended to guarantee your freedom to // share and change all versions of a program--to make sure it remains free // software for all its users. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <>.


Package Files

api.go cache.go checkin.go dashboard.go doc.go errors.go export.go function.go groups.go handlers.go incident.go index.go messages.go middleware.go notifications.go prometheus.go query.go routes.go scope.go services.go setup.go users.go


var (
    NewError = func(e error) Error {
        return Error{
            err:  e,
            code: http.StatusInternalServerError,
    NotFound = func(err error) Error {
        return Error{
            err:  errors.Wrap(err, "not found"),
            code: http.StatusNotFound,
    Unauthorized = func(e error) Error {
        return Error{
            err:  e,
            code: http.StatusUnauthorized,

func DecodeJSON Uses

func DecodeJSON(r *http.Request, obj interface{}) error

func ExecuteResponse Uses

func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}, redirect interface{})

ExecuteResponse will render a HTTP response for the front end user

func ExportSettings Uses

func ExportSettings() ([]byte, error)

ExportSettings will export a JSON file containing all of the settings below: - Core - Notifiers - Checkins - Users - Services - Groups - Messages

func GetID Uses

func GetID(r *http.Request) (int64, error)

func Gzip Uses

func Gzip(handler http.Handler) http.Handler

func IsAdmin Uses

func IsAdmin(r *http.Request) bool

IsAdmin returns true if the user session is an administrator

func IsFullAuthenticated Uses

func IsFullAuthenticated(r *http.Request) bool

IsFullAuthenticated returns true if the HTTP request is authenticated. You can set the environment variable GO_ENV=test to bypass the admin authenticate to the dashboard features.

func IsReadAuthenticated Uses

func IsReadAuthenticated(r *http.Request) bool

IsReadAuthenticated will allow Read Only authentication for some routes

func IsUser Uses

func IsUser(r *http.Request) bool

IsUser returns true if the user is registered

func PrometheusComment Uses

func PrometheusComment(comment string)

func PrometheusExportKey Uses

func PrometheusExportKey(keyName string, id int64, name string, value interface{})

func PrometheusKeyValue Uses

func PrometheusKeyValue(keyName string, value interface{})

func PrometheusNoIDExportKey Uses

func PrometheusNoIDExportKey(keyName string, name string, value interface{})

func RespondError Uses

func RespondError(w http.ResponseWriter, err Error)

func Router Uses

func Router() *mux.Router

Router returns all of the routes used in Statping. Server will use static assets if the 'assets' directory is found in the root directory.

func RunHTTPServer Uses

func RunHTTPServer(ip string, port int) error

RunHTTPServer will start a HTTP server on a specific IP and port

func SafeJson Uses

func SafeJson(val reflect.Value, scope string) map[string]interface{}

func ScopeName Uses

func ScopeName(r *http.Request) string

type Cacher Uses

type Cacher interface {
    Get(key string) []byte
    Delete(key string)
    Set(key string, content []byte, duration time.Duration)
    List() map[string]Item
var CacheStorage Cacher

type CustomResponseWriter Uses

type CustomResponseWriter struct {
    // contains filtered or unexported fields

func NewCustomResponseWriter Uses

func NewCustomResponseWriter() *CustomResponseWriter

func (*CustomResponseWriter) Header Uses

func (w *CustomResponseWriter) Header() http.Header

func (*CustomResponseWriter) Write Uses

func (w *CustomResponseWriter) Write(b []byte) (int, error)

func (*CustomResponseWriter) WriteHeader Uses

func (w *CustomResponseWriter) WriteHeader(statusCode int)

type Error Uses

type Error struct {
    // contains filtered or unexported fields

func (Error) Error Uses

func (e Error) Error() string

type ExportData Uses

type ExportData struct {
    Core      *core.Core          `json:"core"`
    Services  []services.Service  `json:"services"`
    Messages  []*messages.Message `json:"messages"`
    Checkins  []*checkins.Checkin `json:"checkins"`
    Users     []*users.User       `json:"users"`
    Groups    []*groups.Group     `json:"groups"`
    Notifiers []core.AllNotifiers `json:"notifiers"`

type Item Uses

type Item struct {
    Content    []byte
    Expiration int64

Item is a cached reference

func (Item) Expired Uses

func (item Item) Expired() bool

Expired returns true if the item has expired.

type JwtClaim Uses

type JwtClaim struct {
    Username string `json:"username"`
    Admin    bool   `json:"admin"`

type Storage Uses

type Storage struct {
    // contains filtered or unexported fields

Storage mecanism for caching strings in memory

func NewStorage Uses

func NewStorage() *Storage

NewStorage creates a new in memory CacheStorage

func (Storage) Delete Uses

func (s Storage) Delete(key string)

func (Storage) Get Uses

func (s Storage) Get(key string) []byte

Get a cached content by key

func (Storage) List Uses

func (s Storage) List() map[string]Item

func (Storage) Lock Uses

func (s Storage) Lock()

func (Storage) Set Uses

func (s Storage) Set(key string, content []byte, duration time.Duration)

Set a cached content by key

func (Storage) StopRoutine Uses

func (s Storage) StopRoutine()

func (Storage) Unlock Uses

func (s Storage) Unlock()


graphqlgo:generate go run

Package handlers imports 40 packages (graph) and is imported by 2 packages. Updated 2020-03-26. Refresh now. Tools for package owners.