rest

package
v0.0.0-...-b0cd610 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2017 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RESTMethodOrds = map[string]string{
	"GET":    "0",
	"POST":   "1",
	"PUT":    "2",
	"DELETE": "3",
}
View Source
var StartTime = time.Now()

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetFS

func AssetFS() *assetfs.AssetFS

AssetFS returns the assetfs.AssetFS "filesystem" that holds static HTTP resources (css/html/js/images, etc) for the web UI.

Users might introduce their own static HTTP resources and override resources from AssetFS() with their own resource lookup chaining.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func DiagGetPProf

func DiagGetPProf(w http.ResponseWriter, profile string, debug int)

func DocIDLookup

func DocIDLookup(req *http.Request) string

func ExtractSourceTypeName

func ExtractSourceTypeName(req *http.Request, indexDef *cbgt.IndexDef, indexName string) (string, string)

func IndexNameLookup

func IndexNameLookup(req *http.Request) string

func InitRESTRouter

func InitRESTRouter(r *mux.Router, versionMain string,
	mgr *cbgt.Manager, staticDir, staticETag string,
	mr *cbgt.MsgRing,
	assetDir func(name string) ([]string, error),
	asset func(name string) ([]byte, error)) (
	*mux.Router, map[string]RESTMeta, error)

InitRESTRouter initializes a mux.Router with REST API routes.

func InitRESTRouterEx

func InitRESTRouterEx(r *mux.Router, versionMain string,
	mgr *cbgt.Manager, staticDir, staticETag string,
	mr *cbgt.MsgRing,
	assetDir func(name string) ([]string, error),
	asset func(name string) ([]byte, error),
	options map[string]interface{}) (
	*mux.Router, map[string]RESTMeta, error)

InitRESTRouter initializes a mux.Router with REST API routes with extra option.

func InitStaticRouter

func InitStaticRouter(r *mux.Router, staticDir, staticETag string,
	pages []string, pagesHandler http.Handler) *mux.Router

InitStaticRouter adds static HTTP resource routes to a router.

func InitStaticRouterEx

func InitStaticRouterEx(r *mux.Router, staticDir, staticETag string,
	pages []string, pagesHandler http.Handler,
	mgr *cbgt.Manager) *mux.Router

InitStaticRouterEx is like InitStaticRouter, but with optional manager parameter for more options.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func MustEncode

func MustEncode(w io.Writer, i interface{})

func MuxVariableLookup

func MuxVariableLookup(req *http.Request, name string) string

func NewRESTRouter

func NewRESTRouter(versionMain string, mgr *cbgt.Manager,
	staticDir, staticETag string, mr *cbgt.MsgRing,
	assetDir func(name string) ([]string, error),
	asset func(name string) ([]byte, error)) (
	*mux.Router, map[string]RESTMeta, error)

NewRESTRouter creates a mux.Router initialized with the REST API and web UI routes. See also InitStaticRouter and InitRESTRouter if you need finer control of the router initialization.

func PIndexNameLookup

func PIndexNameLookup(req *http.Request) string

func PIndexTypesInitRouter

func PIndexTypesInitRouter(r *mux.Router, phase string,
	mgr *cbgt.Manager)

PIndexTypesInitRouter initializes a mux.Router with the REST API routes provided by registered pindex types.

func PathFocusName

func PathFocusName(path string) string

PathFocusName return the focus name of path spec. For example, given a path spec of "/api/index/{indexName}", the focus name result is "indexName". A focus name of "" is valid.

func RESTGetRuntimeArgs

func RESTGetRuntimeArgs(w http.ResponseWriter, r *http.Request)

func RESTGetRuntimeStats

func RESTGetRuntimeStats(w http.ResponseWriter, r *http.Request)

func RESTGetRuntimeStatsMem

func RESTGetRuntimeStatsMem(w http.ResponseWriter, r *http.Request)

func RESTPostRuntimeGC

func RESTPostRuntimeGC(w http.ResponseWriter, r *http.Request)

func RESTProfileCPU

func RESTProfileCPU(w http.ResponseWriter, r *http.Request)

To start a cpu profiling...

curl -X POST http://127.0.0.1:9090/api/runtime/profile/cpu -d secs=5

To analyze a profiling...

go tool pprof [program-binary] run-cpu.pprof

func RESTProfileMemory

func RESTProfileMemory(w http.ResponseWriter, r *http.Request)

To grab a memory profiling...

curl -X POST http://127.0.0.1:9090/api/runtime/profile/memory

To analyze a profiling...

go tool pprof [program-binary] run-memory.pprof

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func RewriteURL

func RewriteURL(to string, h http.Handler) http.Handler

RewriteURL is a helper function that returns a URL path rewriter HandlerFunc, rewriting the URL path to a provided "to" string.

func ShowError

func ShowError(w http.ResponseWriter, r *http.Request,
	msg string, code int)

func WriteManagerStatsJSON

func WriteManagerStatsJSON(mgr *cbgt.Manager, w io.Writer,
	indexName string) error

WriteManagerStatsJSON writes JSON stats for a manager, and is optionally focus'able on a particular indexName.

Types

type CfgGetHandler

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

CfgGetHandler is a REST handler that retrieves the contents of the Cfg system.

func NewCfgGetHandler

func NewCfgGetHandler(mgr *cbgt.Manager) *CfgGetHandler

func (*CfgGetHandler) ServeHTTP

func (h *CfgGetHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type CfgRefreshHandler

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

CfgRefreshHandler is a REST handler that processes a request for the manager/node to refresh its cached snapshot of the Cfg system contents.

func NewCfgRefreshHandler

func NewCfgRefreshHandler(mgr *cbgt.Manager) *CfgRefreshHandler

func (*CfgRefreshHandler) ServeHTTP

func (h *CfgRefreshHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type CountHandler

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

CountHandler is a REST handler for counting documents/entries in an index.

func NewCountHandler

func NewCountHandler(mgr *cbgt.Manager) *CountHandler

func (*CountHandler) RESTOpts

func (h *CountHandler) RESTOpts(opts map[string]string)

func (*CountHandler) ServeHTTP

func (h *CountHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type CountPIndexHandler

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

CountPIndexHandler is a REST handler for counting the documents/entries in a pindex.

func NewCountPIndexHandler

func NewCountPIndexHandler(mgr *cbgt.Manager) *CountPIndexHandler

func (*CountPIndexHandler) ServeHTTP

func (h *CountPIndexHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type CountResponseWriter

type CountResponseWriter struct {
	ResponseWriter  http.ResponseWriter
	TotBytesWritten uint64
}

A CountResponseWriter is a wrapper of an http.ResponseWriter that counts the bytes written.

func (*CountResponseWriter) CloseNotify

func (cw *CountResponseWriter) CloseNotify() <-chan bool

func (*CountResponseWriter) Header

func (cw *CountResponseWriter) Header() http.Header

func (*CountResponseWriter) Write

func (cw *CountResponseWriter) Write(p []byte) (n int, err error)

func (*CountResponseWriter) WriteHeader

func (cw *CountResponseWriter) WriteHeader(n int)

type CreateIndexHandler

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

CreateIndexHandler is a REST handler that processes an index creation request.

func NewCreateIndexHandler

func NewCreateIndexHandler(mgr *cbgt.Manager) *CreateIndexHandler

func (*CreateIndexHandler) RESTOpts

func (h *CreateIndexHandler) RESTOpts(opts map[string]string)

func (*CreateIndexHandler) ServeHTTP

func (h *CreateIndexHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type DeleteIndexHandler

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

DeleteIndexHandler is a REST handler that processes an index deletion request.

func NewDeleteIndexHandler

func NewDeleteIndexHandler(mgr *cbgt.Manager) *DeleteIndexHandler

func (*DeleteIndexHandler) RESTOpts

func (h *DeleteIndexHandler) RESTOpts(opts map[string]string)

func (*DeleteIndexHandler) ServeHTTP

func (h *DeleteIndexHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type DiagGetHandler

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

DiagGetHandler is a REST handler that retrieves diagnostic information for a node.

func NewDiagGetHandler

func NewDiagGetHandler(versionMain string,
	mgr *cbgt.Manager, mr *cbgt.MsgRing,
	assetDir func(name string) ([]string, error),
	asset func(name string) ([]byte, error)) *DiagGetHandler

func (*DiagGetHandler) ServeHTTP

func (h *DiagGetHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type ETagFileHandler

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

func (ETagFileHandler) ServeHTTP

func (mfh ETagFileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type GetIndexHandler

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

GetIndexHandler is a REST handler for retrieving an index definition.

func NewGetIndexHandler

func NewGetIndexHandler(mgr *cbgt.Manager) *GetIndexHandler

func (*GetIndexHandler) RESTOpts

func (h *GetIndexHandler) RESTOpts(opts map[string]string)

func (*GetIndexHandler) ServeHTTP

func (h *GetIndexHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type GetPIndexHandler

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

GetPIndexHandler is a REST handler for retrieving information on a pindex.

func NewGetPIndexHandler

func NewGetPIndexHandler(mgr *cbgt.Manager) *GetPIndexHandler

func (*GetPIndexHandler) ServeHTTP

func (h *GetPIndexHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type HandlerWithRESTMeta

type HandlerWithRESTMeta struct {
	RESTMeta *RESTMeta
	// contains filtered or unexported fields
}

HandlerWithRESTMeta wrapper associates a http.Handler with RESTMeta information.

func (*HandlerWithRESTMeta) ServeHTTP

func (h *HandlerWithRESTMeta) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type IndexControlHandler

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

IndexControlHandler is a REST handler for processing admin control requests on an index.

func NewIndexControlHandler

func NewIndexControlHandler(mgr *cbgt.Manager, control string,
	allowedOps map[string]bool) *IndexControlHandler

func (*IndexControlHandler) RESTOpts

func (h *IndexControlHandler) RESTOpts(opts map[string]string)

func (*IndexControlHandler) ServeHTTP

func (h *IndexControlHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type ListIndexHandler

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

ListIndexHandler is a REST handler for list indexes.

func NewListIndexHandler

func NewListIndexHandler(mgr *cbgt.Manager) *ListIndexHandler

func (*ListIndexHandler) ServeHTTP

func (h *ListIndexHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type ListPIndexHandler

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

ListPIndexHandler is a REST handler for listing pindexes.

func NewListPIndexHandler

func NewListPIndexHandler(mgr *cbgt.Manager) *ListPIndexHandler

func (*ListPIndexHandler) ServeHTTP

func (h *ListPIndexHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type LogGetHandler

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

LogGetHandler is a REST handler that retrieves recent log messages.

func NewLogGetHandler

func NewLogGetHandler(
	mgr *cbgt.Manager, mr *cbgt.MsgRing) *LogGetHandler

func (*LogGetHandler) ServeHTTP

func (h *LogGetHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type ManagerHandler

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

ManagerHandler is a REST handler that returns runtime config information about a manager/node.

func NewManagerHandler

func NewManagerHandler(mgr *cbgt.Manager) *ManagerHandler

func (*ManagerHandler) ServeHTTP

func (h *ManagerHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type ManagerKickHandler

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

ManagerKickHandler is a REST handler that processes a request to kick a manager.

func NewManagerKickHandler

func NewManagerKickHandler(mgr *cbgt.Manager) *ManagerKickHandler

func (*ManagerKickHandler) ServeHTTP

func (h *ManagerKickHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type ManagerMetaHandler

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

ManagerMetaHandler is a REST handler that returns metadata about a manager/node.

func NewManagerMetaHandler

func NewManagerMetaHandler(mgr *cbgt.Manager,
	meta map[string]RESTMeta) *ManagerMetaHandler

func (*ManagerMetaHandler) ServeHTTP

func (h *ManagerMetaHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type ManagerOptions

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

ManagerOptions is a REST handler that sets the managerOptions

func NewManagerOptions

func NewManagerOptions(mgr *cbgt.Manager) *ManagerOptions

func (*ManagerOptions) ServeHTTP

func (h *ManagerOptions) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type MetaDesc

type MetaDesc struct {
	Description     string            `json:"description"`
	StartSample     interface{}       `json:"startSample"`
	StartSampleDocs map[string]string `json:"startSampleDocs"`
}

MetaDesc represents a part of the JSON of a ManagerMetaHandler REST response.

type MetaDescIndex

type MetaDescIndex struct {
	MetaDesc

	CanCount bool `json:"canCount"`
	CanQuery bool `json:"canQuery"`

	QuerySamples interface{} `json:"querySamples"`
	QueryHelp    string      `json:"queryHelp"`

	UI map[string]string `json:"ui"`
}

MetaDescSource represents the index-type parts of the JSON of a ManagerMetaHandler REST response.

type MetaDescSource

type MetaDescSource MetaDesc

MetaDescSource represents the source-type/feed-type parts of the JSON of a ManagerMetaHandler REST response.

type NoopHandler

type NoopHandler struct{}

NoopHandler is a REST handler that returns nothing.

func (*NoopHandler) ServeHTTP

func (h *NoopHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type QueryHandler

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

QueryHandler is a REST handler for querying an index.

func NewQueryHandler

func NewQueryHandler(mgr *cbgt.Manager, pathStats *RESTPathStats) *QueryHandler

func (*QueryHandler) RESTOpts

func (h *QueryHandler) RESTOpts(opts map[string]string)

func (*QueryHandler) ServeHTTP

func (h *QueryHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type QueryPIndexHandler

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

QueryPIndexHandler is a REST handler for querying a pindex.

func NewQueryPIndexHandler

func NewQueryPIndexHandler(mgr *cbgt.Manager) *QueryPIndexHandler

func (*QueryPIndexHandler) ServeHTTP

func (h *QueryPIndexHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type RESTCfg

type RESTCfg struct {
	Status            string             `json:"status"`
	IndexDefs         *cbgt.IndexDefs    `json:"indexDefs"`
	IndexDefsCAS      uint64             `json:"indexDefsCAS"`
	IndexDefsErr      error              `json:"indexDefsErr"`
	NodeDefsWanted    *cbgt.NodeDefs     `json:"nodeDefsWanted"`
	NodeDefsWantedCAS uint64             `json:"nodeDefsWantedCAS"`
	NodeDefsWantedErr error              `json:"nodeDefsWantedErr"`
	NodeDefsKnown     *cbgt.NodeDefs     `json:"nodeDefsKnown"`
	NodeDefsKnownCAS  uint64             `json:"nodeDefsKnownCAS"`
	NodeDefsKnownErr  error              `json:"nodeDefsKnownErr"`
	PlanPIndexes      *cbgt.PlanPIndexes `json:"planPIndexes"`
	PlanPIndexesCAS   uint64             `json:"planPIndexesCAS"`
	PlanPIndexesErr   error              `json:"planPIndexesErr"`
}

type RESTFocusStats

type RESTFocusStats struct {
	TotRequest        uint64
	TotRequestTimeNS  uint64
	TotRequestErr     uint64 `json:"TotRequestErr,omitempty"`
	TotRequestSlow    uint64 `json:"TotRequestSlow,omitempty"`
	TotRequestTimeout uint64 `json:"TotRequestTimeout,omitempty"`
	TotResponseBytes  uint64 `json:"TotResponseBytes,omitempty"`
}

RESTFocusStats represents stats for a targeted or "focused" REST endpoint, like "/api/index/beer-sample/query".

func (*RESTFocusStats) AtomicCopyTo

func (s *RESTFocusStats) AtomicCopyTo(r *RESTFocusStats)

AtomicCopyTo copies stats from s to r (from source to result).

type RESTMeta

type RESTMeta struct {
	Path   string // The path spec, including any optional prefix.
	Method string
	Opts   map[string]string
}

RESTMeta represents the metadata of a REST API endpoint and is used for auto-generated REST API documentation.

type RESTOpts

type RESTOpts interface {
	RESTOpts(map[string]string)
}

RESTOpts interface may be optionally implemented by REST API handlers to provide even more information for auto-generated REST API documentation.

type RESTPathStats

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

RESTPathStats represents the stats for a REST path spec. A REST path spec, like "/api/index" or "/api/index/{indexName}/query", can have an optional focusName (i.e., "indexName"), which can in turn have multiple runtime focus values, like "beer-sample", "indexForCRM", "".

func (*RESTPathStats) FocusStats

func (s *RESTPathStats) FocusStats(focusVal string) *RESTFocusStats

FocusStats returns the RESTFocusStats for a given focus value (like "beer-sample"), and is a concurrent safe method. The returned RESTFocusStats should only be accessed via sync/atomic functions.

func (*RESTPathStats) FocusValues

func (s *RESTPathStats) FocusValues() (rv []string)

FocusValues returns the focus value strings, like ["beer-sample", "indexForCRM", "wikiIndexTitles"].

type RuntimeGetHandler

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

RuntimeGetHandler is a REST handler for runtime GET endpoint.

func NewRuntimeGetHandler

func NewRuntimeGetHandler(
	versionMain string, mgr *cbgt.Manager) *RuntimeGetHandler

func (*RuntimeGetHandler) ServeHTTP

func (h *RuntimeGetHandler) ServeHTTP(
	w http.ResponseWriter, r *http.Request)

type SourcePartitionSeqsHandler

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

SourcePartitionSeqsHandler is a REST handler for retrieving the partition seqs from the data source for an index.

func NewSourcePartitionSeqsHandler

func NewSourcePartitionSeqsHandler(mgr *cbgt.Manager) *SourcePartitionSeqsHandler

func (*SourcePartitionSeqsHandler) RESTOpts

func (h *SourcePartitionSeqsHandler) RESTOpts(opts map[string]string)

func (*SourcePartitionSeqsHandler) ServeHTTP

type SourceStatsHandler

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

SourceStatsHandler is a REST handler for retrieving the partition seqs from the data source for an index.

func NewSourceStatsHandler

func NewSourceStatsHandler(mgr *cbgt.Manager) *SourceStatsHandler

func (*SourceStatsHandler) RESTOpts

func (h *SourceStatsHandler) RESTOpts(opts map[string]string)

func (*SourceStatsHandler) ServeHTTP

func (h *SourceStatsHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

type StatsHandler

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

StatsHandler is a REST handler that provides stats/metrics for a node.

func NewStatsHandler

func NewStatsHandler(mgr *cbgt.Manager) *StatsHandler

func (*StatsHandler) ServeHTTP

func (h *StatsHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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