Documentation
¶
Overview ¶
Package api manages the api controllers
Index ¶
- Constants
- Variables
- func ErrInvalidRequest(err error) render.Renderer
- func ErrRegister(err error) render.Renderer
- func ErrRender(err error) render.Renderer
- func ErrRenew(err error) render.Renderer
- func ErrReturn(err error) render.Renderer
- func ErrRevoke(err error) render.Renderer
- func ErrServer(err error) render.Renderer
- func NewEventListResponse(events *[]stor.Event) []render.Renderer
- func NewLicenseInfoListResponse(licenses *[]stor.LicenseInfo) []render.Renderer
- func NewPublicationListResponse(publications *[]stor.Publication) []render.Renderer
- type APICtrl
- func (a *APICtrl) CreateLicense(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) CreatePublication(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) DeleteLicense(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) DeletePublication(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) FreshLicense(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) GenerateLicense(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) GetDashboardData(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) GetLicense(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) GetOversharedLicenses(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) GetPublication(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) GetPublicationByAltID(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) ListLicenseEvents(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) ListLicenses(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) ListPublications(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) ListUserLicenses(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) Register(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) Renew(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) ReportGeneratedLicenses(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) Return(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) Revoke(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) SearchLicenses(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) SearchPublications(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) StatusDoc(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) UpdateLicense(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) UpdatePublication(w http.ResponseWriter, r *http.Request)
- type DashboardResponse
- type ErrResponse
- type EventResponse
- type LicenseInfoRequest
- type LicenseInfoResponse
- type LicenseRequest
- type LicenseResponse
- type OversharedLicensesResponse
- type PaginationKey
- type PublicationRequest
- type PublicationResponse
- type StatusDocResponse
Constants ¶
const ERROR_BASE_URL = "http://readium.org/license-status-document/error/"
Error types defined by the License Status Document specification
const REGISTER_ERROR = ERROR_BASE_URL + "registration"
const RENEW_DATE = ERROR_BASE_URL + "renew/date" // unused
const RENEW_ERROR = ERROR_BASE_URL + "renew"
const RETURN_ALREADY = ERROR_BASE_URL + "return/already" // unused
const RETURN_ERROR = ERROR_BASE_URL + "return"
const RETURN_EXPIRED = ERROR_BASE_URL + "return/expired" // unused
const REVOKE_ERROR = ERROR_BASE_URL + "revoke"
Error types defined for this server
const SERVER_ERROR = ERROR_BASE_URL + "server"
Variables ¶
var ( ErrMissingLicenseId = errors.New("missing required license identifier") ErrMissingDeviceInfo = errors.New("missing required device information") )
var ErrNotFound = &ErrResponse{
HTTPStatusCode: 404,
Type: "about:blank",
Title: "Resource not found",
}
Functions ¶
func ErrInvalidRequest ¶
func ErrRegister ¶
func NewEventListResponse ¶
NewEventListResponse creates a rendered list of events
func NewLicenseInfoListResponse ¶
func NewLicenseInfoListResponse(licenses *[]stor.LicenseInfo) []render.Renderer
NewLicenseInfoListResponse creates a rendered list of licenses
func NewPublicationListResponse ¶
func NewPublicationListResponse(publications *[]stor.Publication) []render.Renderer
NewPublicationListResponse creates a rendered list of publications
Types ¶
type APICtrl ¶
APICtrl contains the context required by http handlers.
func NewAPICtrl ¶
NewAPICtrl returns a new API controller
func (*APICtrl) CreateLicense ¶
func (a *APICtrl) CreateLicense(w http.ResponseWriter, r *http.Request)
CreateLicense adds a new license to the database.
func (*APICtrl) CreatePublication ¶
func (a *APICtrl) CreatePublication(w http.ResponseWriter, r *http.Request)
CreatePublication adds a new Publication to the database.
func (*APICtrl) DeleteLicense ¶
func (a *APICtrl) DeleteLicense(w http.ResponseWriter, r *http.Request)
DeleteLicense removes an existing license from the database.
func (*APICtrl) DeletePublication ¶
func (a *APICtrl) DeletePublication(w http.ResponseWriter, r *http.Request)
DeletePublication removes an existing Publication from the database.
func (*APICtrl) FreshLicense ¶
func (a *APICtrl) FreshLicense(w http.ResponseWriter, r *http.Request)
FreshLicense returns a fresh license
func (*APICtrl) GenerateLicense ¶
func (a *APICtrl) GenerateLicense(w http.ResponseWriter, r *http.Request)
GenerateLicense creates a license in the db and returns a fresh license
func (*APICtrl) GetDashboardData ¶
func (a *APICtrl) GetDashboardData(w http.ResponseWriter, r *http.Request)
GetDashboardData provides a summary of key metrics and statistics about the system.
func (*APICtrl) GetLicense ¶
func (a *APICtrl) GetLicense(w http.ResponseWriter, r *http.Request)
GetLicense returns a specific license
func (*APICtrl) GetOversharedLicenses ¶
func (a *APICtrl) GetOversharedLicenses(w http.ResponseWriter, r *http.Request)
GetOversharedLicenses provides a list of licenses that have been shared across multiple devices.
func (*APICtrl) GetPublication ¶
func (a *APICtrl) GetPublication(w http.ResponseWriter, r *http.Request)
GetPublication returns a specific publication
func (*APICtrl) GetPublicationByAltID ¶
func (a *APICtrl) GetPublicationByAltID(w http.ResponseWriter, r *http.Request)
GetPublicationByAltID returns a specific publication by its alternative ID
func (*APICtrl) ListLicenseEvents ¶
func (a *APICtrl) ListLicenseEvents(w http.ResponseWriter, r *http.Request)
ListLicenseEvents returns all events for a specific license
func (*APICtrl) ListLicenses ¶
func (a *APICtrl) ListLicenses(w http.ResponseWriter, r *http.Request)
ListLicenses lists licenses present in the database.
func (*APICtrl) ListPublications ¶
func (a *APICtrl) ListPublications(w http.ResponseWriter, r *http.Request)
ListPublications lists publications present in the database.
func (*APICtrl) ListUserLicenses ¶
func (a *APICtrl) ListUserLicenses(w http.ResponseWriter, r *http.Request)
ListUserLicenses returns licenses for a specific user. This is a similar but more direct way to get licenses for a user, compared to the search by user in SearchLicenses. It returns the title of the publication as well, which is useful for display in a user interface.
func (*APICtrl) Register ¶
func (a *APICtrl) Register(w http.ResponseWriter, r *http.Request)
Register records a new device using the license and returns a status document.
func (*APICtrl) Renew ¶
func (a *APICtrl) Renew(w http.ResponseWriter, r *http.Request)
Renew extends the lifetime of a license and returns a status document.
func (*APICtrl) ReportGeneratedLicenses ¶
func (a *APICtrl) ReportGeneratedLicenses(w http.ResponseWriter, r *http.Request)
ReportGeneratedLicenses generates a CSV report of licenses for a specific month or date
func (*APICtrl) Return ¶
func (a *APICtrl) Return(w http.ResponseWriter, r *http.Request)
Return forces the expiration of a license and returns a status document.
func (*APICtrl) Revoke ¶
func (a *APICtrl) Revoke(w http.ResponseWriter, r *http.Request)
Revoke forces the expiration of a license and returns a status document.
func (*APICtrl) SearchLicenses ¶
func (a *APICtrl) SearchLicenses(w http.ResponseWriter, r *http.Request)
SearchLicenses searches licenses corresponding to a specific criteria.
func (*APICtrl) SearchPublications ¶
func (a *APICtrl) SearchPublications(w http.ResponseWriter, r *http.Request)
SearchPublications searches publications corresponding to a specific criteria.
func (*APICtrl) StatusDoc ¶
func (a *APICtrl) StatusDoc(w http.ResponseWriter, r *http.Request)
Status returns a status document for the input license.
func (*APICtrl) UpdateLicense ¶
func (a *APICtrl) UpdateLicense(w http.ResponseWriter, r *http.Request)
UpdateLicense updates an existing License in the database.
func (*APICtrl) UpdatePublication ¶
func (a *APICtrl) UpdatePublication(w http.ResponseWriter, r *http.Request)
UpdatePublication updates an existing Publication in the database.
type DashboardResponse ¶
type DashboardResponse struct {
*stor.DashboardData
}
DashboardResponse is the response payload for the dashboard.
func NewDashboardResponse ¶
func NewDashboardResponse(dashboard *stor.DashboardData) *DashboardResponse
NewDashboardResponse creates a rendered dashboard
func (*DashboardResponse) Render ¶
func (s *DashboardResponse) Render(w http.ResponseWriter, r *http.Request) error
Render processes responses before marshalling.
type ErrResponse ¶
type ErrResponse struct {
//not serialized
Err error `json:"-"` // low-level runtime error
HTTPStatusCode int `json:"-"` // http response status code
//mandatory
Type string `json:"type"`
Title string `json:"title"`
//optional
Detail string `json:"detail,omitempty"` // application-level error message
Instance string `json:"instance,omitempty"`
}
ErrResponse renderer type for handling all sorts of errors.
In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error
type EventResponse ¶
EventResponse is the response payload for events.
func NewEventResponse ¶
func NewEventResponse(event *stor.Event) *EventResponse
NewEventResponse creates a rendered event
func (*EventResponse) Render ¶
func (e *EventResponse) Render(w http.ResponseWriter, r *http.Request) error
Render processes event responses before marshalling.
type LicenseInfoRequest ¶
type LicenseInfoRequest struct {
*stor.LicenseInfo
}
LicenseInfoRequest is the request payload for licenses.
type LicenseInfoResponse ¶
type LicenseInfoResponse struct {
*stor.LicenseInfo
// do not serialize the following properties
//ID omit `json:"ID,omitempty"`
//CreatedAt omit `json:"CreatedAt,omitempty"`
//UpdatedAt omit `json:"UpdatedAt,omitempty"`
//DeletedAt omit `json:"DeletedAt,omitempty"`
Publication omit `json:"Publication,omitempty"`
PublicationTitle *string `json:"publication_title,omitempty"`
}
LicenseInfoResponse is the response payload for licenses.
func NewLicenseInfoResponse ¶
func NewLicenseInfoResponse(license *stor.LicenseInfo) *LicenseInfoResponse
NewLicenseInfoResponse creates a rendered license
func (*LicenseInfoResponse) Render ¶
func (l *LicenseInfoResponse) Render(w http.ResponseWriter, r *http.Request) error
Render processes responses before marshalling.
type LicenseRequest ¶
type LicenseRequest struct {
PublicationID string `json:"publication_id" validate:"omitempty,uuid"`
AltID string `json:"alt_id,omitempty"`
UserID string `json:"user_id,omitempty" validate:"required"`
UserName string `json:"user_name,omitempty"`
UserEmail string `json:"user_email,omitempty"`
UserEncrypted []string `json:"user_encrypted,omitempty"`
Start *time.Time `json:"start,omitempty"`
End *time.Time `json:"end,omitempty"`
Copy *int32 `json:"copy,omitempty"`
Print *int32 `json:"print,omitempty"`
Profile string `json:"profile,omitempty"`
TextHint string `json:"text_hint" validate:"required"`
PassHash string `json:"pass_hash" validate:"required"`
}
LicenseRequest is the request payload for licenses. TODO: add an extension point for custom user properties, that have to be returned in the license, optionally encrypted.
type LicenseResponse ¶
LicenseResponse is the response payload for licenses.
func NewLicenseResponse ¶
func NewLicenseResponse(license *lic.License) *LicenseResponse
NewLicenseResponse creates a rendered license
func (*LicenseResponse) Render ¶
func (l *LicenseResponse) Render(w http.ResponseWriter, r *http.Request) error
Render processes responses before marshalling.
type OversharedLicensesResponse ¶
type OversharedLicensesResponse []stor.OversharedLicenseData
OversharedLicensesResponse is the response payload for the overshared licenses.
func NewOversharedLicensesResponse ¶
func NewOversharedLicensesResponse(licenses []stor.OversharedLicenseData) OversharedLicensesResponse
NewOversharedLicensesResponse creates a rendered overshared licenses response.
func (OversharedLicensesResponse) Render ¶
func (s OversharedLicensesResponse) Render(w http.ResponseWriter, r *http.Request) error
Render processes responses before marshalling.
type PaginationKey ¶
type PaginationKey string
PaginationKey is used to store pagination parameters in the context.
const ( PageKey PaginationKey = "page" PerPageKey PaginationKey = "per_page" )
type PublicationRequest ¶
type PublicationRequest struct {
*stor.Publication
}
PublicationRequest is the request publication payload.
type PublicationResponse ¶
type PublicationResponse struct {
*stor.Publication
}
PublicationResponse is the response publication payload.
func NewPublicationResponse ¶
func NewPublicationResponse(pub *stor.Publication) *PublicationResponse
NewPublicationResponse creates a rendered publication.
func (*PublicationResponse) Render ¶
func (pub *PublicationResponse) Render(w http.ResponseWriter, r *http.Request) error
Render processes responses before marshalling.
type StatusDocResponse ¶
StatusDocResponse is the response payload for licenses.
func NewStatusDocResponse ¶
func NewStatusDocResponse(statusDoc *lic.StatusDoc) *StatusDocResponse
NewStatusDocResponse creates a rendered status document
func (*StatusDocResponse) Render ¶
func (s *StatusDocResponse) Render(w http.ResponseWriter, r *http.Request) error
Render processes responses before marshalling.