knowlfx

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package knowlfx contains the public Fx composition layer for Knowl. It wraps the plain-Go host assembly in pkg/knowl and keeps Fx-specific lifecycle wiring out of the root package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Module

func Module(ctx context.Context, options Options) fx.Option

Module exposes the public Fx module for one Knowl host. Host assembly delegates to the plain-Go constructor in root pkg/knowl.

func NewApp

func NewApp(ctx context.Context, options Options, additional ...fx.Option) *fx.App

NewApp builds an fx.App for one Knowl host.

Example
package main

import (
	"context"
	"fmt"
	"os"
	"path/filepath"
	"time"

	"github.com/baldaworks/knowl/pkg/knowl"
	contentfs "github.com/baldaworks/knowl/pkg/knowl/content/fs"
	"github.com/baldaworks/knowl/pkg/knowl/provider"
	"github.com/baldaworks/knowl/pkg/knowlfx"
	"go.uber.org/fx"
)

func main() {
	root, err := os.MkdirTemp("", "knowl-fx-example-")
	if err != nil {
		panic(err)
	}
	defer func() { _ = os.RemoveAll(root) }()

	workspace, err := contentfs.New(root)
	if err != nil {
		panic(err)
	}
	if err := workspace.Init(); err != nil {
		panic(err)
	}

	config := knowl.DefaultConfig()
	config.Workspace = workspace.Root()
	config.StorePath = filepath.Join(workspace.Root(), ".knowl", "knowl.sqlite")
	config.ListenAddr = "127.0.0.1:0"

	var host *knowl.Host
	application := knowlfx.NewApp(context.Background(), knowlfx.Options{
		Config:     config,
		Maintainer: provider.Fixture{},
	}, fx.Populate(&host))
	if err := application.Err(); err != nil {
		fmt.Println(false)
		return
	}

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	if err := application.Start(ctx); err != nil {
		fmt.Println(false)
		return
	}
	ready := host != nil && host.Ready()
	if err := application.Stop(ctx); err != nil {
		fmt.Println(false)
		return
	}

	fmt.Println(ready)

}
Output:
true

Types

type Host

type Host = knowl.Host

type Options

type Options = knowl.Options

Jump to

Keyboard shortcuts

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