api

package
v0.0.0-...-50c13da Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateUser

type CreateUser struct {
	ID uuid.UUID `json:"id"`
}

Ref: #/components/responses/CreateUser

func (*CreateUser) Decode

func (s *CreateUser) Decode(d *jx.Decoder) error

Decode decodes CreateUser from json.

func (*CreateUser) Encode

func (s *CreateUser) Encode(e *jx.Encoder)

Encode implements json.Marshaler.

func (*CreateUser) GetID

func (s *CreateUser) GetID() uuid.UUID

GetID returns the value of ID.

func (*CreateUser) MarshalJSON

func (s *CreateUser) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*CreateUser) SetID

func (s *CreateUser) SetID(val uuid.UUID)

SetID sets the value of ID.

func (*CreateUser) UnmarshalJSON

func (s *CreateUser) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

type CreateUserReq

type CreateUserReq struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

func (*CreateUserReq) Decode

func (s *CreateUserReq) Decode(d *jx.Decoder) error

Decode decodes CreateUserReq from json.

func (*CreateUserReq) Encode

func (s *CreateUserReq) Encode(e *jx.Encoder)

Encode implements json.Marshaler.

func (*CreateUserReq) GetEmail

func (s *CreateUserReq) GetEmail() string

GetEmail returns the value of Email.

func (*CreateUserReq) GetName

func (s *CreateUserReq) GetName() string

GetName returns the value of Name.

func (*CreateUserReq) MarshalJSON

func (s *CreateUserReq) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*CreateUserReq) SetEmail

func (s *CreateUserReq) SetEmail(val string)

SetEmail sets the value of Email.

func (*CreateUserReq) SetName

func (s *CreateUserReq) SetName(val string)

SetName sets the value of Name.

func (*CreateUserReq) UnmarshalJSON

func (s *CreateUserReq) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

func (*CreateUserReq) Validate

func (s *CreateUserReq) Validate() error

type Error

type Error struct {
	Message string `json:"message"`
}

Ref: #/components/responses/Error

func (*Error) Decode

func (s *Error) Decode(d *jx.Decoder) error

Decode decodes Error from json.

func (*Error) Encode

func (s *Error) Encode(e *jx.Encoder)

Encode implements json.Marshaler.

func (*Error) GetMessage

func (s *Error) GetMessage() string

GetMessage returns the value of Message.

func (*Error) MarshalJSON

func (s *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*Error) SetMessage

func (s *Error) SetMessage(val string)

SetMessage sets the value of Message.

func (*Error) UnmarshalJSON

func (s *Error) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

type ErrorHandler

type ErrorHandler = ogenerrors.ErrorHandler

ErrorHandler is error handler.

type ErrorStatusCode

type ErrorStatusCode struct {
	StatusCode int
	Response   Error
}

ErrorStatusCode wraps Error with StatusCode.

func (*ErrorStatusCode) Error

func (s *ErrorStatusCode) Error() string

func (*ErrorStatusCode) GetResponse

func (s *ErrorStatusCode) GetResponse() Error

GetResponse returns the value of Response.

func (*ErrorStatusCode) GetStatusCode

func (s *ErrorStatusCode) GetStatusCode() int

GetStatusCode returns the value of StatusCode.

func (*ErrorStatusCode) SetResponse

func (s *ErrorStatusCode) SetResponse(val Error)

SetResponse sets the value of Response.

func (*ErrorStatusCode) SetStatusCode

func (s *ErrorStatusCode) SetStatusCode(val int)

SetStatusCode sets the value of StatusCode.

type GetUserParams

type GetUserParams struct {
	UserID uuid.UUID
}

GetUserParams is parameters of getUser operation.

type Handler

type Handler interface {
	// CreateUser implements createUser operation.
	//
	// Create a user.
	//
	// POST /api/v1/users
	CreateUser(ctx context.Context, req *CreateUserReq) (*CreateUser, error)
	// GetUser implements getUser operation.
	//
	// Get user by ID.
	//
	// GET /api/v1/users/{userID}
	GetUser(ctx context.Context, params GetUserParams) (*User, error)
	// GetUsers implements getUsers operation.
	//
	// Get all users.
	//
	// GET /api/v1/users
	GetUsers(ctx context.Context) ([]User, error)
	// Ping implements ping operation.
	//
	// Ping API.
	//
	// GET /api/v1/ping
	Ping(ctx context.Context) (PingOK, error)
	// NewError creates *ErrorStatusCode from error returned by handler.
	//
	// Used for common default response.
	NewError(ctx context.Context, err error) *ErrorStatusCode
}

