server

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindAvailablePort

func FindAvailablePort(host string, start int) int

FindAvailablePort finds an available port starting from the given port, binding to the specified host.

Types

type Opener added in v0.12.0

type Opener struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Kind string `json:"kind"` // "editor", "terminal", "files", "action"
	Bin  string `json:"bin"`
}

Opener represents an application that can open a project directory.

type Option

type Option func(*Server)

Option configures a Server.

func WithDataDir added in v0.12.0

func WithDataDir(dir string) Option

WithDataDir sets the data directory used for update caching.

func WithGenerateFunc added in v0.4.0

func WithGenerateFunc(f insight.GenerateFunc) Option

WithGenerateFunc overrides the insight generation function, allowing tests to substitute a stub. Nil is ignored.

func WithGenerateStreamFunc added in v0.10.0

func WithGenerateStreamFunc(f insight.GenerateStreamFunc) Option

WithGenerateStreamFunc overrides the streaming insight generation function used by the SSE handler. Nil is ignored.

func WithUpdateChecker added in v0.12.0

func WithUpdateChecker(f UpdateCheckFunc) Option

WithUpdateChecker overrides the update check function, allowing tests to substitute a deterministic stub.

func WithVersion

func WithVersion(v VersionInfo) Option

WithVersion sets the build-time version metadata.

type SSEStream

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

SSEStream manages a Server-Sent Events connection.

func NewSSEStream

func NewSSEStream(w http.ResponseWriter) (*SSEStream, error)

NewSSEStream initializes an SSE connection by setting the required headers and flushing them to the client. Returns an error if the ResponseWriter does not support streaming.

func (*SSEStream) ForceWriteDeadlineNow added in v0.10.0

func (s *SSEStream) ForceWriteDeadlineNow()

ForceWriteDeadlineNow asks the underlying writer (when supported) to expire write deadlines immediately. This is used during shutdown to unblock stalled writes.

func (*SSEStream) Send

func (s *SSEStream) Send(event, data string) bool

Send writes an SSE event with the given name and string data. It returns false when the write fails.

func (*SSEStream) SendJSON

func (s *SSEStream) SendJSON(event string, v any) bool

SendJSON writes an SSE event with JSON-serialized data. Logs and skips the event if marshaling fails.

type Server

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

Server is the HTTP server that serves the SPA and REST API.

func New

func New(
	cfg config.Config, database *db.DB, engine *sync.Engine,
	opts ...Option,
) *Server

New creates a new Server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the http.Handler with middleware applied.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the HTTP server.

func (*Server) SetGithubToken

func (s *Server) SetGithubToken(token string)

SetGithubToken updates the GitHub token for testing.

func (*Server) SetPort

func (s *Server) SetPort(port int)

SetPort updates the listen port (for testing).

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the HTTP server.

type UpdateCheckFunc added in v0.12.0

type UpdateCheckFunc func(
	currentVersion string,
	forceCheck bool,
	cacheDir string,
) (*update.UpdateInfo, error)

UpdateCheckFunc is the signature for functions that check for available updates. The default is update.CheckForUpdate.

type VersionInfo

type VersionInfo struct {
	Version   string `json:"version"`
	Commit    string `json:"commit"`
	BuildDate string `json:"build_date"`
}

VersionInfo holds build-time version metadata.

Jump to

Keyboard shortcuts

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