api

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const Prefix = "/api/v1"

Variables

This section is empty.

Functions

func WithServerURL

func WithServerURL(ctx context.Context, u *url.URL) context.Context

WithServerURL sets context key to override server URL.

Types

type Client

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

Client implements OAS client.

func NewClient

func NewClient(serverURL string, opts ...ClientOption) (*Client, error)

NewClient initializes new Client defined by OAS.

func (*Client) CreateToken

func (c *Client) CreateToken(ctx context.Context, request *Config) (*Credential, error)

CreateToken invokes createToken operation.

Create new token for user.

POST /tokens

func (*Client) DeleteToken

func (c *Client) DeleteToken(ctx context.Context, params DeleteTokenParams) error

DeleteToken invokes deleteToken operation.

Delete token for user.

DELETE /tokens/{token}

func (*Client) GetToken

func (c *Client) GetToken(ctx context.Context, params GetTokenParams) (*Token, error)

GetToken invokes getToken operation.

Get tokens by ID and for the current user.

GET /tokens/{token}

func (*Client) ListTokens

func (c *Client) ListTokens(ctx context.Context) ([]Token, error)

ListTokens invokes listTokens operation.

List all tokens for user.

GET /tokens

func (*Client) RefreshToken

func (c *Client) RefreshToken(ctx context.Context, params RefreshTokenParams) (*Credential, error)

RefreshToken invokes refreshToken operation.

Regenerate token key.

POST /tokens/{token}

func (*Client) UpdateToken

func (c *Client) UpdateToken(ctx context.Context, request *Config, params UpdateTokenParams) error

UpdateToken invokes updateToken operation.

Update token for user. Supports partial update.

PATCH /tokens/{token}

type ClientOption

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

ClientOption is client config option.

func WithClient

func WithClient(client ht.Client) ClientOption

WithClient specifies http client to use.

type Config

type Config struct {
	// Custom token description.
	Label OptString `json:"label"`
	// Allowed hosts. Supports globs. Empty means "allow all".
	Host OptString `json:"host"`
	// Allowed path. Supports globs. Empty means "allow all".
	Path OptString `json:"path"`
	// Custom headers which will be added after successfull authorization.
	Headers []NameValue `json:"headers"`
}

Ref: #/components/schemas/Config

func (*Config) Decode

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

Decode decodes Config from json.

func (*Config) Encode

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

Encode implements json.Marshaler.

func (*Config) GetHeaders

func (s *Config) GetHeaders() []NameValue

GetHeaders returns the value of Headers.

func (*Config) GetHost

func (s *Config) GetHost() OptString

GetHost returns the value of Host.

func (*Config) GetLabel

func (s *Config) GetLabel() OptString

GetLabel returns the value of Label.

func (*Config) GetPath

func (s *Config) GetPath() OptString

GetPath returns the value of Path.

func (*Config) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Config) SetHeaders

func (s *Config) SetHeaders(val []NameValue)

SetHeaders sets the value of Headers.

func (*Config) SetHost

func (s *Config) SetHost(val OptString)

SetHost sets the value of Host.

func (*Config) SetLabel

func (s *Config) SetLabel(val OptString)

SetLabel sets the value of Label.

func (*Config) SetPath

func (s *Config) SetPath(val OptString)

SetPath sets the value of Path.

func (*Config) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*Config) Validate

func (s *Config) Validate() error

type Credential

type Credential struct {
	// Token ID.
	ID int `json:"id"`
	// Raw token key.
	Key string `json:"key"`
}

Ref: #/components/schemas/Credential

func (*Credential) Decode

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

Decode decodes Credential from json.

func (*Credential) Encode

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

Encode implements json.Marshaler.

func (*Credential) GetID

func (s *Credential) GetID() int

GetID returns the value of ID.

func (*Credential) GetKey

func (s *Credential) GetKey() string

GetKey returns the value of Key.

func (*Credential) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Credential) SetID

func (s *Credential) SetID(val int)

SetID sets the value of ID.

func (*Credential) SetKey

func (s *Credential) SetKey(val string)

SetKey sets the value of Key.

func (*Credential) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type DeleteTokenNoContent

type DeleteTokenNoContent struct{}

DeleteTokenNoContent is response for DeleteToken operation.

type DeleteTokenParams

type DeleteTokenParams struct {
	// Token ID.
	Token int
}

DeleteTokenParams is parameters of deleteToken operation.

type ErrorHandler

type ErrorHandler = ogenerrors.ErrorHandler

ErrorHandler is error handler.

type GetTokenParams

type GetTokenParams struct {
	// Token ID.
	Token int
}

GetTokenParams is parameters of getToken operation.

type Handler

