api

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteNoteNoContent

type DeleteNoteNoContent struct{}

DeleteNoteNoContent is response for DeleteNote operation.

type DeleteNoteParams

type DeleteNoteParams struct {
	// Note ID.
	ID ID
}

DeleteNoteParams is parameters of deleteNote operation.

type DraftMultipart

type DraftMultipart struct {
	// Note title.
	Title string `json:"title"`
	// Note body.
	Text string `json:"text"`
	// Optional (and not verifiable) author of note.
	Author OptString `json:"author"`
	// Do not make list of attachments.
	HideAttachments OptBool `json:"hide_attachments"`
	// File attachment.
	Attachment []ht.MultipartFile `json:"attachment"`
}

Ref: #/components/schemas/draft

func (*DraftMultipart) GetAttachment

func (s *DraftMultipart) GetAttachment() []ht.MultipartFile

GetAttachment returns the value of Attachment.

func (*DraftMultipart) GetAuthor

func (s *DraftMultipart) GetAuthor() OptString

GetAuthor returns the value of Author.

func (*DraftMultipart) GetHideAttachments

func (s *DraftMultipart) GetHideAttachments() OptBool

GetHideAttachments returns the value of HideAttachments.

func (*DraftMultipart) GetText

func (s *DraftMultipart) GetText() string

GetText returns the value of Text.

func (*DraftMultipart) GetTitle

func (s *DraftMultipart) GetTitle() string

GetTitle returns the value of Title.

func (*DraftMultipart) SetAttachment

func (s *DraftMultipart) SetAttachment(val []ht.MultipartFile)

SetAttachment sets the value of Attachment.

func (*DraftMultipart) SetAuthor

func (s *DraftMultipart) SetAuthor(val OptString)

SetAuthor sets the value of Author.

func (*DraftMultipart) SetHideAttachments

func (s *DraftMultipart) SetHideAttachments(val OptBool)

SetHideAttachments sets the value of HideAttachments.

func (*DraftMultipart) SetText

func (s *DraftMultipart) SetText(val string)

SetText sets the value of Text.

func (*DraftMultipart) SetTitle

func (s *DraftMultipart) SetTitle(val string)

SetTitle sets the value of Title.

type ErrorHandler

type ErrorHandler = ogenerrors.ErrorHandler

ErrorHandler is error handler.

type Handler

type Handler interface {
	// CreateNote implements createNote operation.
	//
	// Create new note from draft with (optional) attachments.
	// Returns public URL and unique ID.
	// Consumer should not make any assumptions about ID and treat it as
	// arbitrary string with variable reasonable length.
	// Attachments with name index.html will be ignored.
	// Note can use relative reference to attachments as-is.
	//
	// POST /notes
	CreateNote(ctx context.Context, req *DraftMultipart) (*Note, error)
	// DeleteNote implements deleteNote operation.
	//
	// Remove existent note and all attachments.
	//
	// DELETE /note/{id}
	DeleteNote(ctx context.Context, params DeleteNoteParams) error
	// UpdateNote implements updateNote operation.
	//
	// Update existent note by ID.
	// Old attachments may not be removed, but could be replaced.
	//
	// PUT /note/{id}
	UpdateNote(ctx context.Context, req *DraftMultipart, params UpdateNoteParams) error
}

Handler handles operations described by OpenAPI v3 specification.

type HeaderAuth

type HeaderAuth struct {
	APIKey string
}

func (*HeaderAuth) GetAPIKey

func (s *HeaderAuth) GetAPIKey() string

GetAPIKey returns the value of APIKey.

func (*HeaderAuth) SetAPIKey

func (s *HeaderAuth) SetAPIKey(val string)

SetAPIKey sets the value of APIKey.

type ID

type ID string

func (*ID) Decode

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

Decode decodes ID from json.

func (ID) Encode

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

Encode encodes ID as json.

func (ID) MarshalJSON

func (s ID) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*ID) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (ID) Validate

func (s ID) Validate() error

type Middleware

type Middleware = middleware.Middleware

Middleware is middleware type.

type Note

type Note struct {
	ID ID `json:"id"`
	// Public URL.
	PublicURL string `json:"public_url"`
}

Ref: #/components/schemas/note

func (*Note) Decode

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

Decode decodes Note from json.

func (*Note) Encode

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

Encode implements json.Marshaler.

func (*Note) GetID

func (s *Note) GetID() ID

GetID returns the value of ID.

func (*Note) GetPublicURL

func (s *Note) GetPublicURL() string

