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 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) GetLicense(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) GetPublication(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) Register(w http.ResponseWriter, r *http.Request)
- func (a *APICtrl) Renew(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 ErrResponse
- type LicenseInfoRequest
- type LicenseInfoResponse
- type LicenseRequest
- type LicenseResponse
- 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 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 ¶
type APICtrl struct { *conf.Config // TODO: change for an interface (dependency) stor.Store Cert *tls.Certificate }
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) GetLicense ¶
func (a *APICtrl) GetLicense(w http.ResponseWriter, r *http.Request)
GetLicense returns a specific license
func (*APICtrl) GetPublication ¶
func (a *APICtrl) GetPublication(w http.ResponseWriter, r *http.Request)
GetPublication returns a specific publication
func (*APICtrl) ListLicenses ¶
func (a *APICtrl) ListLicenses(w http.ResponseWriter, r *http.Request)
ListLicenses lists all licenses present in the database.
func (*APICtrl) ListPublications ¶
func (a *APICtrl) ListPublications(w http.ResponseWriter, r *http.Request)
ListPublications lists all publications present in the database.
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) 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 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 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"` }
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:"required,uuid"` 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 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 ¶
LicenseResponse is the response payload for licenses.
func NewStatusDocResponse ¶
func NewStatusDocResponse(statusDoc *lic.StatusDoc) *StatusDocResponse
NewLicenseResponse creates a rendered license
func (*StatusDocResponse) Render ¶
func (s *StatusDocResponse) Render(w http.ResponseWriter, r *http.Request) error
Render processes responses before marshalling.