service

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 20 Imported by: 0

README

ODP Service package

Package service integrates ODP with Go's standard net/http stack. Service implements http.Handler and owns the well-known document, fixed operation routes, representation defaults, request validation, bounded JSON parsing, media negotiation, localization headers, response validation, and Problem Details.

Small catalogs

NewStaticCatalog supplies the required Offering operations from an in-memory catalog. Configuring Collections also enables Collection listing, retrieval, and direct Offering membership. It validates identifiers and relationships at construction and uses opaque, integrity-protected stateless continuations.

catalog, err := service.NewStaticCatalog(service.StaticCatalogOptions{
	Offerings: []odp.Offering{
		{
			ID:         "gpu-h100",
			Name:       "H100 GPU",
			ODPVersion: odp.Version,
			Price:      &odp.PricePreview{Type: odp.PriceQuote},
		},
	},
})
if err != nil {
	return err
}

odpService, err := service.New(service.Options{
	Catalog: catalog,
	Document: odp.ServiceDocument{
		Branding: &odp.ServiceBranding{
			Icon: odp.ServiceBrandingImage{Source: "/branding/icon.svg", Type: odp.ServiceBrandingSVG},
			Logo: odp.ServiceBrandingImage{Source: "/branding/logo.svg", Type: odp.ServiceBrandingSVG},
		},
		Description:   "On-demand compute resources",
		HTTP: odp.HTTPConfiguration{
			EndpointBase: "/odp",
			OpenAPI:      &odp.ServiceOpenAPI{URL: "/openapi.json"},
		},
		Language:      "en",
		Localizations: []string{"en"},
		Name:          "Example Compute",
		Protocols: &odp.ServiceProtocols{
			Enrollment: []odp.EnrollmentProtocol{{Name: odp.ProtocolAEP}},
		},
	},
	OperationAuthentication: map[odp.Operation]odp.AuthenticationRequirement{
		odp.OperationGetOffering: odp.AuthenticationOptional,
	},
})

Branding is optional. When present, it contains both a square icon and a wide logo as SVG, PNG, or WebP resources. Raster icons are square and at least 200 by 200 pixels; raster logos use a 4:1 aspect ratio and are at least 400 by 100 pixels. SVG resources use the corresponding aspect ratio. Each image's optional Type provides a pre-retrieval format hint; set it when the resource URL does not have a recognizable filename extension. The optional Service-wide OpenAPI document is inherited by Offering Actions that identify only an operation ID.

Mount odpService at /.well-known/odp and its configured endpoint base. Operations default to not-required; OperationAuthentication advertises different access requirements. Authentication, AEP, MPP, x402, rate limiting, and application policy compose as ordinary HTTP middleware.

Storage-backed catalogs

Large Services configure Catalog with functions backed by their own storage and indexes. The runtime invokes only the function required for the incoming operation; it does not materialize, sort, or inspect the complete catalog. Each function receives the request context, original HTTP request, normalized representation, preferred language, limit, and opaque cursor.

Optional operation functions are the source of truth for Service Document advertisement. Search functions receive a validated request on the initial POST and nil on a continuation GET, so a Service can use either server-managed or integrity-protected stateless continuation state.

Catalog functions can return *service.Error for an intentional ODP Problem Details response. Unexpected errors become a generic 500 response without exposing application details.

Documentation

Overview

Package service provides framework-neutral HTTP integration for ODP Services.

Index

Constants

View Source
const (
	MediaType               = "application/odp+json"
	ProblemMediaType        = "application/problem+json"
	MaximumRequestBodyBytes = 65_536
	MaximumResourceBytes    = 524_288
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog

func NewStaticCatalog

func NewStaticCatalog(options StaticCatalogOptions) (Catalog, error)

type CatalogRequest

type CatalogRequest struct {
	Cursor         string
	Language       string
	Limit          int
	Representation odp.Representation
	Request        *http.Request
}

type Error

type Error struct {
	Code    string
	Header  http.Header
	Message string
	Status  int
}

func (*Error) Error

func (err *Error) Error() string

type Options

type Options struct {
	Catalog                 Catalog
	Document                odp.ServiceDocument
	OperationAuthentication map[odp.Operation]odp.AuthenticationRequirement
}

type Service

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

func New

func New(options Options) (*Service, error)

func (*Service) Document

func (service *Service) Document() odp.ServiceDocument

func (*Service) ServeHTTP

func (service *Service) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type StaticCatalogOptions

type StaticCatalogOptions struct {
	Collections []odp.Collection
	Offerings   []odp.Offering
}

Jump to

Keyboard shortcuts

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