client

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientNotFound   = errors.New("user_not_found")
	ErrInvalidRequest   = errors.New("invalid_request")
	ErrInvalidParameter = errors.New("invalid_parameter")
	ErrForbidden        = errors.New("forbidden")
)

Predefined errors.

Error codes map

View Source
var ErrorMessages = map[error]string{
	ErrClientNotFound:   "Client not found",
	ErrInvalidRequest:   "Invalid request",
	ErrInvalidParameter: "Invalid parameter",
	ErrForbidden:        "Forbidden action",
}

Error messages

Functions

func MakeCreateEndpoint

func MakeCreateEndpoint(s Service) endpoint.Endpoint

MakeCreateEndpoint returns an endpoint via the passed service.

func MakeDeleteEndpoint

func MakeDeleteEndpoint(s Service) endpoint.Endpoint

MakeDeleteEndpoint returns an endpoint via the passed service.

func MakeGetByIDEndpoint

func MakeGetByIDEndpoint(s Service) endpoint.Endpoint

MakeGetByIDEndpoint returns an endpoint via the passed service.

func MakeGetByUserIDEndpoint

func MakeGetByUserIDEndpoint(s Service) endpoint.Endpoint

MakeGetByUserIDEndpoint returns an endpoint via the passed service.

func MakeHTTPHandler

func MakeHTTPHandler(e Endpoints, log logger) http.Handler

MakeHTTPHandler ...

func NewError

func NewError(err error) *httpencoder.ErrorResponse

NewError creates a new error

Types

type Client

type Client struct {
	ID        string `json:"id"`
	Secret    string `json:"secret,omitempty"`
	Domain    string `json:"domain"`
	Public    bool   `json:"is_public"`
	UserID    string `json:"user_id"`
	CreatedAt string `json:"created_at"`
}

Client represents an OAuth client.

func NewClient

func NewClient(source repository.Client, secret string) *Client

NewClient creates a new client instance. The secret is hashed before being stored in the database. So it can be returned only once after creation.

type ClientResponse

type ClientResponse struct {
	Client  *Client   `json:"client,omitempty"`
	Clients []*Client `json:"clients,omitempty"`
}

type CreateRequest

type CreateRequest struct {
	Domain string `json:"domain" validate:"required|fullUrl" filter:"trim|lower|escapeJs|escapeHtml" label:"Domain"`
	Public bool   `json:"is_public" validate:"bool" label:"Is Public"`
}

CreateRequest is a request for the Create method.

type Endpoints

type Endpoints struct {
	Create      endpoint.Endpoint
	GetByID     endpoint.Endpoint
	GetByUserID endpoint.Endpoint
	Delete      endpoint.Endpoint
}

Endpoints collects all of the endpoints that compose a client service. It's meant to be used as a helper struct, to collect all of the endpoints into a single parameter.

func MakeEndpoints

func MakeEndpoints(s Service, m ...endpoint.Middleware) Endpoints

MakeEndpoints returns an Endpoints struct where each endpoint invokes the corresponding method on the provided service. Primarily useful in a server.

type Service

type Service interface {
	// Create creates a new client.
	Create(ctx context.Context, uid string, domain string, isPublic bool) (*Client, error)
	// GetByID returns a client by its ID.
	GetByID(ctx context.Context, id string) (*Client, error)
	// GetByUserID returns a clients list by its user ID.
	GetByUserID(ctx context.Context, uid string) ([]*Client, error)
	// Delete deletes a client by its ID.
	Delete(ctx context.Context, id string) error
}

Service is the client service interface.

func NewService

func NewService(repo clientRepository) Service

NewService returns a new instance of a service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL