api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: EUPL-1.2 Imports: 19 Imported by: 0

Documentation

Overview

Package api provides a service provider that wraps go-build's build, release, and SDK subsystems as REST endpoints with WebSocket event streaming.

Index

Examples

Constants

This section is empty.

Variables

View Source
var Assets embed.FS

Assets holds the built UI bundle (core-build.js and related files). The directory is populated by running `npm run build` in the ui/ directory.

Usage example: use api.Assets from package consumers as needed.

Functions

func Fail

func Fail(code, message string) any
Example
_ = Fail("bad_request", "invalid request")

func FailWithDetails

func FailWithDetails(code, message string, details any) any
Example
_ = FailWithDetails("bad_request", "invalid request", map[string]any{"field": "name"})

func New

func New(opts ...Option) core.Result
Example
_ = New(WithAddr("127.0.0.1:0"))

func OK

func OK(data any) any
Example
_ = OK(map[string]any{"status": "ok"})

Types

type BuildProvider

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

BuildProvider wraps go-build's build, release, and SDK operations as a service provider. It implements Provider, Streamable, Describable, and Renderable.

p := api.NewProvider(".", hub)

func NewProvider

func NewProvider(projectDir string, hub *events.Hub) *BuildProvider

NewProvider creates a BuildProvider for the given project directory. If projectDir is empty, the current working directory is used. The WS hub is used to emit real-time build events; pass nil if not available.

p := api.NewProvider(".", hub)

Example

--- v0.9.0 generated usage examples ---

_ = NewProvider(core.Path(core.TempDir(), "go-build-compliance"), nil)
core.Println("NewProvider")
Output:
NewProvider

func (*BuildProvider) BasePath

func (p *BuildProvider) BasePath() string

BasePath implements api.RouteGroup.

path := p.BasePath() // → "/api/v1/build"

Example
subject := &BuildProvider{}
_ = subject.BasePath()
core.Println("BuildProvider_BasePath")
Output:
BuildProvider_BasePath

func (*BuildProvider) Channels

func (p *BuildProvider) Channels() []string

Channels implements provider.Streamable.

channels := p.Channels() // → ["build.started", "build.complete", ...]

Example
subject := &BuildProvider{}
_ = subject.Channels()
core.Println("BuildProvider_Channels")
Output:
BuildProvider_Channels

func (*BuildProvider) Describe

func (p *BuildProvider) Describe() []RouteDescription

Describe implements api.DescribableGroup.

routes := p.Describe() // → [{Method: "GET", Path: "/config", ...}, ...]

Example
subject := &BuildProvider{}
_ = subject.Describe()
core.Println("BuildProvider_Describe")
Output:
BuildProvider_Describe

func (*BuildProvider) Element

func (p *BuildProvider) Element() provider.ElementSpec

Element implements provider.Renderable.

spec := p.Element() // → {Tag: "core-build-panel", Source: "/assets/core-build.js"}

Example
subject := &BuildProvider{}
_ = subject.Element()
core.Println("BuildProvider_Element")
Output:
BuildProvider_Element

func (*BuildProvider) Name

func (p *BuildProvider) Name() string

Name implements api.RouteGroup.

name := p.Name() // → "build"

Example
subject := &BuildProvider{}
_ = subject.Name()
core.Println("BuildProvider_Name")
Output:
BuildProvider_Name

func (*BuildProvider) RegisterRoutes

func (p *BuildProvider) RegisterRoutes(rg *gin.RouterGroup)

RegisterRoutes implements api.RouteGroup.

p.RegisterRoutes(rg)

Example
subject := &BuildProvider{}
subject.RegisterRoutes(gin.New().Group("/build"))
core.Println("BuildProvider_RegisterRoutes")
Output:
BuildProvider_RegisterRoutes

type DescribableGroup

type DescribableGroup interface {
	RouteGroup
	Describe() []RouteDescription
}

type Engine

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

func (*Engine) Handler

func (e *Engine) Handler() http.Handler
Example
engine := New().Value.(*Engine)
_ = engine.Handler()

func (*Engine) Register

func (e *Engine) Register(group RouteGroup)
Example
engine := New().Value.(*Engine)
engine.Register(httpTestGroup{name: "test", base: "/test"})

func (*Engine) Serve

func (e *Engine) Serve(ctx context.Context) core.Result
Example
var engine *Engine
_ = engine.Serve(context.Background())

