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 ¶
Module exposes the public Fx module for one Knowl host. Host assembly delegates to the plain-Go constructor in root pkg/knowl.
func NewApp ¶
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 ¶
Click to show internal directories.
Click to hide internal directories.