-
Notifications
You must be signed in to change notification settings - Fork 140
Source Files
This is a quick tour of the Sync Gateway source files, for the benefit of those wanting to dive into the code.
The gateway's packages are nested under github.com/couchbaselabs/sync_gateway, and the corresponding source directories are under src/github.com/couchbaselabs/sync_gateway. I'll go through them in bottom-up order.
Shared utilities used by the other packages.
- bucket.go: Defines a wrapper that adapts the go-couchbase package's
Bucketto match Walrus'sBucketinterface, allowing the two to be used interchangeably by the rest of the code. Also has some factory functions for instantiating buckets. - error.go: Error handling utilities.
- http_listener.go: An implementation of an HTTP listener that can limit the number of simultaneous connections it allows.
- logging.go: A nice logging utility. You'll see calls to
base.LogTo()all over the code. - logging_bucket.go: A wrapper around the Bucket interface that logs info about every call.
- set.go: Implements
Set, a reusable "set of strings" data type. - util.go: Miscellaneous utility functions.
Various types and functions for working with channels.
- change_log.go: The widely-used
LogEntry(represents a change to the database, i.e. a new revision) andChangeLog(an array ofLogEntrys). - channelmapper.go: High-level API to a database's sync function. Adds thread-safety to
SyncRunner. - set.go: Extra functions for using a
base.Setas a set of channel names. Includes channel name validation and some utilities for managing the magic*channel name. - sync_runner.go: Low-level API to a database's sync function. The actual implementation that calls into JavaScript is here, but this level is not thread-safe so it should not be called directly.
- timed_set.go: A map from channel names to sequence numbers.
Manages users and roles and their persistent storage.
- auth.go: The
Authenticatorclass, a factory forUserandRoleobjects. - password_hash.go: Password hashing for authentication.
- principal.go: Defines the abstract
Principalinterface and its two sub-interfacesRoleandUser. - role.go: Concrete implementation of
Roleinterface. - user.go: Concrete implementation of
Userinterface.
There are a number of dependent Go packages. Rather than use the regular Go package manager (go get), which always updates packages to the latest revision available, we add them to the Git repo as submodules, so we can control exactly which revisions we use.
To do this, we change the $GOPATH. The details are in the go.sh script, but basically the GOPATH consists of the root of the repo (for the Gateway sources) and the vendor subdirectory (for the dependent packages). The Git submodules are checked out under vendor/src:
-
github.com/couchbaselabs/go-couchbase: Couchbase Server API -
github.com/couchbaselabs/go.assert: Assertion utilities for unit tests -
github.com/couchbaselabs/sync_gateway_admin_ui: HTML source for the Gateway admin UI -
github.com/couchbaselabs/walrus: Lightweight storage engine for tests and experimentation -
github.com/dustin/gomemcached: Memcached API (used by go-couchbase) -
github.com/gorilla/context: Web-server utility for storing request variables (used by gorilla/mux) -
github.com/gorilla/mux: Rails-like HTTP request routing package -
github.com/robertkrimen/otto: A pure Go JavaScript interpreter -
github.com/samuel/go-metrics: Utilities for computing performance metrics; used for logging -
github.com/tleyden/fakehttp: Mock HTTP server; used by unit tests
Some of the dependent packages don't have Git repositories because they're hosted by Google Code. These are checked in directly. Most of these have several sub-packages of which we use only one or two:
-
code.google.com/p/go.crypto: We use thebcryptpackage for password hashing. -
code.google.com/p/go.net: We use thewebsocketpackage for handling WebSocket requests. -
code.google.com/p/go.text: Walrus uses thecollateandlanguagepackages for Unicode sorting.