uBrowserSync/syncstore/blob.go

59 lines
1.3 KiB
Go

package syncstore
import (
"fmt"
"net/http"
"time"
)
type Blob struct {
ID string `json:"id"`
Bookmarks string `json:"bookmarks"`
Version string `json:"version"`
Created time.Time `json:"created"`
LastUpdated time.Time `json:"lastUpdated"`
LastAccessed time.Time `json:"lastAccessed"`
}
type ErrorPayload struct {
Code string `json:"code"`
Message string `json:"message"`
}
type SyncError struct {
StatusCode int
Payload ErrorPayload
}
func (e SyncError) Error() string {
return fmt.Sprintf("code: %s, message: %s", e.Payload.Code, e.Payload.Message)
}
func NewSyncError(code string, message string, status int) SyncError {
return SyncError{
StatusCode: status,
Payload: ErrorPayload{
Code: code,
Message: message}}
}
var NotImplementedError = NewSyncError(
"NotImplementedException",
"The requested route has not been implemented",
http.StatusNotFound)
var MethodNotImplementedError = NewSyncError(
"NotImplementedException",
"The requested method has not been implemented",
http.StatusMethodNotAllowed)
var SyncNotFoundError = NewSyncError(
"SyncNotFoundException",
"Sync does not exist",
http.StatusUnauthorized)
var SyncConflictError = NewSyncError(
"SyncConflictException",
"A sync conflict was detected",
http.StatusConflict)