Handler handles operations described by OpenAPI v3 specification.

type Middleware

type Middleware = middleware.Middleware

Middleware is middleware type.

type OperationName

type OperationName = string

OperationName is the ogen operation name

const (
	CreateUserOperation OperationName = "CreateUser"
	GetUserOperation    OperationName = "GetUser"
	GetUsersOperation   OperationName = "GetUsers"
	PingOperation       OperationName = "Ping"
)

type Option

type Option interface {
	ServerOption
}

Option is config option.

type PingOK

type PingOK struct {
	Data io.Reader
}

func (PingOK) Read

func (s PingOK) Read(p []byte) (n int, err error)

Read reads data from the Data reader.

Kept to satisfy the io.Reader interface.

type Route

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

Route is route object.

func (Route) Args

func (r Route) Args() []string

Args returns parsed arguments.

func (Route) Name

func (r Route) Name() string

Name returns ogen operation name.

It is guaranteed to be unique and not empty.

func (Route) OperationGroup

func (r Route) OperationGroup() string

OperationGroup returns the x-ogen-operation-group value.

func (Route) OperationID

func (r Route) OperationID() string

OperationID returns OpenAPI operationId.

func (Route) PathPattern

func (r Route) PathPattern() string

PathPattern returns OpenAPI path.

func (Route) Summary

func (r Route) Summary() string

Summary returns OpenAPI summary.

type Server

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

Server implements http server based on OpenAPI v3 specification and calls Handler to handle requests.

func NewServer

func NewServer(h Handler, opts ...ServerOption) (*Server, error)

NewServer creates new Server.

func (*Server) FindPath

func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool)

FindPath finds Route for given method and URL.

func (*Server) FindRoute

func (s *Server) FindRoute(method, path string) (Route, bool)

FindRoute finds Route for given method and path.

Note: this method does not unescape path or handle reserved characters in path properly. Use FindPath instead.

func (*Server) ServeHTTP

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

ServeHTTP serves http request as defined by OpenAPI v3 specification, calling handler that matches the path or returning not found error.

type ServerOption

type ServerOption interface {
	// contains filtered or unexported methods
}

ServerOption is server config option.

func WithErrorHandler

func WithErrorHandler(h ErrorHandler) ServerOption

WithErrorHandler specifies error handler to use.

func WithMaxMultipartMemory

func WithMaxMultipartMemory(max int64) ServerOption

WithMaxMultipartMemory specifies limit of memory for storing file parts. File parts which can't be stored in memory will be stored on disk in temporary files.

func WithMethodNotAllowed

func WithMethodNotAllowed(methodNotAllowed func(w http.ResponseWriter, r *http.Request, allowed string)) ServerOption

WithMethodNotAllowed specifies Method Not Allowed handler to use.

func WithMiddleware

func WithMiddleware(m ...Middleware) ServerOption

WithMiddleware specifies middlewares to use.

func WithNotFound

func WithNotFound(notFound http.HandlerFunc) ServerOption

WithNotFound specifies Not Found handler to use.

func WithPathPrefix

func WithPathPrefix(prefix string) ServerOption

WithPathPrefix specifies server path prefix.

type User

type User struct {
	ID      uuid.UUID `json:"id"`
	Name    string    `json:"name"`
	Email   string    `json:"email"`
	IconUrl string    `json:"iconUrl"`
}

Ref: #/components/schemas/User

func (*User) Decode

func (s *User) Decode(d *jx.Decoder) error

Decode decodes User from json.

func (*User) Encode

func (s *User) Encode(e *jx.Encoder)

Encode implements json.Marshaler.

func (*User) GetEmail

func (s *User) GetEmail() string

GetEmail returns the value of Email.

func (*User) GetID

func (s *User) GetID() uuid.UUID

GetID returns the value of ID.

func (*User) GetIconUrl

func (s *User) GetIconUrl() string

GetIconUrl returns the value of IconUrl.

func (*User) GetName

func (s *User) GetName() string

GetName returns the value of Name.

func (*User) MarshalJSON

func (s *User) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*User) SetEmail

func (s *User) SetEmail(val string)

SetEmail sets the value of Email.

func (*User) SetID

func (s *User) SetID(val uuid.UUID)

SetID sets the value of ID.

func (*User) SetIconUrl

func (s *User) SetIconUrl(val string)

SetIconUrl sets the value of IconUrl.

func (*User) SetName

func (s *User) SetName(val string)

SetName sets the value of Name.

func (*User) UnmarshalJSON

func (s *User) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

Jump to

Keyboard shortcuts

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