server

package
v1.0.43 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 36 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapt added in v1.0.2

func Adapt[S any](fn func(grpc.ServiceRegistrar, S)) func(grpc.ServiceRegistrar, any)

func BufferGrpcStream added in v1.0.15

func BufferGrpcStream[M DataChunk](
	ctx context.Context,
	stream RecvStream[M],
	acceptable map[string]struct{},
	maxSize int,
) ([]byte, string, error)

* Used to buffer a client-side gRPC stream. * Example usage: * rpc UploadProfileImage(stream UploadImageRequest) returns (UploadImageResponse) {} * * message UploadImageRequest { bytes chunkData = 1; } * * // server-side handler * func (s *Server) UploadProfileImage(stream grpc.ClientStreamingServer[pb.UploadImageRequest, pb.UploadImageResponse]) error { * ctx := stream.Context() * acceptable := map[string]struct{}{ * "image/jpeg": {}, * "image/png": {}, * } * * data, mime, err := BufferGrpcStream(ctx, stream, acceptable, 10*1024*1024) // 10 MB limit * }

func RetryWithExponentialBackoff added in v1.0.15

func RetryWithExponentialBackoff(ctx context.Context, maxRetries int, baseDelay time.Duration, fn func() error) error

Types

type BootServer added in v1.0.0

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

func (*BootServer) Serve added in v1.0.0

func (s *BootServer) Serve(ctx context.Context) error

Serve blocks until context is cancelled or a listen error occurs.

func (*BootServer) Shutdown added in v1.0.0

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

Shutdown is rarely needed (Serve handles it), but exposed for tests.

type Builder added in v1.0.0

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

─── public fluent builder ───────────────────────────────────

func New added in v1.0.0

func New() *Builder

func (*Builder) AddMCPConfigurator added in v1.0.43

func (b *Builder) AddMCPConfigurator(factory any) *Builder

AddMCPConfigurator registers a factory function whose return type implements MCPConfigurator. Dependencies are injected the same way as for gRPC services and REST controllers. Example:

builder.AddMCPConfigurator(func(repo *UserRepo) *MyMCPTools {
    return &MyMCPTools{repo: repo}
})

func (*Builder) AddRestController added in v1.0.38

func (b *Builder) AddRestController(factory any) *Builder

AddRestController registers a REST controller factory for dependency injection. The factory is a function that takes dependencies as arguments and returns a type implementing RestController interface.

Example:

builder.AddRestController(func(userRepo UserRepository) *UserController {
    return &UserController{repo: userRepo}
})

func (*Builder) ApplySettings added in v1.0.26

func (b *Builder) ApplySettings(opts []grpc.ServerOption) *Builder

Apply server settings

func (*Builder) Build added in v1.0.0

func (b *Builder) Build() (*BootServer, error)

func (*Builder) CORS added in v1.0.0

func (b *Builder) CORS(c *cors.Cors) *Builder

func (*Builder) ConfigureMCP added in v1.0.43

func (b *Builder) ConfigureMCP(fn func(*mcp.Server)) *Builder

ConfigureMCP registers a function that is called with the MCP server during Build. Use this to add tools, resources, and prompts directly:

builder.ConfigureMCP(func(s *mcp.Server) {
    mcp.AddTool(s, &mcp.Tool{Name: "greet"}, SayHi)
})

func (*Builder) EnableSSL added in v1.0.0

func (b *Builder) EnableSSL(p SSLProvider) *Builder

func (*Builder) GRPCPort added in v1.0.0

func (b *Builder) GRPCPort(p string) *Builder

func (*Builder) HTTPPort added in v1.0.0

func (b *Builder) HTTPPort(p string) *Builder

func (*Builder) MCPHTTPOptions added in v1.0.43

func (b *Builder) MCPHTTPOptions(opts *mcp.StreamableHTTPOptions) *Builder

MCPHTTPOptions sets the StreamableHTTPOptions for the MCP handler. If nil, sensible defaults are used.

func (*Builder) MCPPath added in v1.0.43

func (b *Builder) MCPPath(path string) *Builder

MCPPath sets the HTTP path where the MCP server is mounted. Default is "/mcp".

func (*Builder) Provide added in v1.0.0

func (b *Builder) Provide(value any) *Builder

func (*Builder) ProvideAs added in v1.0.2

func (b *Builder) ProvideAs(value any, ifacePtr any) *Builder

func (*Builder) ProvideFunc added in v1.0.0

func (b *Builder) ProvideFunc(fn any) *Builder

func (*Builder) RegisterService added in v1.0.10

func (b *Builder) RegisterService(
	register func(grpc.ServiceRegistrar, any),
	factory any,
) *Builder

func (*Builder) RegisterTemporalActivity added in v1.0.10

func (b *Builder) RegisterTemporalActivity(factory any) *Builder