GetPublicURL returns the value of PublicURL.

func (*Note) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Note) SetID

func (s *Note) SetID(val ID)

SetID sets the value of ID.

func (*Note) SetPublicURL

func (s *Note) SetPublicURL(val string)

SetPublicURL sets the value of PublicURL.

func (*Note) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*Note) Validate

func (s *Note) Validate() error

type OptBool

type OptBool struct {
	Value bool
	Set   bool
}

OptBool is optional bool.

func NewOptBool

func NewOptBool(v bool) OptBool

NewOptBool returns new OptBool with value set to v.

func (OptBool) Get

func (o OptBool) Get() (v bool, ok bool)

Get returns value and boolean that denotes whether value was set.

func (OptBool) IsSet

func (o OptBool) IsSet() bool

IsSet returns true if OptBool was set.

func (OptBool) Or

func (o OptBool) Or(d bool) bool

Or returns value if set, or given parameter if does not.

func (*OptBool) Reset

func (o *OptBool) Reset()

Reset unsets value.

func (*OptBool) SetTo

func (o *OptBool) SetTo(v bool)

SetTo sets value to v.

type OptString

type OptString struct {
	Value string
	Set   bool
}

OptString is optional string.

func NewOptString

func NewOptString(v string) OptString

NewOptString returns new OptString with value set to v.

func (OptString) Get

func (o OptString) Get() (v string, ok bool)

Get returns value and boolean that denotes whether value was set.

func (OptString) IsSet

func (o OptString) IsSet() bool

IsSet returns true if OptString was set.

func (OptString) Or

func (o OptString) Or(d string) string

Or returns value if set, or given parameter if does not.

func (*OptString) Reset

func (o *OptString) Reset()

Reset unsets value.

func (*OptString) SetTo

func (o *OptString) SetTo(v string)

SetTo sets value to v.

type Option

type Option interface {
	ServerOption
}

Option is config option.

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) Option

WithMeterProvider specifies a meter provider to use for creating a meter.

If none is specified, the otel.GetMeterProvider() is used.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) Option

WithTracerProvider specifies a tracer provider to use for creating a tracer.

If none is specified, the global provider is used.

type QueryAuth

type QueryAuth struct {
	APIKey string
}

func (*QueryAuth) GetAPIKey

func (s *QueryAuth) GetAPIKey() string

GetAPIKey returns the value of APIKey.

func (*QueryAuth) SetAPIKey

func (s *QueryAuth) SetAPIKey(val string)

SetAPIKey sets the value of APIKey.

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) OperationID

func (r Route) OperationID() string

OperationID returns OpenAPI operationId.

func (Route) PathPattern

func (r Route) PathPattern() string

PathPattern returns OpenAPI path.

type SecurityHandler

type SecurityHandler interface {
	// HandleHeaderAuth handles HeaderAuth security.
	HandleHeaderAuth(ctx context.Context, operationName string, t HeaderAuth) (context.Context, error)
	// HandleQueryAuth handles QueryAuth security.
	HandleQueryAuth(ctx context.Context, operationName string, t QueryAuth) (context.Context, error)
}

SecurityHandler is handler for security parameters.

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, sec SecurityHandler, 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 UnimplementedHandler

type UnimplementedHandler struct{}

UnimplementedHandler is no-op Handler which returns http.ErrNotImplemented.

func (UnimplementedHandler) CreateNote

func (UnimplementedHandler) CreateNote(ctx context.Context, req *DraftMultipart) (r *Note, _ error)

CreateNote implements createNote operation.

Create new note from draft with (optional) attachments. Returns public URL and unique ID. Consumer should not make any assumptions about ID and treat it as arbitrary string with variable reasonable length. Attachments with name index.html will be ignored. Note can use relative reference to attachments as-is.

POST /notes

func (UnimplementedHandler) DeleteNote

func (UnimplementedHandler) DeleteNote(ctx context.Context, params DeleteNoteParams) error

DeleteNote implements deleteNote operation.

Remove existent note and all attachments.

DELETE /note/{id}

func (UnimplementedHandler) UpdateNote

UpdateNote implements updateNote operation.

Update existent note by ID. Old attachments may not be removed, but could be replaced.

PUT /note/{id}

type UpdateNoteNoContent

type UpdateNoteNoContent struct{}

UpdateNoteNoContent is response for UpdateNote operation.

type UpdateNoteParams

type UpdateNoteParams struct {
	// Note ID.
	ID ID
}

UpdateNoteParams is parameters of updateNote operation.

Jump to

Keyboard shortcuts

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