Documentation ¶
Overview ¶
Provides an HTTP API exposing many components of Kapacitor.
Index ¶
- Constants
- Variables
- func HttpError(w http.ResponseWriter, err string, pretty bool, code int)
- func MarshalJSON(v interface{}, pretty bool) []byte
- type Config
- type Handler
- type Route
- type ServeMux
- func (mux *ServeMux) Deregister(pattern string)
- func (mux *ServeMux) Handle(pattern string, handler http.Handler) error
- func (mux *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) error
- func (mux *ServeMux) Handler(r *http.Request) (h http.Handler, pattern string)
- func (mux *ServeMux) Patterns() []string
- func (mux *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Service
Constants ¶
const (
APIRoot = "/api/v1"
)
Variables ¶
var DefaultServeMux = NewServeMux()
DefaultServeMux is the default ServeMux used by Serve.
Functions ¶
func HttpError ¶
func HttpError(w http.ResponseWriter, err string, pretty bool, code int)
HttpError writes an error to the client in a standard format.
func MarshalJSON ¶
MarshalJSON will marshal v to JSON. Pretty prints if pretty is true.
Types ¶
type Config ¶
type Config struct { BindAddress string `toml:"bind-address"` AuthEnabled bool `toml:"auth-enabled"` LogEnabled bool `toml:"log-enabled"` WriteTracing bool `toml:"write-tracing"` PprofEnabled bool `toml:"pprof-enabled"` HttpsEnabled bool `toml:"https-enabled"` HttpsCertificate string `toml:"https-certificate"` }
type Handler ¶
type Handler struct { Version string MetaStore interface { Database(name string) (*meta.DatabaseInfo, error) Authenticate(username, password string) (ui *meta.UserInfo, err error) Users() ([]meta.UserInfo, error) } PointsWriter interface { WritePoints(p *cluster.WritePointsRequest) error } Logger *log.Logger WriteTrace bool // Detailed logging of write path // contains filtered or unexported fields }
Handler represents an HTTP handler for the Kapacitor API server.
func NewHandler ¶
func NewHandler(requireAuthentication, loggingEnabled, writeTrace bool, statMap *expvar.Map, l *log.Logger) *Handler
NewHandler returns a new instance of handler with routes.
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
What follows is an copy of golang's built in ServeMux with a few modifications:
- An error is returned instead of a panics on registering handlers.
- A delete method has been added to remove handlers.
- Removed 'Helpful Behavior' of adding redirects automatically
ServeMux is an HTTP request multiplexer. It matches the URL of each incoming request against a list of registered patterns and calls the handler for the pattern that most closely matches the URL.
Patterns name fixed, rooted paths, like "/favicon.ico", or rooted subtrees, like "/images/" (note the trailing slash). Longer patterns take precedence over shorter ones, so that if there are handlers registered for both "/images/" and "/images/thumbnails/", the latter handler will be called for paths beginning "/images/thumbnails/" and the former will receive requests for any other paths in the "/images/" subtree.
Note that since a pattern ending in a slash names a rooted subtree, the pattern "/" matches all paths not matched by other registered patterns, not just the URL with Path == "/".
Patterns may optionally begin with a host name, restricting matches to URLs on that host only. Host-specific patterns take precedence over general patterns, so that a handler might register for the two patterns "/codesearch" and "codesearch.google.com/" without also taking over requests for "http://www.google.com/".
ServeMux also takes care of sanitizing the URL request path, redirecting any request containing . or .. elements to an equivalent .- and ..-free URL.
func (*ServeMux) Deregister ¶
func (*ServeMux) Handle ¶
Handle registers the handler for the given pattern. If a handler already exists for pattern an error is returned.
func (*ServeMux) HandleFunc ¶
func (mux *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) error
HandleFunc registers the handler function for the given pattern.
func (*ServeMux) Handler ¶
Handler returns the handler to use for the given request, consulting r.Method, r.Host, and r.URL.Path. It always returns a non-nil handler. If the path is not in its canonical form, the handler will be an internally-generated handler that redirects to the canonical path.
Handler also returns the registered pattern that matches the request or, in the case of internally-generated redirects, the pattern that will match after following the redirect.
If there is no registered handler that applies to the request, Handler returns a “page not found” handler and an empty pattern.