Documentation ¶
Index ¶
- Constants
- Variables
- func AcceptHeaderOk(w http.ResponseWriter, r *http.Request) bool
- func ConvertTimestamp(ts string) (int, error)
- func GetBatchIdAndCommit(r *http.Request) (batchFound bool, batchId string, batchCommit bool)
- func InternalError(w http.ResponseWriter, r *http.Request, err error)
- func JSON(w http.ResponseWriter, r *http.Request, statusCode int, val interface{})
- func JSONError(w http.ResponseWriter, msg string, code int)
- func JsonNewline(w http.ResponseWriter, r *http.Request, val interface{})
- func JsonNewlineStatus(w http.ResponseWriter, r *http.Request, statusCode int, val interface{})
- func NewLine(w http.ResponseWriter, r *http.Request, statusCode int, val interface{})
- func NewLogHandler(l logrus.FieldLogger, h http.Handler) http.Handler
- func NewSessionContext(ctx context.Context, ses *Session) context.Context
- func NewWeaveHandler(h http.Handler) http.Handler
- func OKResponse(w http.ResponseWriter, s string)
- func ReadNewlineJSON(data io.Reader) []json.RawMessage
- func RequestToPostBSOInput(r *http.Request, maxPayloadSize int) (syncstorage.PostBSOInput, *syncstorage.PostResults, error)
- func TwoLevelPath(uid string) []string
- func WeaveInvalidWBOError(w http.ResponseWriter, r *http.Request, reason error)
- func WeaveSizeLimitExceeded(w http.ResponseWriter, r *http.Request, reason error)
- type CacheConfig
- type CacheHandler
- type HawkHandler
- type InfoHandler
- type LoggingHandler
- type MozlogFormatter
- type PostResults
- type PprofHandler
- type Session
- type StoppableHandler
- type SyncPoolConfig
- type SyncPoolHandler
- type SyncUserHandler
- type SyncUserHandlerConfig
- type WeaveWrapperHandler
- type XModHeader
Constants ¶
const ( WEAVE_UNKNOWN_ERROR = "0" WEAVE_ILLEGAL_METH = "1" // Illegal method/protocol WEAVE_MALFORMED_JSON = "6" // Json parse failure WEAVE_INVALID_WBO = "8" // Invalid Weave Basic Object WEAVE_OVER_QUOTA = "14" // User over quota WEAVE_SIZE_LIMIT_EXCEEDED = "17" // Batch X-Weave-* headers too large )
Variables ¶
var ( EmptyData = []byte{} ErrTokenInvalid = errors.New("Token is invalid") ErrTokenExpired = errors.New("Token is expired") )
var (
DefaultCacheHandlerConfig = CacheConfig{
MaxCacheSize: 256,
}
)
Functions ¶
func AcceptHeaderOk ¶
func AcceptHeaderOk(w http.ResponseWriter, r *http.Request) bool
func ConvertTimestamp ¶
ConvertTimestamp converts the sync decimal time in seconds to a time in milliseconds
func GetBatchIdAndCommit ¶
func InternalError ¶
func InternalError(w http.ResponseWriter, r *http.Request, err error)
InternalError produces an HTTP 500 error, basically means a bug in the system
func JsonNewline ¶
func JsonNewline(w http.ResponseWriter, r *http.Request, val interface{})
JsonNewline returns data as newline separated or as a single json array
func JsonNewlineStatus ¶
func JsonNewlineStatus(w http.ResponseWriter, r *http.Request, statusCode int, val interface{})
func NewLine ¶
func NewLine(w http.ResponseWriter, r *http.Request, statusCode int, val interface{})
NewLine prints out new line \n separated JSON objects instead of a single JSON array of objects
func NewLogHandler ¶
NewLogHandler return a http.Handler that wraps h and logs request out to logrus INFO level with fields
func NewWeaveHandler ¶
WeaveHandler is a convenient and messy place to capture sync 1.5, and legacy weave specific functionality. TODO will have to implement http.Hijack()
func OKResponse ¶
func OKResponse(w http.ResponseWriter, s string)
OKResponse writes a 200 response with a simple string body
func ReadNewlineJSON ¶
func ReadNewlineJSON(data io.Reader) []json.RawMessage
ReadNewlineDelimitedJSON takes newline separate JSON and produces produces an array of json.RawMessage
func RequestToPostBSOInput ¶
func RequestToPostBSOInput(r *http.Request, maxPayloadSize int) ( syncstorage.PostBSOInput, *syncstorage.PostResults, error, )
RequestToPostBSOInput extracts and unmarshals request.Body into a syncstorage.PostBSOInput. It returns a PostResults as well since it also validates BSOs
func TwoLevelPath ¶
TwoLevelPath creates a reverse sub-directory path structure e.g. uid:123456 => DATA_ROOT/65/43/123456.db
func WeaveInvalidWBOError ¶
func WeaveInvalidWBOError(w http.ResponseWriter, r *http.Request, reason error)
func WeaveSizeLimitExceeded ¶
func WeaveSizeLimitExceeded(w http.ResponseWriter, r *http.Request, reason error)
Types ¶
type CacheConfig ¶
type CacheConfig struct {
MaxCacheSize int // megabytes
}
type CacheHandler ¶
type CacheHandler struct {
// contains filtered or unexported fields
}
CacheHandler contains logic for caching and speeding up requests that do not need to go to disk. Endpoints such as info/collections and info/configuration can be cached and served out of RAM.
func NewCacheHandler ¶
func NewCacheHandler(handler http.Handler, cacheConfig CacheConfig) *CacheHandler
func (*CacheHandler) ServeHTTP ¶
func (s *CacheHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type HawkHandler ¶
type HawkHandler struct {
// contains filtered or unexported fields
}
func NewHawkHandler ¶
func NewHawkHandler(handler http.Handler, secrets []string) *HawkHandler
func (*HawkHandler) ServeHTTP ¶
func (h *HawkHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type InfoHandler ¶
type InfoHandler struct {
// contains filtered or unexported fields
}
InfoHandler serves endpoints that are not part of the sync 1.5 api that a syncserver should provide
func NewInfoHandler ¶
func NewInfoHandler(h http.Handler) *InfoHandler
func (*InfoHandler) ServeHTTP ¶
func (h *InfoHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type LoggingHandler ¶
type LoggingHandler struct { OnlyHTTPErrors bool // contains filtered or unexported fields }
func (*LoggingHandler) ServeHTTP ¶
func (h *LoggingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type MozlogFormatter ¶
MozlogFormatter is a custom logrus formatter
type PostResults ¶
used to massage post results into JSON the client expects
func (*PostResults) MarshalJSON ¶
func (p *PostResults) MarshalJSON() ([]byte, error)
MarshalJSON manually creates the JSON string since the modified needs to be converted in the python (ugh) timeformat required for sync 1.5. Which means no quotes
func (*PostResults) UnmarshalJSON ¶
func (p *PostResults) UnmarshalJSON(data []byte) error
UnmarshalJSON reverses custom formatting from MarshalJSON
type PprofHandler ¶
type PprofHandler struct {
// contains filtered or unexported fields
}
PprofHandler adds net/http/pprof into the system
func NewPprofHandler ¶
func NewPprofHandler(h http.Handler) *PprofHandler
func (*PprofHandler) ServeHTTP ¶
func (h *PprofHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type Session ¶
type Session struct { Token token.TokenPayload ErrorResult error }
type StoppableHandler ¶
type StoppableHandler struct { sync.Mutex RetryAfter string // contains filtered or unexported fields }
StoppableHandler abstracts common logic to stop serving regular traffic
func (*StoppableHandler) IsStopped ¶
func (s *StoppableHandler) IsStopped() bool
func (*StoppableHandler) ServeHTTP ¶
func (s *StoppableHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*StoppableHandler) StopHTTP ¶
func (s *StoppableHandler) StopHTTP()
type SyncPoolConfig ¶
type SyncPoolConfig struct { Basepath string NumPools int TTL time.Duration MaxPoolSize int VacuumKB int PurgeMinHours int PurgeMaxHours int DBConfig *syncstorage.Config }
func NewDefaultSyncPoolConfig ¶
func NewDefaultSyncPoolConfig(basepath string) *SyncPoolConfig
type SyncPoolHandler ¶
type SyncPoolHandler struct { StoppableHandler // contains filtered or unexported fields }
func NewSyncPoolHandler ¶
func NewSyncPoolHandler(config *SyncPoolConfig, userHandlerConfig *SyncUserHandlerConfig) *SyncPoolHandler
func (*SyncPoolHandler) ServeHTTP ¶
func (s *SyncPoolHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
proxyHandler extracts the UID from the URL and passes control over to one of the internal handlers
func (*SyncPoolHandler) StopHTTP ¶
func (s *SyncPoolHandler) StopHTTP()
Stop immediately stops serving web requests and then it stops all additional handlers
type SyncUserHandler ¶
type SyncUserHandler struct { StoppableHandler // contains filtered or unexported fields }
SyncUserHandler provides all the sync 1.5 API routes for a single user. It implements http.Handler. It's design is kept simple on purpose to make it easy to wrap it in other http.Handler.
func NewSyncUserHandler ¶
func NewSyncUserHandler(uid string, db *syncstorage.DB, config *SyncUserHandlerConfig) *SyncUserHandler
func (*SyncUserHandler) ServeHTTP ¶
func (s *SyncUserHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*SyncUserHandler) StopHTTP ¶
func (s *SyncUserHandler) StopHTTP()
Stop immediately prevents handling web requests then purges expired BSOs before closing the DB.
func (*SyncUserHandler) TidyUp ¶
func (s *SyncUserHandler) TidyUp(minPurge, maxPurge time.Duration, vacuumKB int) (skipped bool, took time.Duration, err error)
TidyUp will purge expired BSOs and Batches. When the database has exceeded vacuumKB (in kilobytes) it will be optimized. This could potentially be a long operation as the database vacuumed needs to rewrite the entire database file
type SyncUserHandlerConfig ¶
type SyncUserHandlerConfig struct { // API Limits MaxRequestBytes int MaxPOSTRecords int MaxPOSTBytes int MaxTotalRecords int MaxTotalBytes int MaxBatchTTL int MaxRecordPayloadBytes int // largest BSO payload }
func NewDefaultSyncUserHandlerConfig ¶
func NewDefaultSyncUserHandlerConfig() *SyncUserHandlerConfig
type WeaveWrapperHandler ¶
type WeaveWrapperHandler struct {
// contains filtered or unexported fields
}
func (*WeaveWrapperHandler) ServeHTTP ¶
func (weave *WeaveWrapperHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type XModHeader ¶
type XModHeader int
The code below is a little weird and inelegant. Basically its purpose is to reduce boilerplate in the handlers for dealing with the X-If-Modified-Since and X-If-Unmodified-Since header logic from clients
const ( X_TS_HEADER_NONE XModHeader = iota X_IF_MODIFIED_SINCE // X-If-Modified-Since X_IF_UNMODIFIED_SINCE // X-If-Unmodified )