Documentation
¶
Index ¶
- Constants
- Variables
- func CreateAdminHandler(sc *ServerContext) http.Handler
- func CreatePublicHandler(sc *ServerContext) http.Handler
- func GetGZipWriter(writer io.Writer) *gzip.Writer
- func ParseCommandLine()
- func ReloadConf()
- func ReturnGZipWriter(gz *gzip.Writer)
- func RunServer(config *ServerConfig)
- func ServerMain(runMode SyncGatewayRunMode)
- func ValidateConfigOrPanic(runMode SyncGatewayRunMode)
- type BucketConfig
- type CORSConfig
- type CacheConfig
- type ChannelIndexConfig
- type ClusterConfig
- type DbConfig
- type DbConfigMap
- type EncodedResponseWriter
- type EventConfig
- type EventHandlerConfig
- type FacebookConfig
- type FacebookResponse
- type GoogleConfig
- type GoogleResponse
- type PersonaConfig
- type PersonaResponse
- type SequenceHashConfig
- type ServerConfig
- func (config *ServerConfig) HasAnyIndexReaderConfiguredDatabases() bool
- func (config *ServerConfig) HasAnyIndexWriterConfiguredDatabases() bool
- func (self *ServerConfig) MergeWith(other *ServerConfig) error
- func (config *ServerConfig) NumIndexReaders() int
- func (config *ServerConfig) NumIndexWriters() int
- type ServerContext
- func (sc *ServerContext) AddDatabaseFromConfig(config *DbConfig) (*db.DatabaseContext, error)
- func (sc *ServerContext) AllDatabaseNames() []string
- func (sc *ServerContext) Close()
- func (sc *ServerContext) GetConfig() *ServerConfig
- func (sc *ServerContext) GetDatabase(name string) (*db.DatabaseContext, error)
- func (sc *ServerContext) GetDatabaseConfig(name string) *DbConfig
- func (sc *ServerContext) HasIndexWriters() bool
- func (sc *ServerContext) InitCBGT() error
- func (sc *ServerContext) InitCBGTManager() (base.CbgtContext, error)
- func (sc *ServerContext) NewSyncGatewayPIndexFactory(indexType, indexParams, path string, restart func()) (cbgt.PIndexImpl, cbgt.Dest, error)
- func (sc *ServerContext) OpenSyncGatewayPIndexFactory(indexType, path string, restart func()) (cbgt.PIndexImpl, cbgt.Dest, error)
- func (sc *ServerContext) ReloadDatabaseFromConfig(reloadDbName string, useExisting bool) (*db.DatabaseContext, error)
- func (sc *ServerContext) RemoveDatabase(dbName string) bool
- func (sc *ServerContext) Stats() map[string]interface{}
- func (sc *ServerContext) SyncGatewayPIndexFactoryCommon(indexParams base.SyncGatewayIndexParams) (cbgt.PIndexImpl, cbgt.Dest, error)
- type ShadowConfig
- type SyncGatewayRunMode
- type UnsupportedConfig
- type UserAgentVersion
- type UserViewsConfig
Constants ¶
const ( DefaultMaxCouchbaseConnections = 16 DefaultMaxCouchbaseOverflowConnections = 0 // Default value of ServerConfig.MaxIncomingConnections DefaultMaxIncomingConnections = 0 // Default value of ServerConfig.MaxFileDescriptors DefaultMaxFileDescriptors uint64 = 5000 )
const GitBranch = ""
const GitCommit = ""
The git commit that was compiled. This will be filled in by the compiler.
const GitDirty = ""
const ServerName = "Couchbase Sync Gateway" // DO NOT CHANGE; clients check this
const VersionBuildNumberString = "@PRODUCT_VERSION@" // Real string substituted by Gerrit
const VersionCommitSHA = "@COMMIT_SHA@" // Real string substituted by Gerrit
const VersionNumber float64 = 1.2 // API/feature level
Variables ¶
var DebugMultipart bool = false
If set to true, diagnostic data will be dumped if there's a problem with MIME multipart data
var DefaultAdminInterface = "127.0.0.1:4985" // Only accessible on localhost!
var DefaultInterface = ":4984"
var DefaultPool = "default"
var DefaultServer = "walrus:"
var LongVersionString string
This includes build number; appears in the response of "GET /" and the initial log message
var PrettyPrint bool = false
If set to true, JSON output will be pretty-printed.
var VersionString string
This appears in the "Server:" header of HTTP responses. This should be changed only very cautiously, because Couchbase Lite parses the header value to determine whether it's talking to Sync Gateway (vs. CouchDB) and what version. This in turn determines what replication API features it will use.
Functions ¶
func CreateAdminHandler ¶
func CreateAdminHandler(sc *ServerContext) http.Handler
Creates the HTTP handler for the PRIVATE admin API of a gateway server.
func CreatePublicHandler ¶
func CreatePublicHandler(sc *ServerContext) http.Handler
Creates the HTTP handler for the public API of a gateway server.
func GetGZipWriter ¶
Gets a gzip writer from the pool, or creates a new one if the pool is empty:
func ParseCommandLine ¶
func ParseCommandLine()
Reads the command line flags and the optional config file.
func ReturnGZipWriter ¶
Closes a gzip writer and returns it to the pool:
func RunServer ¶
func RunServer(config *ServerConfig)
Starts and runs the server given its configuration. (This function never returns.)
func ServerMain ¶
func ServerMain(runMode SyncGatewayRunMode)
Main entry point for a simple server; you can have your main() function just call this. It parses command-line flags, reads the optional configuration file, then starts the server.
func ValidateConfigOrPanic ¶
func ValidateConfigOrPanic(runMode SyncGatewayRunMode)
Types ¶
type BucketConfig ¶
type BucketConfig struct {
Server *string `json:"server,omitempty"` // Couchbase server URL
Pool *string `json:"pool,omitempty"` // Couchbase pool name, default "default"
Bucket *string `json:"bucket,omitempty"` // Bucket name
Username string `json:"username,omitempty"` // Username for authenticating to server
Password string `json:"password,omitempty"` // Password for authenticating to server
}
Bucket configuration elements - used by db, shadow, index
type CORSConfig ¶
type CacheConfig ¶
type CacheConfig struct {
CachePendingSeqMaxWait *uint32 `json:"max_wait_pending,omitempty"` // Max wait for pending sequence before skipping
CachePendingSeqMaxNum *int `json:"max_num_pending,omitempty"` // Max number of pending sequences before skipping
CacheSkippedSeqMaxWait *uint32 `json:"max_wait_skipped,omitempty"` // Max wait for skipped sequence before abandoning
EnableStarChannel *bool `json:"enable_star_channel"` // Enable star channel
ChannelCacheMaxLength *int `json:"channel_cache_max_length"` // Maximum number of entries maintained in cache per channel
ChannelCacheMinLength *int `json:"channel_cache_min_length"` // Minimum number of entries maintained in cache per channel
ChannelCacheAge *int `json:"channel_cache_expiry"` // Time (seconds) to keep entries in cache beyond the minimum retained
}
type ChannelIndexConfig ¶
type ChannelIndexConfig struct {
BucketConfig
IndexWriter bool `json:"writer,omitempty"` // Whether SG node is a channel index writer
NumShards uint16 `json:"num_shards,omitempty"` // Number of partitions in the channel index
SequenceHashConfig *SequenceHashConfig `json:"seq_hashing,omitempty"` // Sequence hash configuration
}
func (*ChannelIndexConfig) GetCredentials ¶
func (channelIndexConfig *ChannelIndexConfig) GetCredentials() (string, string, string)
Implementation of AuthHandler interface for ChannelIndexConfig
type ClusterConfig ¶
type ClusterConfig struct {
BucketConfig
DataDir string `json:"data_dir,omitempty"`
HeartbeatIntervalSeconds *uint16 `json:"heartbeat_interval_seconds,omitempty"`
}
func (ClusterConfig) CBGTEnabled ¶
func (c ClusterConfig) CBGTEnabled() bool
type DbConfig ¶
type DbConfig struct {
BucketConfig
Name string `json:"name,omitempty"` // Database name in REST API (stored as key in JSON)
Sync *string `json:"sync,omitempty"` // Sync function defines which users can see which data
Users map[string]*db.PrincipalConfig `json:"users,omitempty"` // Initial user accounts
Roles map[string]*db.PrincipalConfig `json:"roles,omitempty"` // Initial roles
RevsLimit *uint32 `json:"revs_limit,omitempty"` // Max depth a document's revision tree can grow to
ImportDocs interface{} `json:"import_docs,omitempty"` // false, true, or "continuous"
Shadow *ShadowConfig `json:"shadow,omitempty"` // External bucket to shadow
EventHandlers interface{} `json:"event_handlers,omitempty"` // Event handlers (webhook)
FeedType string `json:"feed_type,omitempty"` // Feed type - "DCP" or "TAP"; defaults based on Couchbase server version
AllowEmptyPassword bool `json:"allow_empty_password,omitempty"` // Allow empty passwords? Defaults to false
CacheConfig *CacheConfig `json:"cache,omitempty"` // Cache settings
ChannelIndex *ChannelIndexConfig `json:"channel_index,omitempty"` // Channel index settings
RevCacheSize *uint32 `json:"rev_cache_size,omitempty"` // Maximum number of revisions to store in the revision cache
StartOffline bool `json:"offline,omitempty"` // start the DB in the offline state, defaults to false
Unsupported *UnsupportedConfig `json:"unsupported,omitempty"` // Config for unsupported features
}
JSON object that defines a database configuration within the ServerConfig.
type DbConfigMap ¶
type EncodedResponseWriter ¶
type EncodedResponseWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
An implementation of http.ResponseWriter that wraps another instance and transparently applies GZip compression when appropriate.
func NewEncodedResponseWriter ¶
func NewEncodedResponseWriter(response http.ResponseWriter, rq *http.Request) *EncodedResponseWriter
Creates a new EncodedResponseWriter, or returns nil if the request doesn't allow encoded responses.
func (*EncodedResponseWriter) Close ¶
func (w *EncodedResponseWriter) Close()
The writer should be closed when output is complete, to flush the GZip encoder buffer.
func (*EncodedResponseWriter) CloseNotify ¶
func (w *EncodedResponseWriter) CloseNotify() <-chan bool
func (*EncodedResponseWriter) Flush ¶
func (w *EncodedResponseWriter) Flush()
Flushes the GZip encoder buffer, and if possible flushes output to the network.
func (*EncodedResponseWriter) WriteHeader ¶
func (w *EncodedResponseWriter) WriteHeader(status int)
type EventConfig ¶
type EventHandlerConfig ¶
type EventHandlerConfig struct {
MaxEventProc uint `json:"max_processes,omitempty"` // Max concurrent event handling goroutines
WaitForProcess string `json:"wait_for_process,omitempty"` // Max wait time when event queue is full (ms)
DocumentChanged []*EventConfig `json:"document_changed,omitempty"` // Document Commit
DBStateChanged []*EventConfig `json:"db_state_changed,omitempty"` // DB state change
}
type FacebookConfig ¶
type FacebookConfig struct {
Register bool // If true, server will register new user accounts
}
type FacebookResponse ¶
type GoogleConfig ¶
type GoogleResponse ¶
type PersonaConfig ¶
type PersonaResponse ¶
type PersonaResponse struct {
Status string // "okay" or "failure"
Reason string // On failure, the error message
Email string // The verified email address
Audience string // The audience value; expected to be your own website URL
Expires uint64 // Date assertion expires, as milliseconds since 1/1/1970
Issuer string // Hostname of the identity provider that issued the assertion
}
Response from a Persona assertion verification. VerifyPersona will never return a response whose status is not "okay"; returns nil instead.
func VerifyPersona ¶
func VerifyPersona(assertion string, audience string) (*PersonaResponse, error)
Verifies a Persona/BrowserID assertion received from a client, returning either the verification response (which includes the verified email address) or an error. The 'audience' parameter must be the same as the 'origin' parameter the client used when requesting the assertion, i.e. the root URL of this website.
type SequenceHashConfig ¶
type SequenceHashConfig struct {
BucketConfig // Bucket used for Sequence hashing
Expiry *uint32 `json:"expiry,omitempty"` // Expiry set for hash values on latest use
Frequency *int `json:"hash_frequency,omitempty"` // Frequency of sequence hashing in changes feeds
}
type ServerConfig ¶
type ServerConfig struct {
Interface *string `json:",omitempty"` // Interface to bind REST API to, default ":4984"
SSLCert *string `json:",omitempty"` // Path to SSL cert file, or nil
SSLKey *string `json:",omitempty"` // Path to SSL private key file, or nil
ServerReadTimeout *int `json:",omitempty"` // maximum duration.Second before timing out read of the HTTP(S) request
ServerWriteTimeout *int `json:",omitempty"` // maximum duration.Second before timing out write of the HTTP(S) response
AdminInterface *string `json:",omitempty"` // Interface to bind admin API to, default ":4985"
AdminUI *string `json:",omitempty"` // Path to Admin HTML page, if omitted uses bundled HTML
ProfileInterface *string `json:",omitempty"` // Interface to bind Go profile API to (no default)
ConfigServer *string `json:",omitempty"` // URL of config server (for dynamic db discovery)
Persona *PersonaConfig `json:",omitempty"` // Configuration for Mozilla Persona validation
Facebook *FacebookConfig `json:",omitempty"` // Configuration for Facebook validation
Google *GoogleConfig `json:",omitempty"` // Configuration for Google validation
CORS *CORSConfig `json:",omitempty"` // Configuration for allowing CORS
Log []string `json:",omitempty"` // Log keywords to enable
LogFilePath *string `json:",omitempty"` // Path to log file, if missing write to stderr
Pretty bool `json:",omitempty"` // Pretty-print JSON responses?
DeploymentID *string `json:",omitempty"` // Optional customer/deployment ID for stats reporting
StatsReportInterval *float64 `json:",omitempty"` // Optional stats report interval (0 to disable)
MaxCouchbaseConnections *int `json:",omitempty"` // Max # of sockets to open to a Couchbase Server node
MaxCouchbaseOverflow *int `json:",omitempty"` // Max # of overflow sockets to open
CouchbaseKeepaliveInterval *int `json:",omitempty"` // TCP keep-alive interval between SG and Couchbase server
SlowServerCallWarningThreshold *int `json:",omitempty"` // Log warnings if database calls take this many ms
MaxIncomingConnections *int `json:",omitempty"` // Max # of incoming HTTP connections to accept
MaxFileDescriptors *uint64 `json:",omitempty"` // Max # of open file descriptors (RLIMIT_NOFILE)
CompressResponses *bool `json:",omitempty"` // If false, disables compression of HTTP responses
Databases DbConfigMap `json:",omitempty"` // Pre-configured databases, mapped by name
MaxHeartbeat uint64 `json:",omitempty"` // Max heartbeat value for _changes request (seconds)
ClusterConfig *ClusterConfig `json:"cluster_config,omitempty"` // Bucket and other config related to CBGT
SkipRunmodeValidation bool `json:"skip_runmode_validation,omitempty"` // If this is true, skips any config validation regarding accel vs normal mode
}
JSON object that defines the server configuration.
func ReadServerConfig ¶
func ReadServerConfig(path string) (*ServerConfig, error)
Reads a ServerConfig from either a JSON file or from a URL.
func ReadServerConfigFromData ¶
func ReadServerConfigFromData(data []byte) (*ServerConfig, error)
Reads a ServerConfig from raw data
func ReadServerConfigFromFile ¶
func ReadServerConfigFromFile(path string) (*ServerConfig, error)
Reads a ServerConfig from a JSON file.
func ReadServerConfigFromUrl ¶
func ReadServerConfigFromUrl(url string) (*ServerConfig, error)
Reads a ServerConfig from a URL.
func (*ServerConfig) HasAnyIndexReaderConfiguredDatabases ¶
func (config *ServerConfig) HasAnyIndexReaderConfiguredDatabases() bool
func (*ServerConfig) HasAnyIndexWriterConfiguredDatabases ¶
func (config *ServerConfig) HasAnyIndexWriterConfiguredDatabases() bool
func (*ServerConfig) MergeWith ¶
func (self *ServerConfig) MergeWith(other *ServerConfig) error
func (*ServerConfig) NumIndexReaders ¶
func (config *ServerConfig) NumIndexReaders() int
func (*ServerConfig) NumIndexWriters ¶
func (config *ServerConfig) NumIndexWriters() int
type ServerContext ¶
type ServerContext struct {
HTTPClient *http.Client
CbgtContext base.CbgtContext
// contains filtered or unexported fields
}
Shared context of HTTP handlers: primarily a registry of databases by name. It also stores the configuration settings so handlers can refer to them. This struct is accessed from HTTP handlers running on multiple goroutines, so it needs to be thread-safe.
func NewServerContext ¶
func NewServerContext(config *ServerConfig) *ServerContext
func (*ServerContext) AddDatabaseFromConfig ¶
func (sc *ServerContext) AddDatabaseFromConfig(config *DbConfig) (*db.DatabaseContext, error)
Adds a database to the ServerContext given its configuration. If an existing config is found for the name, returns an error.
func (*ServerContext) AllDatabaseNames ¶
func (sc *ServerContext) AllDatabaseNames() []string
func (*ServerContext) Close ¶
func (sc *ServerContext) Close()
func (*ServerContext) GetConfig ¶
func (sc *ServerContext) GetConfig() *ServerConfig
func (*ServerContext) GetDatabase ¶
func (sc *ServerContext) GetDatabase(name string) (*db.DatabaseContext, error)
Returns the DatabaseContext with the given name
func (*ServerContext) GetDatabaseConfig ¶
func (sc *ServerContext) GetDatabaseConfig(name string) *DbConfig
func (*ServerContext) HasIndexWriters ¶
func (sc *ServerContext) HasIndexWriters() bool
func (*ServerContext) InitCBGT ¶
func (sc *ServerContext) InitCBGT() error
func (*ServerContext) InitCBGTManager ¶
func (sc *ServerContext) InitCBGTManager() (base.CbgtContext, error)
func (*ServerContext) NewSyncGatewayPIndexFactory ¶
func (sc *ServerContext) NewSyncGatewayPIndexFactory(indexType, indexParams, path string, restart func()) (cbgt.PIndexImpl, cbgt.Dest, error)
When CBGT is opening a PIndex for the first time, it will call back this method.
func (*ServerContext) OpenSyncGatewayPIndexFactory ¶
func (sc *ServerContext) OpenSyncGatewayPIndexFactory(indexType, path string, restart func()) (cbgt.PIndexImpl, cbgt.Dest, error)
When CBGT is re-opening an existing PIndex (after a Sync Gw restart for example), it will call back this method.
func (*ServerContext) ReloadDatabaseFromConfig ¶
func (sc *ServerContext) ReloadDatabaseFromConfig(reloadDbName string, useExisting bool) (*db.DatabaseContext, error)
Adds a database to the ServerContext. Attempts a read after it gets the write lock to see if it's already been added by another process. If so, returns either the existing DatabaseContext or an error based on the useExisting flag.
func (*ServerContext) RemoveDatabase ¶
func (sc *ServerContext) RemoveDatabase(dbName string) bool
func (*ServerContext) Stats ¶
func (sc *ServerContext) Stats() map[string]interface{}
func (*ServerContext) SyncGatewayPIndexFactoryCommon ¶
func (sc *ServerContext) SyncGatewayPIndexFactoryCommon(indexParams base.SyncGatewayIndexParams) (cbgt.PIndexImpl, cbgt.Dest, error)
type ShadowConfig ¶
type ShadowConfig struct {
BucketConfig
Doc_id_regex *string `json:"doc_id_regex,omitempty"` // Optional regex that doc IDs must match
FeedType string `json:"feed_type,omitempty"` // Feed type - "DCP" or "TAP"; defaults to TAP
}
func (*ShadowConfig) GetCredentials ¶
func (shadowConfig *ShadowConfig) GetCredentials() (string, string, string)
Implementation of AuthHandler interface for ShadowConfig
type SyncGatewayRunMode ¶
type SyncGatewayRunMode uint8
const ( SyncGatewayRunModeNormal SyncGatewayRunMode = iota SyncGatewayRunModeAccel )
type UnsupportedConfig ¶
type UnsupportedConfig struct {
UserViews *UserViewsConfig `json:"user_views,omitempty"` // Config settings for user views
}
type UserAgentVersion ¶
type UserAgentVersion struct {
// contains filtered or unexported fields
}
func NewUserAgentVersion ¶
func NewUserAgentVersion(requestHeader string) *UserAgentVersion
func (UserAgentVersion) IsBefore ¶
func (uav UserAgentVersion) IsBefore(otherMajorVersion, otherMinorVersion int) bool
func (UserAgentVersion) IsEqualToOrAfter ¶
func (uav UserAgentVersion) IsEqualToOrAfter(otherMajorVersion, otherMinorVersion int) bool
func (UserAgentVersion) MajorVersion ¶
func (uav UserAgentVersion) MajorVersion() int
func (UserAgentVersion) MinorVersion ¶
func (uav UserAgentVersion) MinorVersion() int
type UserViewsConfig ¶
type UserViewsConfig struct {
Enabled *bool `json:"enabled,omitempty"` // Whether pass-through view query is supported through public API
}