type Handler interface {
	// CreateToken implements createToken operation.
	//
	// Create new token for user.
	//
	// POST /tokens
	CreateToken(ctx context.Context, req *Config) (*Credential, error)
	// DeleteToken implements deleteToken operation.
	//
	// Delete token for user.
	//
	// DELETE /tokens/{token}
	DeleteToken(ctx context.Context, params DeleteTokenParams) error
	// GetToken implements getToken operation.
	//
	// Get tokens by ID and for the current user.
	//
	// GET /tokens/{token}
	GetToken(ctx context.Context, params GetTokenParams) (*Token, error)
	// ListTokens implements listTokens operation.
	//
	// List all tokens for user.
	//
	// GET /tokens
	ListTokens(ctx context.Context) ([]Token, error)
	// RefreshToken implements refreshToken operation.
	//
	// Regenerate token key.
	//
	// POST /tokens/{token}
	RefreshToken(ctx context.Context, params RefreshTokenParams) (*Credential, error)
	// UpdateToken implements updateToken operation.
	//
	// Update token for user. Supports partial update.
	//
	// PATCH /tokens/{token}
	UpdateToken(ctx context.Context, req *Config, params UpdateTokenParams) error
}

Handler handles operations described by OpenAPI v3 specification.

type Invoker

type Invoker interface {
	// CreateToken invokes createToken operation.
	//
	// Create new token for user.
	//
	// POST /tokens
	CreateToken(ctx context.Context, request *Config) (*Credential, error)
	// DeleteToken invokes deleteToken operation.
	//
	// Delete token for user.
	//
	// DELETE /tokens/{token}
	DeleteToken(ctx context.Context, params DeleteTokenParams) error
	// GetToken invokes getToken operation.
	//
	// Get tokens by ID and for the current user.
	//
	// GET /tokens/{token}
	GetToken(ctx context.Context, params GetTokenParams) (*Token, error)
	// ListTokens invokes listTokens operation.
	//
	// List all tokens for user.
	//
	// GET /tokens
	ListTokens(ctx context.Context) ([]Token, error)
	// RefreshToken invokes refreshToken operation.
	//
	// Regenerate token key.
	//
	// POST /tokens/{token}
	RefreshToken(ctx context.Context, params RefreshTokenParams) (*Credential, error)
	// UpdateToken invokes updateToken operation.
	//
	// Update token for user. Supports partial update.
	//
	// PATCH /tokens/{token}
	UpdateToken(ctx context.Context, request *Config, params UpdateTokenParams) error
}

Invoker invokes operations described by OpenAPI v3 specification.

type Middleware

type Middleware = middleware.Middleware

Middleware is middleware type.

type NameValue

type NameValue struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Ref: #/components/schemas/NameValue

func (*NameValue) Decode

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

Decode decodes NameValue from json.

func (*NameValue) Encode

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

Encode implements json.Marshaler.

func (*NameValue) GetName

func (s *NameValue) GetName() string

GetName returns the value of Name.

func (*NameValue) GetValue

func (s *NameValue) GetValue() string

GetValue returns the value of Value.

func (*NameValue) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*NameValue) SetName

func (s *NameValue) SetName(val string)

SetName sets the value of Name.

func (*NameValue) SetValue

func (s *NameValue) SetValue(val string)

SetValue sets the value of Value.

func (*NameValue) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*NameValue) Validate

func (s *NameValue) Validate() error

type OptDateTime

type OptDateTime struct {
	Value time.Time
	Set   bool
}

OptDateTime is optional time.Time.

func NewOptDateTime

func NewOptDateTime(v time.Time) OptDateTime

NewOptDateTime returns new OptDateTime with value set to v.

func (*OptDateTime) Decode

func (o *OptDateTime) Decode(d *jx.Decoder, format func(*jx.Decoder) (time.Time, error)) error

Decode decodes time.Time from json.

func (OptDateTime) Encode

func (o OptDateTime) Encode(e *jx.Encoder, format func(*jx.Encoder, time.Time))

Encode encodes time.Time as json.

func (OptDateTime) Get

func (o OptDateTime) Get() (v time.Time, ok bool)

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

func (OptDateTime) IsSet

func (o OptDateTime) IsSet() bool

IsSet returns true if OptDateTime was set.

func (OptDateTime) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (OptDateTime) Or

func (o OptDateTime) Or(d time.Time) time.Time

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

func (*OptDateTime) Reset

func (o *OptDateTime) Reset()

Reset unsets value.

func (*OptDateTime) SetTo

func (o *OptDateTime) SetTo(v time.Time)

SetTo sets value to v.

func (*OptDateTime) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

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

func (o *OptString) Decode(d *jx.Decoder) error

Decode decodes string from json.

func (OptString) Encode

