api

package
v0.0.0-...-9410915 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package api provides primitives to interact with the openapi HTTP API.

Code generated by github.com/discord-gophers/goapi-gen version (devel) DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSwagger

func GetSwagger() (swagger *openapi3.T, err error)

GetSwagger returns the Swagger specification corresponding to the generated code in this file. The external references of Swagger specification are resolved. The logic of resolving external references is tightly connected to "import-mapping" feature. Externally referenced files must be embedded in the corresponding golang packages. Urls can be supported but this task was out of the scope.

func Handler

func Handler(si ServerInterface, opts ...ServerOption) http.Handler

Handler creates http.Handler with routing matching OpenAPI spec.

func PathToRawSpec

func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error)

Constructs a synthetic filesystem for resolving external references when loading openapi specifications.

Types

type InvalidParamFormatError

type InvalidParamFormatError struct {
	// contains filtered or unexported fields
}

func (InvalidParamFormatError) Error

func (err InvalidParamFormatError) Error() string

Error implements error.

func (InvalidParamFormatError) ParamName

func (err InvalidParamFormatError) ParamName() string

func (InvalidParamFormatError) Unwrap

func (err InvalidParamFormatError) Unwrap() error

type Login

type Login struct {
	// The user's email address
	Email openapi_types.Email `json:"email"`

	// The user's password
	Password string `json:"password"`
}

Login defines model for Login.

type ParameterError

type ParameterError interface {
	error
	// ParamName is the name of the parameter that the error is referring to.
	ParamName() string
}

ParameterName is an interface that is implemented by error types that are relevant to a specific parameter.

type Post

type Post struct {
	// The content of the blog post in markdown format
	Content string `json:"content"`

	// The date and time the blog post was created
	CreatedAt time.Time `json:"createdAt"`

	// The unique identifier of the blog post
	ID uuid.UUID `json:"id"`

	// The title of the blog post
	Title string `json:"title"`

	// The date and time the blog post was last updated
	UpdatedAt time.Time `json:"updatedAt"`
}

Post defines model for Post.

type PostAuthLoginJSONBody

type PostAuthLoginJSONBody Login

PostAuthLoginJSONBody defines parameters for PostAuthLogin.

type PostAuthLoginJSONRequestBody

type PostAuthLoginJSONRequestBody PostAuthLoginJSONBody

PostAuthLoginJSONRequestBody defines body for PostAuthLogin for application/json ContentType.

func (PostAuthLoginJSONRequestBody) Bind

Bind implements render.Binder.

type PostAuthSignupJSONBody

type PostAuthSignupJSONBody Signup

PostAuthSignupJSONBody defines parameters for PostAuthSignup.

type PostAuthSignupJSONRequestBody

type PostAuthSignupJSONRequestBody PostAuthSignupJSONBody

PostAuthSignupJSONRequestBody defines body for PostAuthSignup for application/json ContentType.

func (PostAuthSignupJSONRequestBody) Bind

Bind implements render.Binder.

type PostPostsJSONBody

type PostPostsJSONBody Post

PostPostsJSONBody defines parameters for PostPosts.

type PostPostsJSONRequestBody

type PostPostsJSONRequestBody PostPostsJSONBody

PostPostsJSONRequestBody defines body for PostPosts for application/json ContentType.

func (PostPostsJSONRequestBody) Bind

Bind implements render.Binder.

type PutPostsPostIDJSONBody

type PutPostsPostIDJSONBody Post

PutPostsPostIDJSONBody defines parameters for PutPostsPostID.

type PutPostsPostIDJSONRequestBody

type PutPostsPostIDJSONRequestBody PutPostsPostIDJSONBody

PutPostsPostIDJSONRequestBody defines body for PutPostsPostID for application/json ContentType.

func (PutPostsPostIDJSONRequestBody) Bind

Bind implements render.Binder.

type RequiredHeaderError

type RequiredHeaderError struct {
	// contains filtered or unexported fields
}

func (RequiredHeaderError) Error

func (err RequiredHeaderError) Error() string

Error implements error.

func (RequiredHeaderError) ParamName

func (err RequiredHeaderError) ParamName() string

type RequiredParamError

type RequiredParamError struct {
	// contains filtered or unexported fields
}

func (RequiredParamError) Error

func (err RequiredParamError) Error() string

Error implements error.

func (RequiredParamError) ParamName

func (err RequiredParamError) ParamName() string

func (RequiredParamError) Unwrap

func (err RequiredParamError) Unwrap() error

type Response

type Response struct {
	Code int
	// contains filtered or unexported fields
}

