Documentation ¶
Index ¶
- Constants
- Variables
- func CreateAdminHandler(sc *ServerContext) http.Handler
- func CreateAdminHandlerForRouter(sc *ServerContext, r *mux.Router) http.Handler
- func CreateAdminRouter(sc *ServerContext) *mux.Router
- func CreatePublicHandler(sc *ServerContext) http.Handler
- func FixQuotedSlashes(rq *http.Request)
- func GetGZipWriter(writer io.Writer) *gzip.Writer
- func HandleSighup()
- func NewLoggerTeeResponseWriter(wrappedResponseWriter http.ResponseWriter, logKey string, serialNum uint64, ...) http.ResponseWriter
- func NewTeeReadCloser(r io.ReadCloser, w io.Writer) io.ReadCloser
- func ParseCommandLine(runMode SyncGatewayRunMode)
- func ReturnGZipWriter(gz *gzip.Writer)
- func RunServer(config *ServerConfig)
- func ServerMain(runMode SyncGatewayRunMode)
- func SetMaxFileDescriptors(maxP *uint64)
- func ValidateConfigOrPanic(runMode SyncGatewayRunMode)
- type AuthState
- type AuthorizeParameters
- 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 Http2Config
- type LoggingTeeResponseWriter
- type OIDCTokenResponse
- type OidcTokenResponse
- type Page
- type ReplConfigMap
- type ReplicationConfig
- type SequenceHashConfig
- type ServerConfig
- func GetConfig() *ServerConfig
- func ReadServerConfig(runMode SyncGatewayRunMode, path string) (*ServerConfig, error)
- func ReadServerConfigFromData(runMode SyncGatewayRunMode, data []byte) (*ServerConfig, error)
- func ReadServerConfigFromFile(runMode SyncGatewayRunMode, path string) (*ServerConfig, error)
- func ReadServerConfigFromUrl(runMode SyncGatewayRunMode, url string) (*ServerConfig, error)
- 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
- func (config *ServerConfig) Serve(addr string, handler http.Handler)
- type ServerContext
- func (sc *ServerContext) AddDatabaseFromConfig(config *DbConfig) (*db.DatabaseContext, error)
- func (sc *ServerContext) AllDatabaseNames() []string
- func (sc *ServerContext) AllDatabases() map[string]*db.DatabaseContext
- func (sc *ServerContext) Close()
- func (sc *ServerContext) Database(name string) *db.DatabaseContext
- func (sc *ServerContext) FindDbByBucketName(bucketName string) string
- 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) 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) TakeDbOnline(database *db.DatabaseContext)
- type ShadowConfig
- type SyncGatewayRunMode
- type TeeReadCloser
- type TokenRequestType
- type UnsupportedServerConfig
- type UserAgentVersion
Constants ¶
const ( DefaultMaxCouchbaseConnections = 16 DefaultMaxCouchbaseOverflowConnections = 0 // Default value of ServerConfig.MaxIncomingConnections DefaultMaxIncomingConnections = 0 // Default value of ServerConfig.MaxFileDescriptors DefaultMaxFileDescriptors uint64 = 5000 )
const ( OIDC_AUTH_RESPONSE_TYPE = "response_type" OIDC_AUTH_CLIENT_ID = "client_id" OIDC_AUTH_SCOPE = "scope" OIDC_AUTH_REDIRECT_URI = "redirect_uri" OIDC_AUTH_STATE = "state" OIDC_RESPONSE_TYPE_CODE = "code" OIDC_RESPONSE_TYPE_IMPLICIT = "id_token%20token" )
const GitBranch = ""
const GitCommit = ""
const GitDirty = ""
const GitProductName = ""
The git commit that was compiled. This will be filled in by the compiler.
const KDefaultNumShards = 16
const ServerName = "@PRODUCT_NAME@" // 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.5 // 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 ProductName string
Either comes from Gerrit (jenkins builds) or Git (dev builds)
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 CreateAdminHandlerForRouter ¶
func CreateAdminHandlerForRouter(sc *ServerContext, r *mux.Router) http.Handler
func CreateAdminRouter ¶
func CreateAdminRouter(sc *ServerContext) *mux.Router
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 FixQuotedSlashes ¶
func GetGZipWriter ¶
Gets a gzip writer from the pool, or creates a new one if the pool is empty:
func HandleSighup ¶
func HandleSighup()
for now just cycle the logger to allow for log file rotation
func NewLoggerTeeResponseWriter ¶
func NewLoggerTeeResponseWriter(wrappedResponseWriter http.ResponseWriter, logKey string, serialNum uint64, req *http.Request) http.ResponseWriter
func NewTeeReadCloser ¶
func NewTeeReadCloser(r io.ReadCloser, w io.Writer) io.ReadCloser
func ParseCommandLine ¶
func ParseCommandLine(runMode SyncGatewayRunMode)
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 SetMaxFileDescriptors ¶
func SetMaxFileDescriptors(maxP *uint64)
func ValidateConfigOrPanic ¶
func ValidateConfigOrPanic(runMode SyncGatewayRunMode)
Types ¶
type AuthorizeParameters ¶
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 db.UnsupportedOptions `json:"unsupported,omitempty"` // Config for unsupported features OIDCConfig *auth.OIDCOptions `json:"oidc,omitempty"` // Config properties for OpenID Connect authentication }
JSON object that defines a database configuration within the ServerConfig.
func (*DbConfig) GetCredentials ¶
Implementation of AuthHandler interface for DbConfig
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 Http2Config ¶
type Http2Config struct {
Enabled *bool `json:"enabled,omitempty"` // Whether HTTP2 support is enabled
}
type LoggingTeeResponseWriter ¶
type LoggingTeeResponseWriter struct { http.ResponseWriter LogKey string // The log key to use, eg "HTTP+" SerialNumber uint64 // The request ID Request *http.Request // The request }
A ResponseWriter that wraps another ResponseWriter, and dumps a copy of everything to the logging key
type OIDCTokenResponse ¶
type OIDCTokenResponse struct { IDToken string `json:"id_token"` // ID token, from OP RefreshToken string `json:"refresh_token,omitempty"` // Refresh token, from OP SessionID string `json:"session_id,omitempty"` // Sync Gateway session ID Username string `json:"name,omitempty"` // Sync Gateway user name AccessToken string `json:"access_token,omitempty"` // Access token, from OP TokenType string `json:"token_type,omitempty"` // Access token type, from OP Expires int `json:"expires_in,omitempty"` // Access token expiry, from OP }
type OidcTokenResponse ¶
type ReplConfigMap ¶
type ReplConfigMap map[string]*ReplicationConfig
type ReplicationConfig ¶
type ReplicationConfig struct { Source string `json:"source"` Target string `json:"target"` Continuous bool `json:"continuous"` CreateTarget bool `json:"create_target"` DocIds []string `json:"doc_ids"` Filter string `json:"filter"` Proxy string `json:"proxy"` QueryParams interface{} `json:"query_params"` Cancel bool `json:"cancel"` Async bool `json:"async"` ChangesFeedLimit int `json:"changes_feed_limit"` ReplicationId string `json:"replication_id"` }
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) Facebook *FacebookConfig `json:",omitempty"` // Configuration for Facebook validation Google *GoogleConfig `json:",omitempty"` // Configuration for Google validation CORS *CORSConfig `json:",omitempty"` // Configuration for allowing CORS DeprecatedLog []string `json:"log,omitempty"` // Log keywords to enable DeprecatedLogFilePath *string `json:"logFilePath,omitempty"` // Path to log file, if missing write to stderr Logging *base.LoggingConfigMap `json:",omitempty"` // Configuration for logging with optional log file rotation 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 Replications []*ReplicationConfig `json:",omitempty"` 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 Unsupported *UnsupportedServerConfig `json:"unsupported,omitempty"` // Config for unsupported features RunMode SyncGatewayRunMode `json:"runmode,omitempty"` // Whether this is an SG reader or an SG Accelerator }
JSON object that defines the server configuration.
func GetConfig ¶
func GetConfig() *ServerConfig
func ReadServerConfig ¶
func ReadServerConfig(runMode SyncGatewayRunMode, path string) (*ServerConfig, error)
Reads a ServerConfig from either a JSON file or from a URL.
func ReadServerConfigFromData ¶
func ReadServerConfigFromData(runMode SyncGatewayRunMode, data []byte) (*ServerConfig, error)
Reads a ServerConfig from raw data
func ReadServerConfigFromFile ¶
func ReadServerConfigFromFile(runMode SyncGatewayRunMode, path string) (*ServerConfig, error)
Reads a ServerConfig from a JSON file.
func ReadServerConfigFromUrl ¶
func ReadServerConfigFromUrl(runMode SyncGatewayRunMode, 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 ¶
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) AllDatabases ¶
func (sc *ServerContext) AllDatabases() map[string]*db.DatabaseContext
AllDatabases returns a copy of the databases_ map.
func (*ServerContext) Close ¶
func (sc *ServerContext) Close()
func (*ServerContext) Database ¶
func (sc *ServerContext) Database(name string) *db.DatabaseContext
For test use
func (*ServerContext) FindDbByBucketName ¶
func (sc *ServerContext) FindDbByBucketName(bucketName string) string
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) 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) TakeDbOnline ¶
func (sc *ServerContext) TakeDbOnline(database *db.DatabaseContext)
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 TeeReadCloser ¶
type TeeReadCloser struct {
// contains filtered or unexported fields
}
A TeeReader wrapper that can wrap an io.ReadCloser as opposed to just wrapping an io.Reader
func (*TeeReadCloser) Close ¶
func (t *TeeReadCloser) Close() error
type TokenRequestType ¶
type TokenRequestType uint8
const ( TokenRequest_AuthCode TokenRequestType = iota TokenRequest_Refresh )
type UnsupportedServerConfig ¶
type UnsupportedServerConfig struct {
Http2Config *Http2Config `json:"http2,omitempty"` // Config settings for HTTP2
}
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