Documentation ¶
Index ¶
- Variables
- func AddAccessControl(r *http.Request, rw http.ResponseWriter)
- func DiffOfObjects(a, b interface{}) (diff.Changelog, error)
- func EndpointsHandler(ctx requestContext.Context, userSessions SessionManager, pw localuser.PwHasher, ...) http.HandlerFunc
- func ErrApiDatabase(key string, err error) error
- func ErrApiInputValidation(msg, key string) error
- func ErrApiInternalError(msg, key string, err error) error
- func ErrApiMissingArgument(key string) error
- func ErrApiNotAuthorized(key, verb string) error
- func ErrApiNotFound(key string, input string) error
- func ErrApiNotImplemeted(key string) error
- func ExtractParams(r *http.Request) (url.Values, error)
- func GetParams(r *http.Request) httprouter.Params
- func GetRequestSession(r *http.Request) (session types.Session, err error)
- func ImportDescriptionsIntoProject(l logger.AppLogger, db types.Storage, createdBy string, project types.Project, ...) (*ImportResult, *Error)
- func ImportIntoProject(l logger.AppLogger, db types.Storage, kind string, createdBy string, ...) (*ImportResult, *Error)
- func NewApiErr(err error, statusCode int, code string, details ...interface{}) requestContext.APIError
- func NewApiError(msg string, statusCode int, code string, details ...interface{}) requestContext.APIError
- func NewAuthHandler(userSessions SessionManager) func(http.ResponseWriter, *http.Request) (*http.Request, error)
- func NewWsHandler(l logger.AppLogger, sendChannel chan Msg, options WsOptions) http.HandlerFunc
- func PingHandler(next http.Handler) http.Handler
- func StripBeforeLast(s, sep string) string
- func UpdateTranslationFromInferrence(db types.Storage, et types.ExtendedTranslation, ...) (*types.Translation, error)
- func ValidateClientVersion(rw http.ResponseWriter, r *http.Request) error
- type AccessControl
- type AdditionalValue
- type AppHandler
- func ChangePassword(db UserStorage, pwKeeper PasswordKeeper, sessionReplace SessionReplacer) AppHandler
- func CreateOrganization(db types.OrgStorage) AppHandler
- func CreateProject(db types.Storage) AppHandler
- func CreateToken(sessionCreator SessionCreator) AppHandler
- func CreateTranslation() AppHandler
- func DeleteTranslation() AppHandler
- func GetCategory(db types.Storage) AppHandler
- func GetDiff(exportCache Cache) AppHandler
- func GetExport(exportCache Cache) AppHandler
- func GetMissing(db MissingStorage) AppHandler
- func GetOrgForJoinID(db types.Storage) AppHandler
- func GetOrganization(db types.OrgStorage) AppHandler
- func GetProjects(db types.Storage) AppHandler
- func GetServerInfo(sizer Sizer, serverInfo func() *types.ServerInfo) AppHandler
- func GetTranslations() AppHandler
- func JoinOrgFromJoinID(db types.Storage, pw PasswordKeeper) AppHandler
- func ListUsers(db UserStorage, simpleusers bool) AppHandler
- func PostCategory(db types.Storage) AppHandler
- func PostMissing(db types.Storage) AppHandler
- func PostSnapshot(uploaders []uploader.FileUploader) AppHandler
- func UpdateCategory(db types.Storage) AppHandler
- func UpdateOrganization(db types.OrgStorage) AppHandler
- func UpdateProject(db types.Storage) AppHandler
- func UpdateTranslation() AppHandler
- type Cache
- type CallingClient
- type Client
- type ClientList
- type DiffChangeWithOffset
- type Error
- type ImportDiff
- type ImportIntoProjectOptions
- type ImportResult
- type MissingStorage
- type Msg
- type PasswordKeeper
- type PubSub
- type SessionCreator
- type SessionManager
- type SessionReplacer
- type Sizer
- type Updates
- type UserStorage
- type WsOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
CodeInternalServerError requestContext.ErrorCodes = "Internal server error"
)
var (
ContextKeySession = "session"
)
var (
ErrApiInternalErrorMissingSession = NewApiError("Missing session", http.StatusBadGateway, string(CodeInternalServerError))
)
var Ok = models.OkResponse{Ok: boolPointer(true)}
Functions ¶
func AddAccessControl ¶
func AddAccessControl(r *http.Request, rw http.ResponseWriter)
func DiffOfObjects ¶ added in v0.8.1
func DiffOfObjects(a, b interface{}) (diff.Changelog, error)
DiffOfObjects returns a changelog with options set for use with for instance i18n-json.
func EndpointsHandler ¶
func EndpointsHandler( ctx requestContext.Context, userSessions SessionManager, pw localuser.PwHasher, swaggerYml []byte, ) http.HandlerFunc
Deprecated. Migrating to using httproutermux
func ErrApiDatabase ¶
func ErrApiInputValidation ¶
func ErrApiInternalError ¶ added in v0.8.0
func ErrApiMissingArgument ¶
func ErrApiNotAuthorized ¶
func ErrApiNotFound ¶
func ErrApiNotImplemeted ¶ added in v0.8.0
func ExtractParams ¶
Extracts queryparameters from path and query-params. This is useful for caching
Example ¶
package main import ( "fmt" "net/http" "github.com/runar-rkmedia/skiver/handlers" ) func main() { r, _ := http.NewRequest(http.MethodGet, "/api/export/foo=3&feature", nil) fmt.Println(handlers.ExtractParams(r)) }
Output: map[feature:[] foo:[3]] <nil>
Example (Basic) ¶
package main import ( "fmt" "net/http" "github.com/runar-rkmedia/skiver/handlers" ) func main() { r, _ := http.NewRequest(http.MethodGet, "/api/export/?foo=3&feature", nil) fmt.Println(handlers.ExtractParams(r)) }
Output: map[feature:[] foo:[3]] <nil>
func ImportDescriptionsIntoProject ¶ added in v0.8.1
func ImportIntoProject ¶
func NewApiErr ¶
func NewApiErr(err error, statusCode int, code string, details ...interface{}) requestContext.APIError
func NewApiError ¶
func NewApiError(msg string, statusCode int, code string, details ...interface{}) requestContext.APIError
func NewAuthHandler ¶
func NewAuthHandler( userSessions SessionManager, ) func(http.ResponseWriter, *http.Request) (*http.Request, error)
func NewWsHandler ¶
func StripBeforeLast ¶
Removes the characters before the last occureance of `sep` and the `sep` if available
Example ¶
package main import ( "fmt" "github.com/runar-rkmedia/skiver/handlers" ) func main() { fmt.Println(handlers.StripBeforeLast("/api/export/foo", "/")) }
Output: foo
func UpdateTranslationFromInferrence ¶
func UpdateTranslationFromInferrence(db types.Storage, et types.ExtendedTranslation, additionalValues []AdditionalValue, interpolationMaps []map[string]interface{}) (*types.Translation, error)
updates a Translation based on updates to its values. The additionalValues are meant to be new values to consider for inferrence. If the Translation already has a value for the same LocaleID/Context as an additionalValue, the existing value will not be considered.
func ValidateClientVersion ¶ added in v0.8.1
func ValidateClientVersion(rw http.ResponseWriter, r *http.Request) error
temporary check for clients before they upgrade to a version of
Types ¶
type AccessControl ¶
type AdditionalValue ¶
type AppHandler ¶
type AppHandler = func(requestContext.ReqContext, http.ResponseWriter, *http.Request) (interface{}, error)
func ChangePassword ¶
func ChangePassword(db UserStorage, pwKeeper PasswordKeeper, sessionReplace SessionReplacer) AppHandler
func CreateOrganization ¶ added in v0.8.0
func CreateOrganization(db types.OrgStorage) AppHandler
func CreateProject ¶ added in v0.8.0
func CreateProject(db types.Storage) AppHandler
func CreateToken ¶
func CreateToken(sessionCreator SessionCreator) AppHandler
func CreateTranslation ¶
func CreateTranslation() AppHandler
func DeleteTranslation ¶
func DeleteTranslation() AppHandler
func GetCategory ¶
func GetCategory(db types.Storage) AppHandler
func GetDiff ¶
func GetDiff(exportCache Cache) AppHandler
func GetExport ¶
func GetExport( exportCache Cache, ) AppHandler
func GetMissing ¶
func GetMissing(db MissingStorage) AppHandler
func GetOrgForJoinID ¶ added in v0.8.0
func GetOrgForJoinID(db types.Storage) AppHandler
func GetOrganization ¶ added in v0.8.0
func GetOrganization(db types.OrgStorage) AppHandler
func GetProjects ¶ added in v0.8.0
func GetProjects(db types.Storage) AppHandler
func GetServerInfo ¶
func GetServerInfo(sizer Sizer, serverInfo func() *types.ServerInfo) AppHandler
func GetTranslations ¶
func GetTranslations() AppHandler
func JoinOrgFromJoinID ¶ added in v0.8.0
func JoinOrgFromJoinID(db types.Storage, pw PasswordKeeper) AppHandler
func ListUsers ¶
func ListUsers(db UserStorage, simpleusers bool) AppHandler
func PostCategory ¶
func PostCategory(db types.Storage) AppHandler
func PostMissing ¶
func PostMissing(db types.Storage) AppHandler
func PostSnapshot ¶
func PostSnapshot(uploaders []uploader.FileUploader) AppHandler
PostSnapshot creates a snapshot if there does not exist one already with the same hash.
func UpdateCategory ¶
func UpdateCategory(db types.Storage) AppHandler
func UpdateOrganization ¶ added in v0.8.0
func UpdateOrganization(db types.OrgStorage) AppHandler
func UpdateProject ¶ added in v0.8.0
func UpdateProject(db types.Storage) AppHandler
func UpdateTranslation ¶
func UpdateTranslation() AppHandler
type CallingClient ¶ added in v0.8.1
func GetClientVersionFromRequest ¶ added in v0.8.1
func GetClientVersionFromRequest(r *http.Request) (client CallingClient, found bool)
type ClientList ¶
func (*ClientList) Subscribe ¶
func (cl *ClientList) Subscribe(c *Client)
func (*ClientList) Unsubscribe ¶
func (cl *ClientList) Unsubscribe(id string)
func (*ClientList) Writer ¶
func (cl *ClientList) Writer(ch chan Msg)
type DiffChangeWithOffset ¶ added in v0.8.1
type Error ¶
func NewError ¶
func NewError(message string, code requestContext.ErrorCodes, details ...interface{}) *Error
func (*Error) GetApiError ¶
func (Error) GetCode ¶
func (err Error) GetCode() requestContext.ErrorCodes
func (Error) GetStatusCode ¶
type ImportDiff ¶ added in v0.8.1
type ImportDiff struct { Updates map[string]DiffChangeWithOffset `json:"updates,omitempty"` Creations map[string]DiffChangeWithOffset `json:"creations,omitempty"` }
type ImportIntoProjectOptions ¶ added in v0.8.1
type ImportResult ¶
type ImportResult struct { Diff ImportDiff `json:"diff,omitempty"` ChangeSet []importexport.ChangeRequest `json:"change_set,omitempty"` Warnings []importexport.Warning `json:"warnings,omitempty"` }
TODO: Reevaluate this structure.
type MissingStorage ¶
type MissingStorage interface { ReportMissing(key types.MissingTranslation) (*types.MissingTranslation, error) GetMissingKeysFilter(max int, filter ...types.MissingTranslation) (map[string]types.MissingTranslation, error) }
type PasswordKeeper ¶
type PubSub ¶
type PubSub struct {
Ch chan Msg
}
func NewPubSubChannel ¶
func NewPubSubChannel() PubSub
type SessionCreator ¶
type SessionCreator interface {
NewSession(user types.User, organization types.Organization, userAgent string, opts ...types.UserSessionOptions) (s types.Session)
}
type SessionManager ¶
type SessionManager interface { NewSession(user types.User, organization types.Organization, userAgent string, opts ...types.UserSessionOptions) (s types.Session) GetSession(token string) (s types.Session, err error) SessionsForUser(userId string) (s []types.Session) ClearAllSessionsForUser(userId string) error ClearSessionById(token string) error TTL() time.Duration }
type SessionReplacer ¶ added in v0.8.0
type Updates ¶
type Updates struct { TranslationValueUpdates map[string]types.TranslationValue TranslationsValueCreations map[string]types.TranslationValue TranslationCreations map[string]types.Translation CategoryCreations map[string]types.Category }