api

package
v0.0.0-...-e4064bc Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultAddress is the default server address.
	DefaultAddress = "127.0.0.1:8080"
	// DefaultWriteTimeout is the default write timeout for server responses.
	DefaultWriteTimeout = 15 * time.Second
	// DefaultReadTimeout is the default read timeout for incoming requests.
	DefaultReadTimeout = 15 * time.Second

	// ErrMsgBadRequestInvalidRequestBody is a message for bad request with invalid request body.
	ErrMsgBadRequestInvalidRequestBody = "invalid request body"
	// ErrMsgBadRequestUserAlreadyExists is a message for bad request with user already exists.
	ErrMsgBadRequestUserAlreadyExists = "user already exists"
	// ErrMsgBadRequestInvalidBookID is a message for bad request with invalid book id.
	ErrMsgBadRequestInvalidBookID = "invalid book id"
	// ErrMsgUnauthorized is a message for unauthorized.
	ErrMsgUnauthorized = "unauthorized"
	// ErrMsgUnauthorizedExpiredToken is a message for unauthorized with expired token.
	ErrMsgUnauthorizedExpiredToken = "expired token"
	// ErrMsgUnauthorizedInvalidToken is a message for unauthorized with invalid token.
	ErrMsgUnauthorizedInvalidToken = "unauthorized"
	// ErrMsgUnauthorizedInvalidCredentials is a message for unauthorized with invalid credentials.
	ErrMsgUnauthorizedInvalidCredentials = "invalid credentials"
	// ErrMsgNotFound is a message for not found.
	ErrMsgNotFound = "not found"
	// ErrMsgInternalError is a message for internal error.
	ErrMsgInternalError = "internal server error"
)

Variables

View Source
var (
	// ErrUserIDNotSetInContext is returned when the user id is not set in the context.
	ErrUserIDNotSetInContext = errors.New("user id not set in context")
)

Functions

This section is empty.

Types

type Server

type Server struct {
	*http.Server
	// contains filtered or unexported fields
}

Server is a HTTP server for handling REST API requests.

func NewServer

func NewServer(userService services.UserService, bookService services.BookService, tokenService services.TokenService, opts ...ServerOption) *Server

NewServer creates a new Server instance.

type ServerOption

type ServerOption func(*Server)

ServerOption is a function signature for providing options to configure the Server.

func WithAddress

func WithAddress(addr string) ServerOption

WithAddress is an option to set the server address.

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) ServerOption

WithReadTimeout is an option to set the read timeout for the server.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) ServerOption

WithWriteTimeout is an option to set the write timeout for the server.

Jump to

Keyboard shortcuts

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