Documentation
¶
Overview ¶
Package proxy_http provides common HTTP handlers to use in application.
Index ¶
- Variables
- func AsyncSearchProxy(c *HandlerContext) bool
- func BulkProxy(c *HandlerContext) bool
- func CountProxy(c *HandlerContext) (handled bool)
- func Forward(t *Config, w http.ResponseWriter, r *http.Request) bool
- func MappingProxy(c *HandlerContext) bool
- func Ping(t *Config, w http.ResponseWriter, r *http.Request) bool
- func ReverseProxyForConfig(cfg *Config) (http.HandlerFunc, error)
- func SearchProxy(c *HandlerContext) bool
- func VersionHandler(w http.ResponseWriter, r *http.Request)
- type Config
- type DummyCache
- type ElasticMapping
- type HandlerContext
- func (c *HandlerContext) AddHeader(k, v string)
- func (c *HandlerContext) Authenticate(username, password string) bool
- func (c *HandlerContext) BadRequest(s string, args ...any)
- func (c *HandlerContext) Error(status int, s string, args ...any)
- func (c *HandlerContext) HasSnellerEndpoint() bool
- func (c *HandlerContext) InternalServerError(s string, args ...any)
- func (c *HandlerContext) NeedsAuthentication() bool
- func (c *HandlerContext) NotFound(s string, args ...any)
- func (c *HandlerContext) SelectIndex(index string) bool
- type LogDetail
- type Logging
- type MappingCache
- type MemcacheMappingCache
- type SnellerLogging
Constants ¶
This section is empty.
Variables ¶
var Version = "development"
Functions ¶
func AsyncSearchProxy ¶
func AsyncSearchProxy(c *HandlerContext) bool
func BulkProxy ¶
func BulkProxy(c *HandlerContext) bool
func CountProxy ¶
func CountProxy(c *HandlerContext) (handled bool)
func Forward ¶
Forward forwards query to ElasticSearch if it's configured and returns true. Otherwise does nothing and returns false.
func MappingProxy ¶
func MappingProxy(c *HandlerContext) bool
MappingProxy handles GET endpoint for Mapping API
See: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
func ReverseProxyForConfig ¶
func ReverseProxyForConfig(cfg *Config) (http.HandlerFunc, error)
func SearchProxy ¶
func SearchProxy(c *HandlerContext) bool
func VersionHandler ¶
func VersionHandler(w http.ResponseWriter, r *http.Request)
Types ¶
type Config ¶
type Config struct {
Elastic struct {
EndPoint string `json:"endpoint,omitempty"`
User string `json:"user,omitempty"`
Password string `json:"password,omitempty"`
ESPassword string `json:"esPassword,omitempty"`
IgnoreCert bool `json:"ignoreCert,omitempty"`
} `json:"elastic,omitempty"`
Sneller configSneller `json:"sneller,omitempty"`
Mapping map[string]*mappingEntry `json:"mapping"`
CompareWithElastic bool `json:"compareWithElastic,omitempty"`
}
type DummyCache ¶
type DummyCache struct{}
DummyCache is a MappingCache that does not support storing and always fetches nothing.
func (DummyCache) Fetch ¶
func (d DummyCache) Fetch(idxName string) (*ElasticMapping, error)
func (DummyCache) Store ¶
func (d DummyCache) Store(idxName string, mapping *ElasticMapping) error
type ElasticMapping ¶
type ElasticMapping = elastic_proxy.ElasticMapping
type HandlerContext ¶
type HandlerContext struct {
Request *http.Request
Writer http.ResponseWriter
Config *Config
Logging *Logging
Client *http.Client
Mapping *mappingEntry // currently selected mapping for an index
Cache MappingCache
// function performing verbose logging
VerboseLog func(string, ...any)
// Flag indicating we're using verbose logging;
// provided in case some logging activities might
// cost more than a single VerboseLog call.
Verbose bool
Memcache struct {
// Optional memcache client
Client *memcache.Client
// The ID used to distinguish ElasticProxy instances
TenantID string
// A string used to create a crypto key
Secret string
// Item expiration timeout
ExpirationTime int
}
}
HandlerContext is all data required to process an HTTP request.
func NewHandlerContext ¶
func NewHandlerContext(config *Config, client *http.Client, w http.ResponseWriter, r *http.Request, verbose bool, verboseLog func(format string, v ...any)) *HandlerContext
NewHandlerContext creates a new context based on the ElasticSearch configuration and the handled request.
func (*HandlerContext) AddHeader ¶
func (c *HandlerContext) AddHeader(k, v string)
func (*HandlerContext) Authenticate ¶
func (c *HandlerContext) Authenticate(username, password string) bool
func (*HandlerContext) BadRequest ¶
func (c *HandlerContext) BadRequest(s string, args ...any)
func (*HandlerContext) HasSnellerEndpoint ¶
func (c *HandlerContext) HasSnellerEndpoint() bool
func (*HandlerContext) InternalServerError ¶
func (c *HandlerContext) InternalServerError(s string, args ...any)
func (*HandlerContext) NeedsAuthentication ¶
func (c *HandlerContext) NeedsAuthentication() bool
func (*HandlerContext) NotFound ¶
func (c *HandlerContext) NotFound(s string, args ...any)
func (*HandlerContext) SelectIndex ¶
func (c *HandlerContext) SelectIndex(index string) bool
type Logging ¶
type Logging struct {
Revision string `json:"revision"`
SourceIP string `json:"sourceIp"`
TenantID string `json:"tenantId,omitempty"`
QueryID string `json:"queryId"`
Start time.Time `json:"start"`
Index string `json:"index"`
Duration time.Duration `json:"duration"`
HttpStatusCode int `json:"httpStatusCode"`
Sneller *SnellerLogging `json:"sneller,omitempty"`
Request map[string]any `json:"request,omitempty"`
QueryParams url.Values `json:"queryParameters,omitempty"`
SQL string `json:"sql,omitempty"`
SnellerResult map[string]any `json:"snellerResult,omitempty"`
Preprocessed map[string]any `json:"preprocessed,omitempty"`
Result *elastic_proxy.ElasticResult `json:"result,omitempty"`
ElasticResult map[string]any `json:"elasticResult,omitempty"`
ElasticDiff string `json:"diff,omitempty"`
}
type MappingCache ¶
type MappingCache interface {
// Store saves ElasticMapping entry for given database and table.
Store(idxName string, mapping *ElasticMapping) error
// Fetch loads ElasticMapping entry for given database and table.
// It returns nil, false if no mapping was found.
Fetch(idxName string) (*ElasticMapping, error)
}
MappingCache is an interaface to cache ElasticMapping data
Key is constructed from database and table names.
type MemcacheMappingCache ¶
type MemcacheMappingCache struct {
// contains filtered or unexported fields
}
MemcacheMappingCache is a MappingCache backed by memcached
func NewMemcacheMappingCache ¶
func NewMemcacheMappingCache(client *memcache.Client, tenantID string, secret string, defaultExpiration int) *MemcacheMappingCache
NewMemcacheMappingCache creates new MemcacheMappingCache instance.
func (*MemcacheMappingCache) Fetch ¶
func (m *MemcacheMappingCache) Fetch(idxName string) (*ElasticMapping, error)
func (*MemcacheMappingCache) Store ¶
func (m *MemcacheMappingCache) Store(idxName string, mapping *ElasticMapping) error