func (*Builder) RegisterTemporalWorkflow added in v1.0.10

func (b *Builder) RegisterTemporalWorkflow(w interface{}) *Builder

func (*Builder) StaticDir added in v1.0.36

func (b *Builder) StaticDir(dir string) *Builder

StaticDir sets the directory to serve static files from (e.g., "./static"). Static files will be served on the same HTTP port at /static/* path.

func (*Builder) Stream added in v1.0.0

func (b *Builder) Stream(i ...grpc.StreamServerInterceptor) *Builder

func (*Builder) Unary added in v1.0.0

func (b *Builder) Unary(i ...grpc.UnaryServerInterceptor) *Builder

func (*Builder) WithMCP added in v1.0.43

func (b *Builder) WithMCP(impl *mcp.Implementation, opts *mcp.ServerOptions) *Builder

WithMCP enables an MCP (Model Context Protocol) server on the HTTP port. The server is served via the Streamable HTTP transport at the configured path (default "/mcp"). Use AddMCPConfigurator or ConfigureMCP to add tools, resources and prompts to the server.

func (*Builder) WithTemporal added in v1.0.7

func (b *Builder) WithTemporal(taskQueue string, opts *client.Options) *Builder

type DataChunk added in v1.0.15

type DataChunk interface {
	GetData() []byte
}

type MCPConfigurator added in v1.0.43

type MCPConfigurator interface {
	ConfigureMCP(s *mcp.Server)
}

MCPConfigurator is implemented by types that configure an MCP server with tools, resources, prompts, etc. It is the MCP equivalent of RestController – register a factory via Builder.AddMCPConfigurator and go-api-boot will inject dependencies and call ConfigureMCP during Build.

type RecvStream added in v1.0.15

type RecvStream[M DataChunk] interface {
	Recv() (M, error)
}

type RestController added in v1.0.38

type RestController interface {
	// Routes returns the HTTP routes handled by this controller.
	Routes() []Route
}

RestController is an interface for HTTP REST controllers. Controllers implementing this interface can be registered with the Builder and will have their dependencies automatically injected.

type Route added in v1.0.38

type Route struct {
	// Pattern is the URL pattern for the route (e.g., "/api/users", "/api/users/{id}").
	Pattern string

	// Method is the HTTP method for the route (GET, POST, PUT, DELETE, etc.).
	// If empty, the route will handle all HTTP methods.
	Method string

	// Handler is the HTTP handler function for the route.
	Handler http.HandlerFunc
}

Route defines a single HTTP route with its pattern and handler.

type SSLManager added in v0.1.46

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

func NewSSLManager added in v0.1.46

func NewSSLManager(domain string, cache autocert.Cache) *SSLManager

NewSSLManager uses any autocert.Cache (dir, cloud, memory…)

func (*SSLManager) Configure added in v1.0.0

func (s *SSLManager) Configure(srv *http.Server) error

1) Wire GetCertificate into the server we’ll expose publicly.

func (*SSLManager) Run added in v1.0.0

func (s *SSLManager) Run(ctx context.Context) error
  1. Run ACME helper: listener on :80 + cert pre-fetch w/ backoff. Returns when ctx is cancelled.

type SSLProvider added in v1.0.0

type SSLProvider interface {
	// Configure mutates srv.TLSConfig so that http.Server can serve TLS.
	Configure(srv *http.Server) error

	// Run launches any background logic the provider needs
	// (ACME challenge listener, certificate refresh, etc.).
	// It must return when ctx is cancelled.
	Run(ctx context.Context) error
}

func CloudCacheProvider added in v1.0.0

func CloudCacheProvider(cfg *config.BootConfig, cloud cloud.Cloud) SSLProvider

Cloud provider (wraps SSLManager with SslCloudCache)

func DirCache added in v1.0.0

func DirCache(dir string) SSLProvider

Dir cache provider (1-liner)

type SslCloudCache added in v0.1.48

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

func NewSslCloudCache added in v0.1.48

func NewSslCloudCache(cfg *config.BootConfig, cloud cloud.Cloud) *SslCloudCache

ctor

func (*SslCloudCache) Delete added in v0.1.48

func (cc *SslCloudCache) Delete(ctx context.Context, name string) error

func (*SslCloudCache) Get added in v0.1.48

func (cc *SslCloudCache) Get(ctx context.Context, name string) ([]byte, error)

func (*SslCloudCache) Put added in v0.1.48

func (cc *SslCloudCache) Put(ctx context.Context, name string, data []byte) error

type WebProxy added in v0.1.34

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

func GetWebProxy added in v0.1.34

func GetWebProxy(server *grpc.Server) WebProxy

func (WebProxy) ServeHTTP added in v0.1.34

func (w WebProxy) ServeHTTP(resp http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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