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 = "unauthorized" ErrMsgUnauthorizedExpiredToken = "expired token" ErrMsgUnauthorizedInvalidToken = "unauthorized" 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 ¶
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.
Click to show internal directories.
Click to hide internal directories.