Response is a common response struct for all the API calls. A Response object may be instantiated via functions for specific operation responses. It may also be instantiated directly, for the purpose of responding with a single status code.

func GetPostsJSON200Response

func GetPostsJSON200Response(body []Post) *Response

GetPostsJSON200Response is a constructor method for a GetPosts response. A *Response is returned with the configured status code and content type from the spec.

func GetPostsPostIDJSON200Response

func GetPostsPostIDJSON200Response(body Post) *Response

GetPostsPostIDJSON200Response is a constructor method for a GetPostsPostID response. A *Response is returned with the configured status code and content type from the spec.

func PostAuthLoginJSON200Response

func PostAuthLoginJSON200Response(body User) *Response

PostAuthLoginJSON200Response is a constructor method for a PostAuthLogin response. A *Response is returned with the configured status code and content type from the spec.

func PostAuthSignupJSON201Response

func PostAuthSignupJSON201Response(body User) *Response

PostAuthSignupJSON201Response is a constructor method for a PostAuthSignup response. A *Response is returned with the configured status code and content type from the spec.

func PostPostsJSON201Response

func PostPostsJSON201Response(body Post) *Response

PostPostsJSON201Response is a constructor method for a PostPosts response. A *Response is returned with the configured status code and content type from the spec.

func PutPostsPostIDJSON200Response

func PutPostsPostIDJSON200Response(body Post) *Response

PutPostsPostIDJSON200Response is a constructor method for a PutPostsPostID response. A *Response is returned with the configured status code and content type from the spec.

func (*Response) ContentType

func (resp *Response) ContentType(contentType string) *Response

ContentType is a builder method to override the default content type for a response.

func (*Response) MarshalJSON

func (resp *Response) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. This is used to only marshal the body of the response.

func (*Response) MarshalXML

func (resp *Response) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface. This is used to only marshal the body of the response.

func (*Response) Render

func (resp *Response) Render(w http.ResponseWriter, r *http.Request) error

Render implements the render.Renderer interface. It sets the Content-Type header and status code based on the response definition.

func (*Response) Status

func (resp *Response) Status(code int) *Response

Status is a builder method to override the default status code for a response.

type Server

type Server struct {
	DB       db.Querier
	Log      zerolog.Logger
	Server   http.Server
	Sessions *scs.SessionManager
}

func (*Server) Authentication

func (s *Server) Authentication(next http.Handler) http.Handler

func (*Server) DeletePostsPostID

func (s *Server) DeletePostsPostID(w http.ResponseWriter, r *http.Request, postID uuid.UUID) *Response

func (*Server) GetPosts

func (s *Server) GetPosts(w http.ResponseWriter, r *http.Request) *Response

func (*Server) GetPostsPostID

func (s *Server) GetPostsPostID(w http.ResponseWriter, r *http.Request, postID uuid.UUID) *Response

func (*Server) PostAuthLogin

func (s *Server) PostAuthLogin(w http.ResponseWriter, r *http.Request) *Response

func (*Server) PostAuthLogout

func (s *Server) PostAuthLogout(w http.ResponseWriter, r *http.Request) *Response

func (*Server) PostAuthSignup

func (s *Server) PostAuthSignup(w http.ResponseWriter, r *http.Request) *Response

func (*Server) PostPosts

func (s *Server) PostPosts(w http.ResponseWriter, r *http.Request) *Response

func (*Server) PutPostsPostID

func (s *Server) PutPostsPostID(w http.ResponseWriter, r *http.Request, postID uuid.UUID) *Response

func (*Server) Start

func (s *Server) Start(c config.Server, wg *sync.WaitGroup) error

func (*Server) Stop

func (s *Server) Stop()

type ServerInterface

