Documentation
¶
Index ¶
- Variables
- func DecodeCreateClassRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeCreateClassResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeDeleteClassRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeDeleteClassResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeGetClassRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeGetClassResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeGetMemberRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeGetMemberResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeJoinClassRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeJoinClassResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeLeaveClassRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeLeaveClassResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeListClassesRequest(_ context.Context, _ *http.Request) (interface{}, error)
- func DecodeListClassesResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeListMembersRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeListMembersResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeSetRoleRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeSetRoleResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func DecodeUpdateClassRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeUpdateClassResponse(_ context.Context, resp *http.Response) (interface{}, error)
- func EncodeCreateClassRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeDeleteClassRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeGetClassRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeGetMemberRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeJoinClassRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeLeaveClassRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeListClassesRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeListMembersRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeSetRoleRequest(ctx context.Context, req *http.Request, request interface{}) error
- func EncodeUpdateClassRequest(ctx context.Context, req *http.Request, request interface{}) error
- func MakeCreateClassEndpoint(s Service) endpoint.Endpoint
- func MakeDeleteClassEndpoint(s Service) endpoint.Endpoint
- func MakeGetClassEndpoint(s Service) endpoint.Endpoint
- func MakeGetMemberEndpoint(s Service) endpoint.Endpoint
- func MakeHTTPHandler(s Service, introspection oauth2.Introspector, logger log.Logger) http.Handler
- func MakeJoinClassEndpoint(s Service) endpoint.Endpoint
- func MakeLeaveClassEndpoint(s Service) endpoint.Endpoint
- func MakeListClassesEndpoint(s Service) endpoint.Endpoint
- func MakeListMembersEndpoint(s Service) endpoint.Endpoint
- func MakeSetRoleEndpoint(s Service) endpoint.Endpoint
- func MakeUpdateClassEndpoint(s Service) endpoint.Endpoint
- type Endpoints
- func (e Endpoints) CreateClass(ctx context.Context, name string) (*uuid.UUID, error)
- func (e Endpoints) DeleteClass(ctx context.Context, classID uuid.UUID) error
- func (e Endpoints) GetClass(ctx context.Context, classID uuid.UUID) (*models.Class, error)
- func (e Endpoints) GetMember(ctx context.Context, classID, userID uuid.UUID) (*models.Member, error)
- func (e Endpoints) JoinClass(ctx context.Context, classID uuid.UUID) error
- func (e Endpoints) LeaveClass(ctx context.Context, userID *uuid.UUID, classID uuid.UUID) error
- func (e Endpoints) ListClasses(ctx context.Context) ([]uuid.UUID, error)
- func (e Endpoints) ListMembers(ctx context.Context, classID uuid.UUID) ([]*models.Member, error)
- func (e Endpoints) SetRole(ctx context.Context, classID, userID uuid.UUID, role models.UserRole) error
- func (e Endpoints) UpdateClass(ctx context.Context, classID uuid.UUID, name *string, currentUnit *uuid.UUID) error
- type Middleware
- type Service
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("resource not found or user is not allowed to access it") ErrForbidden = errors.New("user is not allowed to perform action") ErrMustSetOwner = errors.New("cannot demote self from owner unless new owner is set") ErrUserEnrolled = errors.New("user is already enrolled in class") ErrInternal = errors.New("internal server error") )
var (
ErrBadRequest = errors.New("the request is malformed or invalid")
)
Functions ¶
func DecodeGetClassRequest ¶
func DecodeGetClassResponse ¶
func DecodeGetMemberRequest ¶ added in v0.1.0
func DecodeGetMemberResponse ¶ added in v0.1.0
func DecodeJoinClassRequest ¶
func DecodeJoinClassResponse ¶
func DecodeLeaveClassRequest ¶
func DecodeSetRoleRequest ¶
func DecodeSetRoleResponse ¶
func EncodeGetClassRequest ¶
func EncodeGetMemberRequest ¶ added in v0.1.0
func EncodeJoinClassRequest ¶
func EncodeLeaveClassRequest ¶
func EncodeSetRoleRequest ¶
func MakeCreateClassEndpoint ¶
func MakeDeleteClassEndpoint ¶
func MakeGetClassEndpoint ¶
func MakeGetMemberEndpoint ¶ added in v0.1.0
func MakeHTTPHandler ¶
func MakeJoinClassEndpoint ¶
func MakeLeaveClassEndpoint ¶
func MakeListClassesEndpoint ¶
func MakeListMembersEndpoint ¶
func MakeSetRoleEndpoint ¶
func MakeUpdateClassEndpoint ¶
Types ¶
type Endpoints ¶
type Endpoints struct { ListClassesEndpoint endpoint.Endpoint GetClassEndpoint endpoint.Endpoint CreateClassEndpoint endpoint.Endpoint UpdateClassEndpoint endpoint.Endpoint DeleteClassEndpoint endpoint.Endpoint JoinClassEndpoint endpoint.Endpoint SetRoleEndpoint endpoint.Endpoint LeaveClassEndpoint endpoint.Endpoint ListMembersEndpoint endpoint.Endpoint GetMemberEndpoint endpoint.Endpoint }
Endpoints collects all of the endpoints that compose a class service. It's meant to be used as a helper struct, to collect all of the endpoints into a single parameter.
In a server, it's useful for functions that need to operate on a per-endpoint basis. For example, you might pass an Endpoints to a function that produces an http.Handler, with each method (endpoint) wired up to a specific path. (It is probably a mistake in design to invoke the Service methods on the Endpoints struct in a server.)
In a client, it's useful to collect individually constructed endpoints into a single type that implements the Service interface. For example, you might construct individual endpoints using transport/http.NewClient, combine them into an Endpoints, and return it to the caller as a Service.
func MakeClientEndpoints ¶
MakeClientEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the remote instance, via a transport/http.Client. Useful in a classsvc client.
func MakeServerEndpoints ¶
func (Endpoints) CreateClass ¶
func (Endpoints) DeleteClass ¶
func (Endpoints) LeaveClass ¶
func (Endpoints) ListClasses ¶
func (Endpoints) ListMembers ¶
type Middleware ¶ added in v0.1.0
type Service ¶
type Service interface { // ListClasses gets all classes the current user is enrolled in. ListClasses(ctx context.Context) ([]uuid.UUID, error) // GetClass gets details for a specific class. GetClass(ctx context.Context, classID uuid.UUID) (*models.Class, error) // CreateClass creates a class and enrolls the current user in it as an administrator. CreateClass(ctx context.Context, name string) (*uuid.UUID, error) // UpdateClass updates a class. UpdateClass(ctx context.Context, classID uuid.UUID, name *string, currentUnit *uuid.UUID) error // DeleteClass deactivates a class. DeleteClass(ctx context.Context, classID uuid.UUID) error // JoinClass enrolls the current user in a class. JoinClass(ctx context.Context, classID uuid.UUID) error // LeaveClass causes a user to be un-enrolled from a class. // If user is not nil, then LeaveClass removes the other user, requiring the current user to have elevated permissions. LeaveClass(ctx context.Context, userID *uuid.UUID, classID uuid.UUID) error // SetRole sets the role of a user in a class. // The current user must have a higher role than the target user. SetRole(ctx context.Context, classID uuid.UUID, userID uuid.UUID, role models.UserRole) error // ListMembers lists all members of a class and their role. ListMembers(ctx context.Context, classID uuid.UUID) ([]*models.Member, error) // GetMember gets a member of a class. GetMember(ctx context.Context, classID, userID uuid.UUID) (member *models.Member, err error) }
Service represents a Studiously class service.