api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package api provides the implementation of the API server for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API is the main HTTP server that serves both the ingest API and the documentation portal.

func New

func New(cfg Config, svc Service, views ViewRenderer) (*API, error)

New creates a new API instance with the provided configuration, service, and view renderer. It validates the configuration and returns an error if the listen address is not specified.

func (*API) Run

func (a *API) Run(ctx context.Context) error

Run starts the API server with the provided configuration. It listens on the address specified in the configuration and handles graceful shutdown. When the context is cancelled, in-flight requests are given a grace period to complete before the server is forcefully closed.

type Config

type Config struct {
	Listen           string   `mapstructure:"listen"`
	APIKeys          []string `mapstructure:"api_keys"`            //nolint:gosec // This is a config struct, not a secret value
	MaxIngestBodyMiB int64    `mapstructure:"max_ingest_body_mib"` // Maximum ingest request body in MiB (default 50).
}

Config holds the configuration for the API server.

type MockService

type MockService struct {
	mock.Mock
}

MockService is an autogenerated mock type for the Service type

func NewMockService

func NewMockService(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockService

NewMockService creates a new instance of MockService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockService) EXPECT

func (_m *MockService) EXPECT() *MockService_Expecter

func (*MockService) GetAsset

func (_m *MockService) GetAsset(ctx context.Context, repo string, path string) ([]byte, error)

GetAsset provides a mock function with given fields: ctx, repo, path

func (*MockService) GetDocument

func (_m *MockService) GetDocument(ctx context.Context, repo string, path string) (core.Document, []byte, []core.Heading, error)

GetDocument provides a mock function with given fields: ctx, repo, path

func (*MockService) IngestDocuments

func (_m *MockService) IngestDocuments(ctx context.Context, req *core.IngestRequest) (*core.IngestResponse, error)

IngestDocuments provides a mock function with given fields: ctx, req

func (*MockService) ListDocuments

func (_m *MockService) ListDocuments(ctx context.Context, repo string) ([]core.DocumentMeta, error)

ListDocuments provides a mock function with given fields: ctx, repo

func (*MockService) ListRepos

func (_m *MockService) ListRepos(ctx context.Context) ([]core.RepoInfo, error)

ListRepos provides a mock function with given fields: ctx

func (*MockService) SearchDocs

func (_m *MockService) SearchDocs(ctx context.Context, query string, opts core.SearchOpts) (*core.SearchResults, error)

SearchDocs provides a mock function with given fields: ctx, query, opts

type MockService_Expecter

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

func (*MockService_Expecter) GetAsset

func (_e *MockService_Expecter) GetAsset(ctx interface{}, repo interface{}, path interface{}) *MockService_GetAsset_Call

GetAsset is a helper method to define mock.On call

  • ctx context.Context
  • repo string
  • path string

func (*MockService_Expecter) GetDocument

func (_e *MockService_Expecter) GetDocument(ctx interface{}, repo interface{}, path interface{}) *MockService_GetDocument_Call

GetDocument is a helper method to define mock.On call

  • ctx context.Context
  • repo string
  • path string

func (*MockService_Expecter) IngestDocuments

func (_e *MockService_Expecter) IngestDocuments(ctx interface{}, req interface{}) *MockService_IngestDocuments_Call

IngestDocuments is a helper method to define mock.On call

  • ctx context.Context
  • req *core.IngestRequest

func (*MockService_Expecter) ListDocuments

func (_e *MockService_Expecter) ListDocuments(ctx interface{}, repo interface{}) *MockService_ListDocuments_Call

ListDocuments is a helper method to define mock.On call

  • ctx context.Context
  • repo string

func (*MockService_Expecter) ListRepos

func (_e *MockService_Expecter) ListRepos(ctx interface{}) *MockService_ListRepos_Call

ListRepos is a helper method to define mock.On call

  • ctx context.Context

func (*MockService_Expecter) SearchDocs

func (_e *MockService_Expecter) SearchDocs(ctx interface{}, query interface{}, opts interface{}) *MockService_SearchDocs_Call

SearchDocs is a helper method to define mock.On call

  • ctx context.Context
  • query string
  • opts core.SearchOpts

type MockService_GetAsset_Call

type MockService_GetAsset_Call struct {
	*mock.Call
}

MockService_GetAsset_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAsset'

func (*MockService_GetAsset_Call) Return