type ServerInterface interface {
	// Log in
	// (POST /auth/login)
	PostAuthLogin(w http.ResponseWriter, r *http.Request) *Response
	// Log out
	// (POST /auth/logout)
	PostAuthLogout(w http.ResponseWriter, r *http.Request) *Response
	// Sign up
	// (POST /auth/signup)
	PostAuthSignup(w http.ResponseWriter, r *http.Request) *Response
	// Get all blog posts
	// (GET /posts)
	GetPosts(w http.ResponseWriter, r *http.Request) *Response
	// Create a new blog post
	// (POST /posts)
	PostPosts(w http.ResponseWriter, r *http.Request) *Response
	// Delete a blog post
	// (DELETE /posts/{postId})
	DeletePostsPostID(w http.ResponseWriter, r *http.Request, postID uuid.UUID) *Response
	// Get a specific blog post
	// (GET /posts/{postId})
	GetPostsPostID(w http.ResponseWriter, r *http.Request, postID uuid.UUID) *Response
	// Update a blog post
	// (PUT /posts/{postId})
	PutPostsPostID(w http.ResponseWriter, r *http.Request, postID uuid.UUID) *Response
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler          ServerInterface
	Middlewares      map[string]func(http.Handler) http.Handler
	ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

ServerInterfaceWrapper converts contexts to parameters.

func (*ServerInterfaceWrapper) DeletePostsPostID

func (siw *ServerInterfaceWrapper) DeletePostsPostID(w http.ResponseWriter, r *http.Request)

DeletePostsPostID operation middleware

func (*ServerInterfaceWrapper) GetPosts

func (siw *ServerInterfaceWrapper) GetPosts(w http.ResponseWriter, r *http.Request)

GetPosts operation middleware

func (*ServerInterfaceWrapper) GetPostsPostID

func (siw *ServerInterfaceWrapper) GetPostsPostID(w http.ResponseWriter, r *http.Request)

GetPostsPostID operation middleware

func (*ServerInterfaceWrapper) PostAuthLogin

func (siw *ServerInterfaceWrapper) PostAuthLogin(w http.ResponseWriter, r *http.Request)

PostAuthLogin operation middleware

func (*ServerInterfaceWrapper) PostAuthLogout

func (siw *ServerInterfaceWrapper) PostAuthLogout(w http.ResponseWriter, r *http.Request)

PostAuthLogout operation middleware

func (*ServerInterfaceWrapper) PostAuthSignup

func (siw *ServerInterfaceWrapper) PostAuthSignup(w http.ResponseWriter, r *http.Request)

PostAuthSignup operation middleware

func (*ServerInterfaceWrapper) PostPosts

func (siw *ServerInterfaceWrapper) PostPosts(w http.ResponseWriter, r *http.Request)

PostPosts operation middleware

func (*ServerInterfaceWrapper) PutPostsPostID

func (siw *ServerInterfaceWrapper) PutPostsPostID(w http.ResponseWriter, r *http.Request)

PutPostsPostID operation middleware

type ServerOption

type ServerOption func(*ServerOptions)

func WithErrorHandler

func WithErrorHandler(handler func(w http.ResponseWriter, r *http.Request, err error)) ServerOption

func WithMiddleware

func WithMiddleware(key string, middleware func(http.Handler) http.Handler) ServerOption

func WithMiddlewares

func WithMiddlewares(middlewares map[string]func(http.Handler) http.Handler) ServerOption

func WithRouter

func WithRouter(r chi.Router) ServerOption

func WithServerBaseURL

func WithServerBaseURL(url string) ServerOption

type ServerOptions

type ServerOptions struct {
	BaseURL          string
	BaseRouter       chi.Router
	Middlewares      map[string]func(http.Handler) http.Handler
	ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

type Signup

type Signup struct {
	// The user's email address
	Email openapi_types.Email `json:"email"`

	// The user's password
	Password string `json:"password"`

	// The user's username
	Username string `json:"username"`
}

Signup defines model for Signup.

type TooManyValuesForParamError

type TooManyValuesForParamError struct {
	NumValues int
	// contains filtered or unexported fields
}

func (TooManyValuesForParamError) Error

func (err TooManyValuesForParamError) Error() string

Error implements error.

func (TooManyValuesForParamError) ParamName

func (err TooManyValuesForParamError) ParamName() string

type UnescapedCookieParamError

type UnescapedCookieParamError struct {
	// contains filtered or unexported fields
}

func (UnescapedCookieParamError) Error

func (err UnescapedCookieParamError) Error() string

Error implements error.

func (UnescapedCookieParamError) ParamName

func (err UnescapedCookieParamError) ParamName() string

func (UnescapedCookieParamError) Unwrap

func (err UnescapedCookieParamError) Unwrap() error

type UnmarshalingParamError

type UnmarshalingParamError struct {
	// contains filtered or unexported fields
}

func (UnmarshalingParamError) Error

func (err UnmarshalingParamError) Error() string

Error implements error.

func (UnmarshalingParamError) ParamName

func (err UnmarshalingParamError) ParamName() string

func (UnmarshalingParamError) Unwrap

func (err UnmarshalingParamError) Unwrap() error

type User

type User struct {
	// The user's email address
	Email openapi_types.Email `json:"email"`

	// The unique identifier of the user
	ID uuid.UUID `json:"id"`

	// The user's username
	Username string `json:"username"`
}

User defines model for User.

Jump to

Keyboard shortcuts

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