httpapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

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

Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT.

Index

Constants

View Source
const (
	PermCanSearch = "can_search"
	PermCanUpload = "can_upload"
	PermCanUpdate = "can_update"
	PermCanDelete = "can_delete"
)
View Source
const (
	BearerAuthScopes = "bearerAuth.Scopes"
)

Variables

This section is empty.

Functions

func Handler

func Handler(si ServerInterface) http.Handler

Handler creates http.Handler with routing matching OpenAPI spec.

func HandlerFromMux

func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler

HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.

func HandlerFromMuxWithBaseURL

func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler

func HandlerWithOptions

func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler

HandlerWithOptions creates http.Handler with additional options

func NewRouter

func NewRouter(cfg *config.Config, st *store.Store, mediaMgr *media.Manager, apiKeys *APIKeyStore, logger *slog.Logger) http.Handler

func WithPrincipal

func WithPrincipal(ctx context.Context, p *Principal) context.Context

Types

type APIKey

type APIKey struct {
	ID          string   `yaml:"id"`
	Key         string   `yaml:"key"`
	Permissions []string `yaml:"permissions"`
}

type APIKeyStore

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

func LoadAPIKeys

func LoadAPIKeys(path string) (*APIKeyStore, error)

func (*APIKeyStore) Lookup

func (s *APIKeyStore) Lookup(key string) (*APIKey, bool)

type Asset

type Asset struct {
	Bytes            int64      `json:"bytes"`
	Caption          string     `json:"caption"`
	CreatedAt        time.Time  `json:"createdAt"`
	Credit           string     `json:"credit"`
	DeletedAt        *time.Time `json:"deletedAt"`
	Height           int        `json:"height"`
	Id               int64      `json:"id"`
	Mime             string     `json:"mime"`
	OriginalFilename *string    `json:"originalFilename,omitempty"`

	// Sha256 Hex-encoded SHA-256 of the original bytes (optional to expose).
	Sha256     *string          `json:"sha256,omitempty"`
	Source     string           `json:"source"`
	Tags       []string         `json:"tags"`
	Title      string           `json:"title"`
	UpdatedAt  time.Time        `json:"updatedAt"`
	UsageNotes string           `json:"usageNotes"`
	Variants   AssetVariantUrls `json:"variants"`
	Width      int              `json:"width"`
}

Asset defines model for Asset.

type AssetId

type AssetId = int64

AssetId defines model for AssetId.

type AssetSearchResponse

type AssetSearchResponse struct {
	Items    []Asset `json:"items"`
	Page     int     `json:"page"`
	PageSize int     `json:"pageSize"`
	Total    int     `json:"total"`
}

AssetSearchResponse defines model for AssetSearchResponse.

type AssetUpdate

type AssetUpdate struct {
	Caption    *string   `json:"caption,omitempty"`
	Credit     *string   `json:"credit,omitempty"`
	Source     *string   `json:"source,omitempty"`
	Tags       *[]string `json:"tags,omitempty"`
	Title      *string   `json:"title,omitempty"`
	UsageNotes *string   `json:"usageNotes,omitempty"`
}

AssetUpdate defines model for AssetUpdate.

type AssetVariantUrls

type AssetVariantUrls struct {
	Content  string `json:"content"`
	Original string `json:"original"`
	Thumb    string `json:"thumb"`
}

AssetVariantUrls defines model for AssetVariantUrls.

type ChiServerOptions

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

type Error

type Error struct {
	Code    string                  `json:"code"`
	Details *map[string]interface{} `json:"details,omitempty"`
	Message string                  `json:"message"`
}

Error defines model for Error.

type GetMediaVariantParamsVariant

type GetMediaVariantParamsVariant string

GetMediaVariantParamsVariant defines parameters for GetMediaVariant.