func (*MockService_GetAsset_Call) Run

func (*MockService_GetAsset_Call) RunAndReturn

type MockService_GetDocument_Call

type MockService_GetDocument_Call struct {
	*mock.Call
}

MockService_GetDocument_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDocument'

func (*MockService_GetDocument_Call) Return

func (*MockService_GetDocument_Call) Run

func (*MockService_GetDocument_Call) RunAndReturn

type MockService_IngestDocuments_Call

type MockService_IngestDocuments_Call struct {
	*mock.Call
}

MockService_IngestDocuments_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IngestDocuments'

func (*MockService_IngestDocuments_Call) Return

func (*MockService_IngestDocuments_Call) Run

func (*MockService_IngestDocuments_Call) RunAndReturn

type MockService_ListDocuments_Call

type MockService_ListDocuments_Call struct {
	*mock.Call
}

MockService_ListDocuments_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListDocuments'

func (*MockService_ListDocuments_Call) Return

func (*MockService_ListDocuments_Call) Run

func (*MockService_ListDocuments_Call) RunAndReturn

type MockService_ListRepos_Call

type MockService_ListRepos_Call struct {
	*mock.Call
}

MockService_ListRepos_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListRepos'

func (*MockService_ListRepos_Call) Return

func (*MockService_ListRepos_Call) Run

func (*MockService_ListRepos_Call) RunAndReturn

type MockService_SearchDocs_Call

type MockService_SearchDocs_Call struct {
	*mock.Call
}

MockService_SearchDocs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SearchDocs'

func (*MockService_SearchDocs_Call) Return

func (*MockService_SearchDocs_Call) Run

func (*MockService_SearchDocs_Call) RunAndReturn

type MockViewRenderer

type MockViewRenderer struct {
	mock.Mock
}

MockViewRenderer is an autogenerated mock type for the ViewRenderer type

func NewMockViewRenderer

func NewMockViewRenderer(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockViewRenderer

NewMockViewRenderer creates a new instance of MockViewRenderer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockViewRenderer) EXPECT

func (*MockViewRenderer) RenderDoc

func (_m *MockViewRenderer) RenderDoc(w io.Writer, doc core.Document, html []byte, headings []core.Heading, navDocs []core.DocumentMeta, partial bool) error

RenderDoc provides a mock function with given fields: w, doc, html, headings, navDocs, partial

func (*MockViewRenderer) RenderHome

func (_m *MockViewRenderer) RenderHome(w io.Writer, repos []core.RepoInfo, partial bool) error

RenderHome provides a mock function with given fields: w, repos, partial

func (*MockViewRenderer) RenderNotFound

func (_m *MockViewRenderer) RenderNotFound(w io.Writer) error

RenderNotFound provides a mock function with given fields: w

func (*MockViewRenderer) RenderRepoIndex

func (_m *MockViewRenderer) RenderRepoIndex(w io.Writer, repo string, docs []core.DocumentMeta, partial bool) error

RenderRepoIndex provides a mock function with given fields: w, repo, docs, partial

func (*MockViewRenderer) RenderSearch

func (_m *MockViewRenderer) RenderSearch(w io.Writer, query string, results *core.SearchResults, partial bool) error

RenderSearch provides a mock function with given fields: w, query, results, partial

type MockViewRenderer_Expecter

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

func (*MockViewRenderer_Expecter) RenderDoc

func (_e *MockViewRenderer_Expecter) RenderDoc(w interface{}, doc interface{}, html interface{}, headings interface{}, navDocs interface{}, partial interface{}) *MockViewRenderer_RenderDoc_Call

RenderDoc is a helper method to define mock.On call

  • w io.Writer
  • doc core.Document
  • html []byte
  • headings []core.Heading
  • navDocs []core.DocumentMeta
  • partial bool

func (*MockViewRenderer_Expecter) RenderHome

func (_e *MockViewRenderer_Expecter) RenderHome(w interface{}, repos interface{}, partial interface{}) *MockViewRenderer_RenderHome_Call

RenderHome is a helper method to define mock.On call

  • w io.Writer
  • repos []core.RepoInfo
  • partial bool

func (*MockViewRenderer_Expecter) RenderNotFound

func (_e *MockViewRenderer_Expecter) RenderNotFound(w interface{}) *MockViewRenderer_RenderNotFound_Call

