Documentation
¶
Overview ¶
Package httpapi exposes the local device service without opening USB handles.
Index ¶
- Constants
- func New(service control.Service, options ...Option) http.Handler
- func NewWithRemote(service control.Service, protect func(http.Handler) http.Handler, ...) (http.Handler, http.Handler)
- type ErrorBody
- type ErrorResponse
- type FlashResetFailure
- type FlashResetTicket
- type Option
- func WithLibraryDirectory(dir string) Option
- func WithLocalProtection(protect func(http.Handler) http.Handler) Option
- func WithPatternDirectory(dir string) Option
- func WithPatternDirectoryV2(dir string) Option
- func WithPatternStore(store PatternStore) Option
- func WithPatternStoreV2(store PatternStoreV2) Option
- func WithSequenceAPI() Option
- func WithSequenceRouting(defaultSerial string, useSingleOnline bool, libraryDir string) Option
- type PatternLibraryInfo
- type PatternList
- type PatternPreview
- type PatternRef
- type PatternStore
- type PatternStoreV2
- type PatternSummary
- type PreviewRequest
- type SubmitRequest
Constants ¶
const FlashTicketHeader = "X-NB1-Flash-Ticket"
const MaxBodyBytes = control.MaxRequestBytes
const PatternLibraryContract = "nb1-pattern-library/v1"
const PatternLibraryV2Contract = "nb1-pattern-library/experimental-v2"
const PatternRefPreviewContract = "nb1-pattern-ref-preview/experimental-v1"
Variables ¶
This section is empty.
Functions ¶
func NewWithRemote ¶ added in v0.1.3
func NewWithRemote(service control.Service, protect func(http.Handler) http.Handler, options ...Option) (http.Handler, http.Handler)
NewWithRemote shares one API instance (including its library lock) between the loopback listener and a distinct listener with its own access checks. protect authenticates and restricts the network request before API dispatch.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorBody `json:"error"`
}
type FlashResetFailure ¶ added in v0.1.4
type FlashResetFailure struct {
Error ErrorBody `json:"error"`
Result flashreset.Result `json:"result"`
}
FlashResetFailure retains the hardware progress alongside the normal API error.
type FlashResetTicket ¶ added in v0.1.4
type FlashResetTicket struct {
Ticket string `json:"ticket"`
}
type Option ¶
type Option func(*handler)
func WithLibraryDirectory ¶
WithLibraryDirectory selects a local v1 library without accessing its files. An empty directory leaves library operations unavailable.
func WithLocalProtection ¶ added in v0.1.3
WithLocalProtection runs protection after the existing loopback Host and Origin checks. Requests from the separate HTTPS listener use its own gate.
func WithPatternDirectory ¶
WithPatternDirectory selects a library without opening or creating it. An invalid configuration disables only Pattern features, never ordinary lights. Empty selects the current service account's UserConfigDir()/nb1/patterns.
func WithPatternDirectoryV2 ¶
WithPatternDirectoryV2 selects an independent v2 library without filesystem I/O. Empty selects UserConfigDir()/nb1/patterns-v2. Only a valid save or import entering its write transaction may create the directory; failed publication does not promise to remove that directory. Invalid configuration disables this library while pure preview and ordinary device operations remain available.
func WithPatternStore ¶
func WithPatternStore(store PatternStore) Option
WithPatternStore opts in to the library without changing existing New calls.
func WithPatternStoreV2 ¶
func WithPatternStoreV2(store PatternStoreV2) Option
WithPatternStoreV2 opts in to one explicitly selected v2 store. It performs no store calls, path selection, default-directory lookup or v1 fallback. In particular, a pure preview never calls even Path on this store.
func WithSequenceAPI ¶
func WithSequenceAPI() Option
WithSequenceAPI selects the new runtime's route table.
type PatternLibraryInfo ¶
type PatternLibraryInfo struct {
Path string `json:"path"`
State string `json:"state"`
CreateOnly bool `json:"create_only"`
MaxRecords int `json:"max_records"`
MaxPackageBytes int `json:"max_package_bytes"`
RecordContract string `json:"record_contract"`
CompileContract string `json:"compile_contract"`
SnapshotKind string `json:"snapshot_kind"`
}
type PatternList ¶
type PatternList struct {
SchemaVersion int `json:"schema_version"`
Contract string `json:"contract"`
Library PatternLibraryInfo `json:"library"`
Patterns []PatternSummary `json:"patterns"`
}
type PatternPreview ¶
type PatternPreview struct {
PatternRef PatternRef `json:"pattern_ref"`
Preview control.PreviewResult `json:"preview"`
}
type PatternRef ¶
type PatternStore ¶
type PatternStore interface {
Path() string
List() ([]patterns.Record, error)
Get(string) (patterns.Record, error)
Resolve(string, string) (patterns.Record, error)
Export() ([]byte, error)
Import([]byte) (patternstore.ImportResult, error)
}
PatternStore owns only the bounded library. It never admits device work.
type PatternStoreV2 ¶
type PatternStoreV2 interface {
Path() string
List() ([]patternsv2.Inspection, error)
Get(string) (patternsv2.Inspection, error)
Resolve(string, string) (patternsv2.Record, error)
Export() ([]byte, error)
Import([]byte) (patternstore.ImportResultV2, error)
}
PatternStoreV2 is explicitly independent of the v1 library. P3 authoring and inspection never call Resolve or any service method; the separate execution adapter uses exact Resolve only after a new receipt miss.
type PatternSummary ¶
type PatternSummary struct {
ID string `json:"id"`
Title string `json:"title"`
Revision string `json:"revision"`
CompileContract string `json:"compile_contract"`
TotalSteps int `json:"total_steps"`
NominalDurationMS int64 `json:"nominal_duration_ms"`
OnFinish string `json:"on_finish"`
RequiredCapabilities []string `json:"required_capabilities"`
}
type PreviewRequest ¶
type PreviewRequest struct {
PatternRef *PatternRef `json:"pattern_ref,omitempty"`
Program *control.Program `json:"program,omitempty"`
Effect *control.Effect `json:"effect,omitempty"`
Serial *string `json:"serial,omitempty"`
}
PreviewRequest is compilation only. Serial optionally checks one configured cached snapshot; policy and receipts are not accepted. A fixed Pattern reference is mutually exclusive with Program and Effect.
type SubmitRequest ¶
type SubmitRequest struct {
Program *control.Program `json:"program,omitempty"`
Effect *control.Effect `json:"effect,omitempty"`
PatternRef *PatternRef `json:"pattern_ref,omitempty"`
Policy string `json:"policy"`
RequestID *string `json:"request_id,omitempty"`
ExpectedDaemonInstanceID *string `json:"expected_daemon_instance_id,omitempty"`
}