const (
	GetMediaVariantParamsVariantContent  GetMediaVariantParamsVariant = "content"
	GetMediaVariantParamsVariantOriginal GetMediaVariantParamsVariant = "original"
	GetMediaVariantParamsVariantThumb    GetMediaVariantParamsVariant = "thumb"
)

Defines values for GetMediaVariantParamsVariant.

type Health

type Health struct {
	Status HealthStatus `json:"status"`
}

Health defines model for Health.

type HealthStatus

type HealthStatus string

HealthStatus defines model for Health.Status.

const (
	Ok HealthStatus = "ok"
)

Defines values for HealthStatus.

type IncludeDeleted

type IncludeDeleted = bool

IncludeDeleted defines model for IncludeDeleted.

type InvalidParamFormatError

type InvalidParamFormatError struct {
	ParamName string
	Err       error
}

func (*InvalidParamFormatError) Error

func (e *InvalidParamFormatError) Error() string

func (*InvalidParamFormatError) Unwrap

func (e *InvalidParamFormatError) Unwrap() error

type ListTagsParams

type ListTagsParams struct {
	// Prefix Prefix filter for tag autocomplete.
	Prefix   *string `form:"prefix,omitempty" json:"prefix,omitempty"`
	Page     *Page   `form:"page,omitempty" json:"page,omitempty"`
	PageSize *int    `form:"pageSize,omitempty" json:"pageSize,omitempty"`
}

ListTagsParams defines parameters for ListTags.

type MediaVariant

type MediaVariant string

MediaVariant defines model for MediaVariant.

const (
	MediaVariantContent  MediaVariant = "content"
	MediaVariantOriginal MediaVariant = "original"
	MediaVariantThumb    MediaVariant = "thumb"
)

Defines values for MediaVariant.

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

type Page

type Page = int

Page defines model for Page.

type PageSize

type PageSize = int

PageSize defines model for PageSize.

type Principal

type Principal struct {
	ID          string
	Permissions map[string]struct{}
	Source      string
}

func PrincipalFromContext

func PrincipalFromContext(ctx context.Context) (*Principal, bool)

func (*Principal) HasPermission

func (p *Principal) HasPermission(perm string) bool

type Query

type Query = string

Query defines model for Query.

type RequiredHeaderError

type RequiredHeaderError struct {
	ParamName string
	Err       error
}

func (*RequiredHeaderError) Error

func (e *RequiredHeaderError) Error() string

func (*RequiredHeaderError) Unwrap

func (e *RequiredHeaderError) Unwrap() error

type RequiredParamError

type RequiredParamError struct {
	ParamName string
}

func (*RequiredParamError) Error

func (e *RequiredParamError) Error() string

type SearchAssetsParams

type SearchAssetsParams struct {
	// Q Full-text query (searched across title, caption, and tags).
	Q *Query `form:"q,omitempty" json:"q,omitempty"`

	// Tag Filter by tag name. Repeatable to require multiple tags.
	Tag      *TagFilter `form:"tag,omitempty" json:"tag,omitempty"`
	Page     *Page      `form:"page,omitempty" json:"page,omitempty"`
	PageSize *PageSize  `form:"pageSize,omitempty" json:"pageSize,omitempty"`

	// Sort Sort order for search results.
	Sort *SearchAssetsParamsSort `form:"sort,omitempty" json:"sort,omitempty"`

	// IncludeDeleted Include soft-deleted assets in results (admin use).
	IncludeDeleted *IncludeDeleted `form:"includeDeleted,omitempty" json:"includeDeleted,omitempty"`
}

SearchAssetsParams defines parameters for SearchAssets.

type SearchAssetsParamsSort

type SearchAssetsParamsSort string

SearchAssetsParamsSort defines parameters for SearchAssets.

const (
	SearchAssetsParamsSortNewest    SearchAssetsParamsSort = "newest"
	SearchAssetsParamsSortOldest    SearchAssetsParamsSort = "oldest"
	SearchAssetsParamsSortRelevance SearchAssetsParamsSort = "relevance"
)