func (o OptString) Encode(e *jx.Encoder)

Encode encodes string as json.

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

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

MarshalJSON implements stdjson.Marshaler.

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.

func (*OptString) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

type Option

type Option interface {
	ServerOption
	ClientOption
}

Option is config option.

type RefreshTokenParams

type RefreshTokenParams struct {
	// Token ID.
	Token int
}

RefreshTokenParams is parameters of refreshToken operation.

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.

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 Token

type Token struct {
	// Unique token ID.
	ID int `json:"id"`
	// Time when token was initially created.
	CreatedAt time.Time `json:"createdAt"`
	// Time when token was updated last time.
	UpdatedAt time.Time `json:"updatedAt"`
	// Tentative time when token was last time used.
	LastAccessAt OptDateTime `json:"lastAccessAt"`
	// Unique first several bytes for token which is used for fast identification.
	KeyID string `json:"keyID"`
	// User which created token.
	User string `json:"user"`
	// Custom token description.
	Label string `json:"label"`
	// Allowed hosts. Supports globs. Empty means "allow all".
	Host string `json:"host"`
	// Allowed path. Supports globs. Empty means "allow all".
	Path string `json:"path"`
	// Custom headers which will be added after successfull authorization.
	Headers []NameValue `json:"headers"`
	// Tentative number of requests used this token.
	Requests int64 `json:"requests"`
}

Ref: #/components/schemas/Token

func (*Token) Decode

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

Decode decodes Token from json.

func (*Token) Encode

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

Encode implements json.Marshaler.

func (*Token) GetCreatedAt

func (s *Token) GetCreatedAt() time.Time

GetCreatedAt returns the value of CreatedAt.

func (*Token) GetHeaders

func (s *Token) GetHeaders() []NameValue

GetHeaders returns the value of Headers.

func (*Token) GetHost

func (s *Token) GetHost() string

GetHost returns the value of Host.

func (*Token) GetID

func (s *Token) GetID() int

GetID returns the value of ID.

func (*Token) GetKeyID

func (s *Token) GetKeyID() string

GetKeyID returns the value of KeyID.

func (*Token) GetLabel

func (s *Token) GetLabel() string

GetLabel returns the value of Label.

func (*Token) GetLastAccessAt

func (s *Token) GetLastAccessAt() OptDateTime

GetLastAccessAt returns the value of LastAccessAt.

func (*Token) GetPath

func (s *Token) GetPath() string

GetPath returns the value of Path.

func (*Token) GetRequests

func (s *Token) GetRequests() int64

GetRequests returns the value of Requests.

func (*Token) GetUpdatedAt

func (s *Token) GetUpdatedAt() time.Time

GetUpdatedAt returns the value of UpdatedAt.

func (*Token) GetUser

func (s *Token) GetUser() string

GetUser returns the value of User.

func (*Token) MarshalJSON

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

MarshalJSON implements stdjson.Marshaler.

func (*Token) SetCreatedAt

func (s *Token) SetCreatedAt(val time.Time)

SetCreatedAt sets the value of CreatedAt.

func (*Token) SetHeaders

func (s *Token) SetHeaders(val []NameValue)

SetHeaders sets the value of Headers.

func (*Token) SetHost

func (s *Token) SetHost(val string)

SetHost sets the value of Host.

func (*Token) SetID

func (s *Token) SetID(val int)

SetID sets the value of ID.

func (*Token) SetKeyID

func (s *Token) SetKeyID(val string)

SetKeyID sets the value of KeyID.

func (*Token) SetLabel

func (s *Token) SetLabel(val string)

SetLabel sets the value of Label.

func (*Token) SetLastAccessAt

func (s *Token) SetLastAccessAt(val OptDateTime)

SetLastAccessAt sets the value of LastAccessAt.

func (*Token) SetPath

func (s *Token) SetPath(val string)

SetPath sets the value of Path.

func (*Token) SetRequests

func (s *Token) SetRequests(val int64)

SetRequests sets the value of Requests.

func (*Token) SetUpdatedAt

func (s *Token) SetUpdatedAt(val time.Time)

SetUpdatedAt sets the value of UpdatedAt.

func (*Token) SetUser

func (s *Token) SetUser(val string)

SetUser sets the value of User.

func (*Token) UnmarshalJSON

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

UnmarshalJSON implements stdjson.Unmarshaler.

func (*Token) Validate

func (s *Token) Validate() error

type UpdateTokenNoContent

type UpdateTokenNoContent struct{}

UpdateTokenNoContent is response for UpdateToken operation.

type UpdateTokenParams

type UpdateTokenParams struct {
	// Token ID.
	Token int
}

UpdateTokenParams is parameters of updateToken operation.

Jump to

Keyboard shortcuts

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