Documentation ¶
Index ¶
- Constants
- Variables
- func AddMigrationScript(migration Migration)
- func AddSyncScript(syncScript SyncPluginCache)
- func ApplyDelta(text string, delta string) (string, error)
- func BillingBlacklistedPaths() []string
- func BillingMiddleware(next http.Handler) http.Handler
- func BillingMiddlewareOffline(next http.Handler) http.Handler
- func CalculateBodyDiff(originalReqBody io.ReadCloser, modifiedReqBody io.ReadCloser) string
- func CalculateBodyStringDiff(originalReqBody string, modifiedReqBody string) string
- func CalculateHeaderDiff(originalReqHeader http.Header, modifiedReqHeader http.Header) string
- func CalculateMethodDiff(originalReq *http.Request, modifiedReq *http.Request) string
- func CalculateMethodStringDiff(originalReqMethod string, modifiedReqMethod string) string
- func CalculateRequestDiff(originalReq *http.Request, modifiedReq *http.Request) *difference.Difference
- func CalculateResponseDiff(originalRes *httptest.ResponseRecorder, modifiedRes *httptest.ResponseRecorder) *difference.Difference
- func CalculateStringDiff(text1 string, text2 string) string
- func CalculateUriDiff(originalReq *http.Request, modifiedReq *http.Request) string
- func CheckIfIndexExists(ctx context.Context, indexName string) bool
- func CleanPasswordFromURL(URL string) string
- func Contains(slice []string, val string) bool
- func CountComponents(route string) (int, int)
- func DaysInCurrentYear() int
- func DaysInMonth(m time.Month, year int) int
- func DaysInYear(year int) int
- func DebugDeprecationWarns(formattedStr string) bool
- func DecodeBase64Key(encoded string) ([]byte, error)
- func DeepCloneRequest(req *http.Request) (*http.Request, error)
- func DeepCloneResponse(res *httptest.ResponseRecorder) (*httptest.ResponseRecorder, error)
- func GetAppbaseID() (string, error)
- func GetArcID() (string, error)
- func GetCachedPlanDetails() ([]byte, error)
- func GetClient6() *es6.Client
- func GetClient7() *es7.Client
- func GetESURL() string
- func GetExpiryTime() time.Time
- func GetFeatureCache() bool
- func GetFeatureCustomEvents() bool
- func GetFeatureEcommerce() bool
- func GetFeaturePipelines() bool
- func GetFeatureRules() bool
- func GetFeatureSearchGrader() bool
- func GetFeatureSearchRelevancy() bool
- func GetFeatureSuggestions() bool
- func GetFeatureUIBuilderPremium() bool
- func GetHitsForIndex(response *elastic.SearchResult, index string) []*elastic.SearchHit
- func GetIndexFilterQueryEs6(query *es6.BoolQuery, indices ...string) *es6.BoolQuery
- func GetIndexFilterQueryEs7(query *es7.BoolQuery, indices ...string) *es7.BoolQuery
- func GetNumberOfMachines() int64
- func GetPlanDetails() *[]byte
- func GetReplicas() int
- func GetSemanticVersion() string
- func GetSyncInterval() int
- func GetTimeValidity() int64
- func GetTotalNodes() (int, error)
- func GetVersion() int
- func GetZincData() (string, string, string)
- func HTTPClient() *http.Client
- func HiddenIndexSettings() string
- func IndicesFromRequest(r *http.Request) []string
- func IntervalForRange(from, to string) (string, error)
- func IsBillingEnabled() bool
- func IsExists(a string, list []string) bool
- func IsProductionPlan() bool
- func IsRSAPIValidateRoute(req *http.Request) bool
- func IsSubset(sub, super []string) bool
- func MakeHttpRequest(method string, url string, requestBody interface{}) (interface{}, error, *http.Response)
- func MakeRequest(url, method string, reqBody []byte) ([]byte, *http.Response, error)
- func MakeRequestWithHeader(url, method string, reqBody []byte, headers http.Header) ([]byte, *http.Response, error)
- func Min(a, b int) int
- func NewClient()
- func NewZincClient()
- func ProxyACCAPI(proxyConfig ProxyConfig) (*http.Response, error)
- func RandStr() string
- func ReportHostedArcUsage()
- func ReportUsage()
- func SetClusterPlan()
- func SetDefaultIndexTemplate() error
- func SetDefaultTier()
- func SetExpiryTime(time time.Time)
- func SetFeatureCache(val bool)
- func SetFeatureCustomEvents(val bool)
- func SetFeatureEcommerce(val bool)
- func SetFeaturePipelines(val bool)
- func SetFeatureRules(val bool)
- func SetFeatureSearchGrader(val bool)
- func SetFeatureSearchRelevancy(val bool)
- func SetFeatureSuggestions(val bool)
- func SetFeatureUIBuilderPremium(val bool)
- func SetPlanDetailsHook(fn *func([]byte))
- func SetSyncInterval(interval int) error
- func SetSystemIndexTemplate() error
- func SetTier(plan *Plan)
- func SetTimeValidity(time int64)
- func ShouldProxyToACCAPI() bool
- func StructToMap(response interface{}) interface{}
- func ToStringSlice(g interface{}) ([]string, error)
- func ValidateArcID(statusCode int)
- func ValidateIndex(pattern string, index string) (bool, error)
- func ValidatePlans(validPlans []Plan, byPassValidation bool) bool
- func WithPrecision(num float64, precision int) float64
- func WriteBackError(w http.ResponseWriter, err string, code int)
- func WriteBackMessage(w http.ResponseWriter, message string, code int)
- func WriteBackRaw(w http.ResponseWriter, raw []byte, code int)
- type ArcInstance
- type ArcInstanceDetails
- type ArcInstanceResponse
- type ArcUsage
- type ArcUsageResponse
- type BuildArc
- type ClusterPlan
- type ClusterPlanResponse
- type Error
- type IndexMappingResponse
- type Migration
- type Plan
- type ProxyConfig
- type Retrier
- type Subscripton
- type SyncPluginCache
- type WrapKitLoggerDebug
- type WrapKitLoggerError
- type ZincClient
Constants ¶
const AppbaseIDEnvName = "APPBASE_ID"
const ArcIDEnvName = "ARC_ID"
const ClusterIDEnvName = "CLUSTER_ID"
Variables ¶
var ACCAPI = "https://accapi.appbase.io/"
ACCAPI URL
var AppbasePublicKey = "f6c7f3e774cc07b73cf97f6a561d940274cd20abd5f64d0ebe6f9ef7a63667f1"
Appbase Public Key to validate the offline license
var Billing string
Billing is a build time variable
var ClusterBilling string
ClusterBilling is a build time variable
var ClusterID string
ClusterID represents the (decrypted) cluster id for appbase.io cloud and byoc clusters
var CreateSchema bool = false
Whether or not to create schema
var HostedBilling string
HostedBilling is a build time variable
var IsTelemetryEnabled bool = true
We set it in the `main.go` based on the env variable and run time flag defaults to `true`
var MachineID string
Machine ID
var MemoryAllocated uint64
Memory Allocated in number of bytes
var NodeCount = 1
NodeCount is the current node count, defaults to 1
var OfflineBilling bool
OfflineBilling is true when license key is defined
var OfflineGracePeriod = 30 // in days
OfflineGracePeriod is the time duration in days that defines the grace period for expired license. Arc would start throwing 402 error when OfflineGracePeriod is passed.
var Opensource string
Opensource is a build time variable
var Port int
Port ReactiveSearch port
var RunTime string
RunTime
var TestURL = "http://foo:bar@localhost:8000"
TestURL for ReactiveSearch
var Version string
Version ReactiveSearch version
Functions ¶
func AddMigrationScript ¶
func AddMigrationScript(migration Migration)
AddMigrationScript allows you to add a migration script
func AddSyncScript ¶
func AddSyncScript(syncScript SyncPluginCache)
AddSyncScript allows you to add a sync cache script
func ApplyDelta ¶
ApplyDelta applies the delta to the passed text1 and returns the text2.
func BillingBlacklistedPaths ¶
func BillingBlacklistedPaths() []string
BillingBlacklistedPaths will return an array of paths that should not be affected if billing is enabled.
func BillingMiddleware ¶
BillingMiddleware function to be called for each request
func BillingMiddlewareOffline ¶
BillingMiddlewareOffline function to be called for each request when offline billing is used
func CalculateBodyDiff ¶
func CalculateBodyDiff(originalReqBody io.ReadCloser, modifiedReqBody io.ReadCloser) string
Calculate the diff in the body
func CalculateBodyStringDiff ¶
Calculate the diff in the body
func CalculateHeaderDiff ¶
func CalculateMethodDiff ¶
Calculate method difference
func CalculateMethodStringDiff ¶
Calculate method difference
func CalculateRequestDiff ¶
func CalculateRequestDiff(originalReq *http.Request, modifiedReq *http.Request) *difference.Difference
Calculate the diff between the passed bodies. We will find the difference between - body - headers - URI - method
func CalculateResponseDiff ¶
func CalculateResponseDiff(originalRes *httptest.ResponseRecorder, modifiedRes *httptest.ResponseRecorder) *difference.Difference
Calculate the diff between the passed bodies. We will find the difference between - body. - headers
func CalculateStringDiff ¶
CalculateStringDiff calculates the delta diff between the passed strings
func CalculateUriDiff ¶
Calculate the difference in the URI
func CleanPasswordFromURL ¶
CleanPasswordFromURL will clean password from the URL if it is present
func CountComponents ¶
CountComponents returns the numbers of "/" and "vars" present in the route.
func DaysInCurrentYear ¶
func DaysInCurrentYear() int
DaysInCurrentYear returns the number of days in the current year.
func DaysInMonth ¶
DaysInMonth returns the number of days in a month for a given year.
func DaysInYear ¶
DaysInYear returns the number of days in a given year.
func DebugDeprecationWarns ¶
DebugDeprecationWarns converts all the error logs containing deprecation warnings to debug logs so that it doesn't invoke sentry
func DecodeBase64Key ¶
DecodeBase64Key decodes a base64 input
func DeepCloneRequest ¶
Deep clone the request body by also reading the body and keeping the body back in the original one.
func DeepCloneResponse ¶
func DeepCloneResponse(res *httptest.ResponseRecorder) (*httptest.ResponseRecorder, error)
Deep clone the response body by also reading the body and keeping the body back in the original response.
func GetCachedPlanDetails ¶
func GetFeatureCustomEvents ¶
func GetFeatureCustomEvents() bool
GetFeatureCustomEvents returns the featureCustomEvents
func GetFeatureEcommerce ¶
func GetFeatureEcommerce() bool
GetFeatureEcommerce returns the featureEcommerce
func GetFeaturePipelines ¶
func GetFeaturePipelines() bool
GetFeatureCache returns the featurePipelines
func GetFeatureSearchGrader ¶
func GetFeatureSearchGrader() bool
GetFeatureSearchGrader returns the featureSearchGrader
func GetFeatureSearchRelevancy ¶
func GetFeatureSearchRelevancy() bool
GetFeatureSearchRelevancy returns the featureSearchRelevancy
func GetFeatureSuggestions ¶
func GetFeatureSuggestions() bool
GetFeatureSuggestions returns the featureSuggestions
func GetFeatureUIBuilderPremium ¶
func GetFeatureUIBuilderPremium() bool
GetFeatureUIBuilderPremium returns the featureUIBuilder
func GetHitsForIndex ¶
func GetHitsForIndex(response *elastic.SearchResult, index string) []*elastic.SearchHit
Filters ES hits by index name
func GetIndexFilterQueryEs6 ¶
GetIndexFilterQueryEs6 apply the index filtering logic
func GetIndexFilterQueryEs7 ¶
GetIndexFilterQueryEs7 apply the index filtering logic
func GetNumberOfMachines ¶
func GetNumberOfMachines() int64
To retrieve the total number of machines
func GetSemanticVersion ¶
func GetSemanticVersion() string
GetSemanticVersion returns the es version
func GetSyncInterval ¶
func GetSyncInterval() int
func GetTotalNodes ¶
GetTotalNodes retrieves the number of es nodes
func GetZincData ¶
GetZincData will return the zinc data from the environment.
The return will be three strings: - URL - username - password
func HTTPClient ¶
HTTPClient returns an http client with reasonable timeout defaults. See: https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779 This client will cap the TCP connect and TLS handshake timeouts, as well as establishing an end-to-end request timeout.
func HiddenIndexSettings ¶
func HiddenIndexSettings() string
HiddenIndexSettings to set plugin indices as hidden index
func IndicesFromRequest ¶
IndicesFromRequest extracts index patterns from the request url (from var "{index}"). It returns an empty slice if {index} is not present in the route.
func IntervalForRange ¶
IntervalForRange returns the interval in seconds for a given time range. It expects the time arguments in RFC3339 format. The interval is calculated by: I = (25 * D) seconds, where D = duration (in hours), I = interval.
func IsBillingEnabled ¶
func IsBillingEnabled() bool
func IsProductionPlan ¶
func IsProductionPlan() bool
IsProductionPlan validates if the user's plan is a production plan
func IsRSAPIValidateRoute ¶
Returns true if req path matches with RS API validate route
func IsSubset ¶
IsSubset returns true if the first slice is completely contained in the second slice. There must be at least the same number of duplicate values in second as there are in first.
func MakeHttpRequest ¶
func MakeRequest ¶
MakeRequest helps in proxing http requests
func MakeRequestWithHeader ¶
func MakeRequestWithHeader(url, method string, reqBody []byte, headers http.Header) ([]byte, *http.Response, error)
MakeRequestWithHeader helps in proxing http requests with header support
func ProxyACCAPI ¶
func ProxyACCAPI(proxyConfig ProxyConfig) (*http.Response, error)
func RandStr ¶
func RandStr() string
RandStr returns "node" field of a UUID. See: https://tools.ietf.org/html/rfc4122#section-4.1.6
func ReportHostedArcUsage ¶
func ReportHostedArcUsage()
ReportHostedArcUsage reports ReactiveSearch usage by hosted cluster, intended to be called every hour
func ReportUsage ¶
func ReportUsage()
ReportUsage reports ReactiveSearch usage, intended to be called every hour
func SetClusterPlan ¶
func SetClusterPlan()
SetClusterPlan fetches the cluster plan & sets the Tier value
func SetDefaultIndexTemplate ¶
func SetDefaultIndexTemplate() error
SetDefaultIndexTemplate sets default template for user indexes
func SetDefaultTier ¶
func SetDefaultTier()
SetDefaultTier sets the default tier when billing is disabled
func SetFeatureCustomEvents ¶
func SetFeatureCustomEvents(val bool)
SetFeatureCustomEvents returns the time validity
func SetFeatureEcommerce ¶
func SetFeatureEcommerce(val bool)
SetFeatureEcommerce sets the featureEcommerce
func SetFeaturePipelines ¶
func SetFeaturePipelines(val bool)
SetFeatureEcommerce sets the featurePipelines
func SetFeatureSearchGrader ¶
func SetFeatureSearchGrader(val bool)
SetFeatureSearchGrader sets the featureSearchGrader
func SetFeatureSearchRelevancy ¶
func SetFeatureSearchRelevancy(val bool)
SetFeatureSearchRelevancy sets the featureSearchRelevancy
func SetFeatureSuggestions ¶
func SetFeatureSuggestions(val bool)
SetFeatureSuggestions returns the time validity
func SetFeatureUIBuilderPremium ¶
func SetFeatureUIBuilderPremium(val bool)
SetFeatureUIBuilderPremium sets the featureUIBuilder
func SetPlanDetailsHook ¶
func SetPlanDetailsHook(fn *func([]byte))
func SetSyncInterval ¶
func SetSystemIndexTemplate ¶
func SetSystemIndexTemplate() error
SetSystemIndexTemplate sets default template for system indexes
func StructToMap ¶
func StructToMap(response interface{}) interface{}
func ToStringSlice ¶
ToStringSlice converts a interface{} type to []string. It basically converts all the elements of the slice to its string representation using fmt.Sprint.
func ValidateArcID ¶
func ValidateArcID(statusCode int)
ValidateArcID validates the APPBASE_ID by checking the response returned from the ACCAPI
func ValidateIndex ¶
ValidateIndex validates an index against a pattern
func ValidatePlans ¶
ValidatePlans validates the user's plan against the valid plans
func WithPrecision ¶
WithPrecision returns the floating point number with the given precision.
func WriteBackError ¶
func WriteBackError(w http.ResponseWriter, err string, code int)
WriteBackError writes the given error message as a json response to the response writer.
func WriteBackMessage ¶
func WriteBackMessage(w http.ResponseWriter, message string, code int)
WriteBackMessage writes the given message as a json response to the response writer.
func WriteBackRaw ¶
func WriteBackRaw(w http.ResponseWriter, raw []byte, code int)
WriteBackRaw writes the given json encoded bytes to the response writer.
Types ¶
type ArcInstance ¶
type ArcInstance struct {
SubscriptionID string `json:"subscription_id"`
}
ArcInstance TBD: remove struct
type ArcInstanceDetails ¶
type ArcInstanceDetails struct { NodeCount int `json:"node_count"` Description string `json:"description"` SubscriptionID string `json:"subscription_id"` SubscriptionCanceled bool `json:"subscription_canceled"` Trial bool `json:"trial"` TrialValidity int64 `json:"trial_validity"` CreatedAt int64 `json:"created_at"` Tier *Plan `json:"tier"` TierValidity int64 `json:"tier_validity"` TimeValidity int64 `json:"time_validity"` Metadata map[string]interface{} `json:"metadata"` FeatureCustomEvents bool `json:"feature_custom_events"` FeatureSuggestions bool `json:"feature_suggestions"` FeatureRules bool `json:"feature_rules"` FeatureSearchRelevancy bool `json:"feature_search_relevancy"` FeatureSearchGrader bool `json:"feature_search_grader"` FeatureEcommerce bool `json:"feature_ecommerce"` FeatureUIBuilderPremium bool `json:"feature_uibuilder_premium"` FeatureCache bool `json:"feature_cache"` FeaturePipelines bool `json:"feature_pipelines"` ClusterID string `json:"cluster_id"` NumberOfMachines int64 `json:"number_of_machines"` CustomerID string `json:"customer_id"` }
ArcInstanceDetails contains the info about a ReactiveSearch Instance
type ArcInstanceResponse ¶
type ArcInstanceResponse struct {
ArcInstances []ArcInstanceDetails `json:"instances"`
}
ArcInstanceResponse TBD: Remove struct
type ArcUsage ¶
type ArcUsage struct { ArcID string `json:"arc_id"` SubscriptionID string `json:"subscription_id"` Quantity int `json:"quantity"` ClusterID string `json:"cluster_id"` MachineID string `json:"machine_id"` }
ArcUsage struct is used to report time usage
type ArcUsageResponse ¶
type ArcUsageResponse struct { Accepted bool `json:"accepted"` FailureReason string `json:"failure_reason"` ErrorMsg string `json:"error_msg"` WarningMsg string `json:"warning_msg"` StatusCode int `json:"status_code"` TimeValidity int64 `json:"time_validity"` }
ArcUsageResponse stores the response from ACCAPI
type BuildArc ¶
type ClusterPlan ¶
type ClusterPlan struct { Tier *Plan `json:"tier"` FeatureCustomEvents bool `json:"feature_custom_events"` FeatureSuggestions bool `json:"feature_suggestions"` FeatureRules bool `json:"feature_rules"` FeatureSearchRelevancy bool `json:"feature_search_relevancy"` FeatureSearchGrader bool `json:"feature_search_grader"` FeatureEcommerce bool `json:"feature_ecommerce"` FeatureCache bool `json:"feature_cache"` FeaturePipelines bool `json:"feature_pipelines"` FeatureUIBuilderPremium bool `json:"feature_uibuilder_premium"` Trial bool `json:"trial"` TrialValidity int64 `json:"trial_validity"` TierValidity int64 `json:"tier_validity"` TimeValidity int64 `json:"time_validity"` SubscriptionID string `json:"subscription_id"` ClusterID string `json:"cluster_id"` NumberOfMachines int64 `json:"number_of_machines"` SubscriptionCanceled bool `json:"subscription_canceled"` CreatedAt int64 `json:"created_at"` CustomerID string `json:"customer_id"` }
type ClusterPlanResponse ¶
type ClusterPlanResponse struct {
Plan ClusterPlan `json:"plan"`
}
Cluster plan response type
type IndexMappingResponse ¶
type IndexMappingResponse map[string]interface{}
Handle unstrctured JSON data from the mapping endpoint
func GetIndexMapping ¶
func GetIndexMapping(indexName string, ctx context.Context) (resp IndexMappingResponse, err error)
Fetch the index mapping manually using the following function Make the request using an es7 client method that allows direct requests. Using that gives us the addition of automatic request retries in case the first request fails (due to ES not being available?)
We will extract the unstructured JSON data from the endpoint and parse it to a map so that it can be directly used.
On error, an empty data body will be returned along with the error itself.
Errors will be returned accordingly and verbosed if the error occurs while extracting the JSON data. There will be no verbose if the error occurs while hitting the endpoint. Those errors are expected to be handled by the calling function.
type Migration ¶
type Migration interface { // ConditionCheck method allows you to control the script // execution only when a certain confition met ConditionCheck() (bool, *Error) // This function allows you to execute the migration logic // Execute the non-blocking scripts in a go routine and return the Error as nil Script() *Error // To determine wether to run script synchronously or asynchronously. // Sync scripts will cause the fatal error if failed IsAsync() bool }
func GetMigrationScripts ¶
func GetMigrationScripts() []Migration
type Plan ¶
type Plan int
An enum having a list of valid plans
const ( ArcBasic Plan = iota ArcStandard ArcEnterprise HostedArcBasic HostedArcBasicV2 HostedArcStandard HostedArcEnterprise Sandbox Hobby Starter ProductionFirst ProductionSecond ProductionThird Sandbox2019 Hobby2019 Starter2019 Sandbox2020 Hobby2020 Starter2020 ProductionFirst2019 ProductionSecond2019 ProductionThird2019 ProductionFourth2019 Starter2021 ProductionFirst2021 ProductionSecond2021 ProductionThird2021 HostedArcStandard2021 HostedArcEnterprise2021 )
func (Plan) MarshalJSON ¶
MarshalJSON is the implementation of the Marshaler interface for marshaling Plan type.
func (Plan) String ¶
String is the implementation of Stringer interface that returns the string representation of Plan type.
func (*Plan) UnmarshalJSON ¶
UnmarshalJSON is the implementation of the Unmarshaler interface for unmarshaling Plan type.
type ProxyConfig ¶
type Retrier ¶
type Retrier struct {
// contains filtered or unexported fields
}
Retrier is a custom Retry implementation.
func NewRetrier ¶
func NewRetrier() *Retrier
NewRetrier returns a new retrier with exponential backoff strategy.
type Subscripton ¶
type SyncPluginCache ¶
type SyncPluginCache interface { // Plugin name PluginName() string // Index to retrieve data Index() string // Method to set the ES data to plugin cache SetCache(response *elastic.SearchResult) error }
func GetSyncScripts ¶
func GetSyncScripts() []SyncPluginCache
type WrapKitLoggerDebug ¶
func (WrapKitLoggerDebug) Printf ¶
func (logger WrapKitLoggerDebug) Printf(format string, vars ...interface{})
type WrapKitLoggerError ¶
func (WrapKitLoggerError) Printf ¶
func (logger WrapKitLoggerError) Printf(format string, vars ...interface{})
type ZincClient ¶
func GetZincClient ¶
func GetZincClient() *ZincClient
GetZincClient will return the zinc client and only init it once.