Defines values for SearchAssetsParamsSort.

type Server

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

func (*Server) DeleteAsset

func (s *Server) DeleteAsset(w http.ResponseWriter, r *http.Request, id AssetId)

func (*Server) GetAsset

func (s *Server) GetAsset(w http.ResponseWriter, r *http.Request, id AssetId)

func (*Server) GetHealthz

func (s *Server) GetHealthz(w http.ResponseWriter, _ *http.Request)

func (*Server) GetMediaVariant

func (s *Server) GetMediaVariant(w http.ResponseWriter, r *http.Request, id AssetId, variant GetMediaVariantParamsVariant)

func (*Server) GetReadyz

func (s *Server) GetReadyz(w http.ResponseWriter, _ *http.Request)

func (*Server) ListTags

func (s *Server) ListTags(w http.ResponseWriter, r *http.Request, params ListTagsParams)

func (*Server) SearchAssets

func (s *Server) SearchAssets(w http.ResponseWriter, r *http.Request, params SearchAssetsParams)

func (*Server) UpdateAsset

func (s *Server) UpdateAsset(w http.ResponseWriter, r *http.Request, id AssetId)

func (*Server) UploadAsset

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

type ServerInterface

type ServerInterface interface {
	// Search and browse assets
	// (GET /api/assets)
	SearchAssets(w http.ResponseWriter, r *http.Request, params SearchAssetsParams)
	// Upload a new asset
	// (POST /api/assets)
	UploadAsset(w http.ResponseWriter, r *http.Request)
	// Soft delete an asset
	// (DELETE /api/assets/{id})
	DeleteAsset(w http.ResponseWriter, r *http.Request, id AssetId)
	// Get an asset by id
	// (GET /api/assets/{id})
	GetAsset(w http.ResponseWriter, r *http.Request, id AssetId)
	// Update asset metadata
	// (PATCH /api/assets/{id})
	UpdateAsset(w http.ResponseWriter, r *http.Request, id AssetId)
	// List tags (optionally by prefix)
	// (GET /api/tags)
	ListTags(w http.ResponseWriter, r *http.Request, params ListTagsParams)
	// Liveness check
	// (GET /healthz)
	GetHealthz(w http.ResponseWriter, r *http.Request)
	// Serve image bytes for an asset variant
	// (GET /media/{id}/{variant})
	GetMediaVariant(w http.ResponseWriter, r *http.Request, id AssetId, variant GetMediaVariantParamsVariant)
	// Readiness check
	// (GET /readyz)
	GetReadyz(w http.ResponseWriter, r *http.Request)
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

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

ServerInterfaceWrapper converts contexts to parameters.

func (*ServerInterfaceWrapper) DeleteAsset

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

DeleteAsset operation middleware

func (*ServerInterfaceWrapper) GetAsset

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

GetAsset operation middleware

func (*ServerInterfaceWrapper) GetHealthz

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

GetHealthz operation middleware

func (*ServerInterfaceWrapper) GetMediaVariant

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

GetMediaVariant operation middleware

func (*ServerInterfaceWrapper) GetReadyz

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

GetReadyz operation middleware

func (*ServerInterfaceWrapper) ListTags

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

ListTags operation middleware

func (*ServerInterfaceWrapper) SearchAssets

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

SearchAssets operation middleware

func (*ServerInterfaceWrapper) UpdateAsset

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

UpdateAsset operation middleware

func (*ServerInterfaceWrapper) UploadAsset

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

UploadAsset operation middleware

type Sort

type Sort string

Sort defines model for Sort.

const (
	SortNewest    Sort = "newest"
	SortOldest    Sort = "oldest"
	SortRelevance Sort = "relevance"
)

Defines values for Sort.

type Tag

type Tag struct {
	Name string `json:"name"`
}

Tag defines model for Tag.

type TagFilter

type TagFilter = []string

TagFilter defines model for TagFilter.

type TagListResponse

type TagListResponse struct {
	Items    []Tag `json:"items"`
	Page     int   `json:"page"`
	PageSize int   `json:"pageSize"`
	Total    int   `json:"total"`
}

TagListResponse defines model for TagListResponse.

type TooManyValuesForParamError

type TooManyValuesForParamError struct {
	ParamName string
	Count     int
}

func (*TooManyValuesForParamError) Error

type UnescapedCookieParamError

type UnescapedCookieParamError struct {
	ParamName string
	Err       error
}

func (*UnescapedCookieParamError) Error

func (e *UnescapedCookieParamError) Error() string

func (*UnescapedCookieParamError) Unwrap

func (e *UnescapedCookieParamError) Unwrap() error

type Unimplemented

type Unimplemented struct{}

func (Unimplemented) DeleteAsset

func (_ Unimplemented) DeleteAsset(w http.ResponseWriter, r *http.Request, id AssetId)

Soft delete an asset (DELETE /api/assets/{id})

func (Unimplemented) GetAsset

func (_ Unimplemented) GetAsset(w http.ResponseWriter, r *http.Request, id AssetId)

Get an asset by id (GET /api/assets/{id})

func (Unimplemented) GetHealthz

func (_ Unimplemented) GetHealthz(w http.ResponseWriter, r *http.Request)

Liveness check (GET /healthz)

func (Unimplemented) GetMediaVariant

func (_ Unimplemented) GetMediaVariant(w http.ResponseWriter, r *http.Request, id AssetId, variant GetMediaVariantParamsVariant)

Serve image bytes for an asset variant (GET /media/{id}/{variant})

func (Unimplemented) GetReadyz

func (_ Unimplemented) GetReadyz(w http.ResponseWriter, r *http.Request)

Readiness check (GET /readyz)

func (Unimplemented) ListTags

func (_ Unimplemented) ListTags(w http.ResponseWriter, r *http.Request, params ListTagsParams)

List tags (optionally by prefix) (GET /api/tags)

func (Unimplemented) SearchAssets

func (_ Unimplemented) SearchAssets(w http.ResponseWriter, r *http.Request, params SearchAssetsParams)

Search and browse assets (GET /api/assets)

func (Unimplemented) UpdateAsset

func (_ Unimplemented) UpdateAsset(w http.ResponseWriter, r *http.Request, id AssetId)

Update asset metadata (PATCH /api/assets/{id})

func (Unimplemented) UploadAsset

func (_ Unimplemented) UploadAsset(w http.ResponseWriter, r *http.Request)

Upload a new asset (POST /api/assets)

type UnmarshalingParamError

type UnmarshalingParamError struct {
	ParamName string
	Err       error
}

func (*UnmarshalingParamError) Error

func (e *UnmarshalingParamError) Error() string

func (*UnmarshalingParamError) Unwrap

func (e *UnmarshalingParamError) Unwrap() error

type UpdateAssetJSONRequestBody

type UpdateAssetJSONRequestBody = AssetUpdate

UpdateAssetJSONRequestBody defines body for UpdateAsset for application/json ContentType.

type UploadAssetMultipartBody

type UploadAssetMultipartBody struct {
	Caption    *string            `json:"caption,omitempty"`
	Credit     *string            `json:"credit,omitempty"`
	File       openapi_types.File `json:"file"`
	Source     *string            `json:"source,omitempty"`
	Tags       *[]string          `json:"tags,omitempty"`
	Title      *string            `json:"title,omitempty"`
	UsageNotes *string            `json:"usageNotes,omitempty"`
}

UploadAssetMultipartBody defines parameters for UploadAsset.

type UploadAssetMultipartRequestBody

type UploadAssetMultipartRequestBody UploadAssetMultipartBody

UploadAssetMultipartRequestBody defines body for UploadAsset for multipart/form-data ContentType.

Jump to

Keyboard shortcuts

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