http

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Error400Title            = "Bad Request"
	Error401Title            = "Unauthorized"
	Error404Title            = "Not Found"
	Error409Title            = "Conflict"
	Error503Title            = "Service Unavailable"
	Error500Title            = "Internal Server Error"
	Error500Detail           = "An unhandled error has occurred. Try again later. If it is a bug we already recorded it. Retrying will most likely not help"
	Error502Title            = "Bad Gateway"
	Error502Detail           = "An upstream Thing Model repository returned an error"
	ErrorRepoAmbiguousDetail = "Repository ambiguous. Repeat the request with the 'repo' query parameter"

	HeaderAuthorization       = "Authorization"
	HeaderContentType         = "Content-Type"
	HeaderCacheControl        = "Cache-Control"
	HeaderXContentTypeOptions = "X-Content-Type-Options"
	MimeText                  = "text/plain"
	MimeJSON                  = "application/json"
	MimeOctetStream           = "application/octet-stream"
	MimeProblemJSON           = "application/problem+json"
	NoSniff                   = "nosniff"
	NoCache                   = "no-cache, no-store, max-age=0, must-revalidate"
)

Variables

This section is empty.

Functions

func HandleByteResponse

func HandleByteResponse(w http.ResponseWriter, r *http.Request, status int, mime string, data []byte)

func HandleErrorResponse

func HandleErrorResponse(w http.ResponseWriter, r *http.Request, err error)

func HandleHealthyResponse

func HandleHealthyResponse(w http.ResponseWriter, r *http.Request)

func HandleJsonResponse

func HandleJsonResponse(w http.ResponseWriter, r *http.Request, status int, data interface{})

func NewBadRequestError

func NewBadRequestError(err error, detail string, args ...any) error

func NewDefaultHandlerService

func NewDefaultHandlerService(servedRepo model.RepoSpec) (*defaultHandlerService, error)

func NewNotFoundError

func NewNotFoundError(err error, detail string, args ...any) error

func NewServiceUnavailableError

func NewServiceUnavailableError(err error, detail string) error

func NewUnauthorizedError

func NewUnauthorizedError(err error, detail string, args ...any) error

Types

type BaseHttpError

type BaseHttpError struct {
	Status int
	Title  string
	Detail string
	Err    error
}

func (*BaseHttpError) Error

func (e *BaseHttpError) Error() string

func (*BaseHttpError) Unwrap

func (e *BaseHttpError) Unwrap() error

type HandlerService

type HandlerService interface {
	ListInventory(ctx context.Context, repo string, search *model.SearchParams) (*model.SearchResult, error)
	ListAuthors(ctx context.Context, search *model.SearchParams) ([]string, error)
	ListManufacturers(ctx context.Context, search *model.SearchParams) ([]string, error)
	ListMpns(ctx context.Context, search *model.SearchParams) ([]string, error)
	FindInventoryEntries(ctx context.Context, repo string, name string) ([]model.FoundEntry, error)
	FetchThingModel(ctx context.Context, repo, tmID string, restoreId bool) ([]byte, error)
	FetchLatestThingModel(ctx context.Context, repo, fetchName string, restoreId bool) ([]byte, error)
	ImportThingModel(ctx context.Context, repo string, file []byte, opts repos.ImportOptions) (repos.ImportResult, error)
	DeleteThingModel(ctx context.Context, repo string, tmID string) error
	CheckHealth(ctx context.Context) error
	CheckHealthLive(ctx context.Context) error
	CheckHealthReady(ctx context.Context) error
	CheckHealthStartup(ctx context.Context) error
	GetCompletions(ctx context.Context, kind string, args []string, toComplete string) ([]string, error)
	GetTMMetadata(ctx context.Context, repo string, tmID string) ([]model.FoundVersion, error)
	GetLatestTMMetadata(ctx context.Context, repo string, fetchName string) (model.FoundVersion, error)
	FetchAttachment(ctx context.Context, repo string, ref model.AttachmentContainerRef, attachmentFileName string) ([]byte, error)
	ImportAttachment(ctx context.Context, repo string, ref model.AttachmentContainerRef, attachmentFileName string, content []byte, contentType string, force bool) error
	DeleteAttachment(ctx context.Context, repo string, ref model.AttachmentContainerRef, attachmentFileName string) error
	ListRepos(ctx context.Context) ([]model.RepoDescription, error)
}

type Mapper

type Mapper struct {
	Ctx context.Context
}

func NewMapper

func NewMapper(ctx context.Context) *Mapper

func (*Mapper) GetInventoryData

func (m *Mapper) GetInventoryData(entries []model.FoundEntry) []server.InventoryEntry

func (*Mapper) GetInventoryEntry

func (m *Mapper) GetInventoryEntry(entry model.FoundEntry) server.InventoryEntry