RenderNotFound is a helper method to define mock.On call

  • w io.Writer

func (*MockViewRenderer_Expecter) RenderRepoIndex

func (_e *MockViewRenderer_Expecter) RenderRepoIndex(w interface{}, repo interface{}, docs interface{}, partial interface{}) *MockViewRenderer_RenderRepoIndex_Call

RenderRepoIndex is a helper method to define mock.On call

  • w io.Writer
  • repo string
  • docs []core.DocumentMeta
  • partial bool

func (*MockViewRenderer_Expecter) RenderSearch

func (_e *MockViewRenderer_Expecter) RenderSearch(w interface{}, query interface{}, results interface{}, partial interface{}) *MockViewRenderer_RenderSearch_Call

RenderSearch is a helper method to define mock.On call

  • w io.Writer
  • query string
  • results *core.SearchResults
  • partial bool

type MockViewRenderer_RenderDoc_Call

type MockViewRenderer_RenderDoc_Call struct {
	*mock.Call
}

MockViewRenderer_RenderDoc_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RenderDoc'

func (*MockViewRenderer_RenderDoc_Call) Return

func (*MockViewRenderer_RenderDoc_Call) Run

func (_c *MockViewRenderer_RenderDoc_Call) Run(run func(w io.Writer, doc core.Document, html []byte, headings []core.Heading, navDocs []core.DocumentMeta, partial bool)) *MockViewRenderer_RenderDoc_Call

func (*MockViewRenderer_RenderDoc_Call) RunAndReturn

type MockViewRenderer_RenderHome_Call

type MockViewRenderer_RenderHome_Call struct {
	*mock.Call
}

MockViewRenderer_RenderHome_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RenderHome'

func (*MockViewRenderer_RenderHome_Call) Return

func (*MockViewRenderer_RenderHome_Call) Run

func (*MockViewRenderer_RenderHome_Call) RunAndReturn

type MockViewRenderer_RenderNotFound_Call

type MockViewRenderer_RenderNotFound_Call struct {
	*mock.Call
}

MockViewRenderer_RenderNotFound_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RenderNotFound'

func (*MockViewRenderer_RenderNotFound_Call) Return

func (*MockViewRenderer_RenderNotFound_Call) Run

func (*MockViewRenderer_RenderNotFound_Call) RunAndReturn

type MockViewRenderer_RenderRepoIndex_Call

type MockViewRenderer_RenderRepoIndex_Call struct {
	*mock.Call
}

MockViewRenderer_RenderRepoIndex_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RenderRepoIndex'

func (*MockViewRenderer_RenderRepoIndex_Call) Return

func (*MockViewRenderer_RenderRepoIndex_Call) Run

func (*MockViewRenderer_RenderRepoIndex_Call) RunAndReturn

type MockViewRenderer_RenderSearch_Call

type MockViewRenderer_RenderSearch_Call struct {
	*mock.Call
}

MockViewRenderer_RenderSearch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RenderSearch'

func (*MockViewRenderer_RenderSearch_Call) Return

func (*MockViewRenderer_RenderSearch_Call) Run

func (*MockViewRenderer_RenderSearch_Call) RunAndReturn

type Service

type Service interface {
	IngestDocuments(ctx context.Context, req *core.IngestRequest) (*core.IngestResponse, error)
	GetDocument(ctx context.Context, repo, path string) (core.Document, []byte, []core.Heading, error)
	GetAsset(ctx context.Context, repo, path string) ([]byte, error)
	SearchDocs(ctx context.Context, query string, opts core.SearchOpts) (*core.SearchResults, error)
	ListRepos(ctx context.Context) ([]core.RepoInfo, error)
	ListDocuments(ctx context.Context, repo string) ([]core.DocumentMeta, error)
}

Service defines the interface for core business logic operations.

type ViewRenderer

type ViewRenderer interface {
	RenderHome(w io.Writer, repos []core.RepoInfo, partial bool) error
	RenderRepoIndex(w io.Writer, repo string, docs []core.DocumentMeta, partial bool) error
	RenderDoc(w io.Writer, doc core.Document, html []byte, headings []core.Heading, navDocs []core.DocumentMeta, partial bool) error
	RenderSearch(w io.Writer, query string, results *core.SearchResults, partial bool) error
	RenderNotFound(w io.Writer) error
}

ViewRenderer defines the interface for rendering HTML views.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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