type Info

type Info struct {
	Name string "json:\"name\""
	Path string "json:\"path\""
	Size int64  "json:\"size\""
}

Info holds JSON-friendly metadata about a dist/ file.

Example
subject := Info{Name: "app.tar.gz", Path: "/dist/app.tar.gz", Size: 42}
core.Println(subject.Name, subject.Size)
Output:
app.tar.gz 42

type Option

type Option func(*Engine)

func WithAddr

func WithAddr(addr string) Option
Example
_ = New(WithAddr("127.0.0.1:0"))

func WithWSHandler

func WithWSHandler(handler http.HandlerFunc) Option
Example
handler := func(http.ResponseWriter, *http.Request) {}
_ = New(WithWSHandler(handler))

func WithWSPath

func WithWSPath(path string) Option
Example
_ = New(WithWSPath("/ws"))

type ReleaseWorkflowRequest

type ReleaseWorkflowRequest struct {
	Path                     string
	WorkflowPath             string `json:"workflowPath"`
	WorkflowPathSnake        string `json:"workflow_path"`
	WorkflowPathHyphen       string `json:"workflow-path"`
	OutputPath               string `json:"outputPath"`
	OutputPathHyphen         string `json:"output-path"`
	OutputPathSnake          string `json:"output_path"`
	LegacyOutputPath         string `json:"output"`
	WorkflowOutputPath       string `json:"workflowOutputPath"`
	WorkflowOutputSnake      string `json:"workflow_output"`
	WorkflowOutputHyphen     string `json:"workflow-output"`
	WorkflowOutputPathSnake  string `json:"workflow_output_path"`
	WorkflowOutputPathHyphen string `json:"workflow-output-path"`
}

ReleaseWorkflowRequest captures the workflow-generation inputs exposed by the API.

request := ReleaseWorkflowRequest{Path: "ci/release.yml"} // writes ./ci/release.yml request := ReleaseWorkflowRequest{WorkflowOutputPath: "ops/release.yml"} // writes ./ops/release.yml

func (*ReleaseWorkflowRequest) Decode

func (r *ReleaseWorkflowRequest) Decode(data []byte) core.Result
Example
var subject ReleaseWorkflowRequest
_ = subject.Decode([]byte(`{"` + apiPathField + `":"ci/release.yml"}`))
core.Println(subject.Path)
Output:
ci/release.yml

type RouteDescription

type RouteDescription struct {
	Method      string         `json:"method,omitempty"`
	Path        string         `json:"path,omitempty"`
	Summary     string         `json:"summary,omitempty"`
	Description string         `json:"description,omitempty"`
	Tags        []string       `json:"tags,omitempty"`
	RequestBody map[string]any `json:"requestBody,omitempty"`
	Responses   map[string]any `json:"responses,omitempty"`
}

type RouteGroup

type RouteGroup interface {
	Name() string
	BasePath() string
	RegisterRoutes(*gin.RouterGroup)
}

type ToolBridge

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

func NewToolBridge

func NewToolBridge(basePath string) *ToolBridge
Example
bridge := NewToolBridge("/tools")
_ = bridge.Tools()

func (*ToolBridge) Add

func (b *ToolBridge) Add(descriptor ToolDescriptor, handler gin.HandlerFunc)
Example
bridge := NewToolBridge("/tools")
bridge.Add(ToolDescriptor{Name: "build"}, func(c *gin.Context) {})

func (*ToolBridge) BasePath

func (b *ToolBridge) BasePath() string
Example
bridge := NewToolBridge("/tools")
_ = bridge.BasePath()

func (*ToolBridge) Name

func (b *ToolBridge) Name() string
Example
bridge := NewToolBridge("/tools")
_ = bridge.Name()

func (*ToolBridge) RegisterRoutes

func (b *ToolBridge) RegisterRoutes(group *gin.RouterGroup)
Example
bridge := NewToolBridge("/tools")
router := gin.New()
bridge.RegisterRoutes(router.Group(bridge.BasePath()))

func (*ToolBridge) Tools

func (b *ToolBridge) Tools() []ToolDescriptor
Example
bridge := NewToolBridge("/tools")
bridge.Add(ToolDescriptor{Name: "build"}, func(c *gin.Context) {})
_ = bridge.Tools()

type ToolDescriptor

type ToolDescriptor struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Group       string `json:"group,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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