func (*Mapper) GetInventoryEntryVersion

func (m *Mapper) GetInventoryEntryVersion(version model.FoundVersion) server.InventoryEntryVersion

func (*Mapper) GetInventoryEntryVersions

func (m *Mapper) GetInventoryEntryVersions(versions []model.FoundVersion) []server.InventoryEntryVersion

func (*Mapper) GetInventoryMeta

func (m *Mapper) GetInventoryMeta(res model.SearchResult) server.Meta

type TmcHandler

type TmcHandler struct {
	Service HandlerService
	Options TmcHandlerOptions
}

func NewTmcHandler

func NewTmcHandler(handlerService HandlerService, options TmcHandlerOptions) *TmcHandler

func (*TmcHandler) DeleteThingModelById

func (h *TmcHandler) DeleteThingModelById(w http.ResponseWriter, r *http.Request, tmID string, params server.DeleteThingModelByIdParams)

DeleteThingModelById Delete a Thing Model by ID (DELETE /thing-models/{id})

func (*TmcHandler) GetAuthors

func (h *TmcHandler) GetAuthors(w http.ResponseWriter, r *http.Request, params server.GetAuthorsParams)

func (*TmcHandler) GetCompletions

func (h *TmcHandler) GetCompletions(w http.ResponseWriter, r *http.Request, params server.GetCompletionsParams)

func (*TmcHandler) GetHealth

func (h *TmcHandler) GetHealth(w http.ResponseWriter, r *http.Request)

GetHealth Get the overall health of the service (GET /healthz)

func (*TmcHandler) GetHealthLive

func (h *TmcHandler) GetHealthLive(w http.ResponseWriter, r *http.Request)

GetHealthLive Returns the liveness of the service (GET /healthz/live)

func (*TmcHandler) GetHealthReady

func (h *TmcHandler) GetHealthReady(w http.ResponseWriter, r *http.Request)

GetHealthReady Returns the readiness of the service (GET /healthz/ready)

func (*TmcHandler) GetHealthStartup

func (h *TmcHandler) GetHealthStartup(w http.ResponseWriter, r *http.Request)

GetHealthStartup Returns whether the service is initialized (GET /healthz/startup)

func (*TmcHandler) GetInventory

func (h *TmcHandler) GetInventory(w http.ResponseWriter, r *http.Request, params server.GetInventoryParams)

Get the inventory of the catalog (GET /inventory)

func (*TmcHandler) GetInventoryByFetchName

func (h *TmcHandler) GetInventoryByFetchName(w http.ResponseWriter, r *http.Request, fetchName server.FetchName, params server.GetInventoryByFetchNameParams)

GetInventoryByFetchName Get the metadata of the most recent TM version matching the name (GET /inventory/.latest/{fetchName})

func (*TmcHandler) GetInventoryByID

func (h *TmcHandler) GetInventoryByID(w http.ResponseWriter, r *http.Request, tmID server.TMID, params server.GetInventoryByIDParams)

GetInventoryById Get the metadata of a single TM by ID (GET /inventory/{tmID})

func (*TmcHandler) GetInventoryByName

func (h *TmcHandler) GetInventoryByName(w http.ResponseWriter, r *http.Request, tmName string, params server.GetInventoryByNameParams)

GetInventoryByName Get an inventory entry by inventory name (GET /inventory/.tmName/{tmName})

func (*TmcHandler) GetManufacturers

func (h *TmcHandler) GetManufacturers(w http.ResponseWriter, r *http.Request, params server.GetManufacturersParams)

func (*TmcHandler) GetMpns

func (h *TmcHandler) GetMpns(w http.ResponseWriter, r *http.Request, params server.GetMpnsParams)

func (*TmcHandler) GetRepos

func (h *TmcHandler) GetRepos(w http.ResponseWriter, r *http.Request)

func (*TmcHandler) GetThingModelByFetchName

func (h *TmcHandler) GetThingModelByFetchName(w http.ResponseWriter, r *http.Request, fetchName server.FetchName, params server.GetThingModelByFetchNameParams)

GetThingModelByFetchName Get the content of a Thing Model by fetch name (GET /thing-models/.latest/{fetchName}

func (*TmcHandler) GetThingModelById

func (h *TmcHandler) GetThingModelById(w http.ResponseWriter, r *http.Request, id string, params server.GetThingModelByIdParams)

GetThingModelById Get the content of a Thing Model by its ID (GET /thing-models/{id})

func (*TmcHandler) ImportThingModel

func (h *TmcHandler) ImportThingModel(w http.ResponseWriter, r *http.Request, p server.ImportThingModelParams)

type TmcHandlerOptions

type TmcHandlerOptions struct {
	UrlContextRoot string
}

Directories

Path Synopsis
Package server provides primitives to interact with the openapi HTTP API.
Package server provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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