refactor: remove service factory wrappers, call store init methods directly
Replace InitNodeService/GetNodeService/GetNodeServiceForUser with thin NewLocalNodeService/NewRemoteNodeService constructors; move wiring logic into cmd/root.go (getNodeService helper) and an inline closure in serve.go. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,6 @@ package service
|
||||
import (
|
||||
"axolotl/models"
|
||||
"axolotl/store"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -12,7 +11,6 @@ import (
|
||||
// invalid state by interacting with this interface alone.
|
||||
//
|
||||
// Every NodeService instance is bound to a specific user (see User()).
|
||||
// GetNodeService returns an error when no user is configured.
|
||||
type NodeService interface {
|
||||
// User returns the name/ID of the user this service instance acts on behalf of.
|
||||
User() string
|
||||
@@ -68,33 +66,10 @@ type RelInput struct {
|
||||
Target string // name or node ID; the service resolves names. Empty = tag rel.
|
||||
}
|
||||
|
||||
func InitNodeService(path string) error {
|
||||
return store.InitSQLiteStore(path)
|
||||
func NewLocalNodeService(st store.GraphStore, user string) NodeService {
|
||||
return &nodeServiceImpl{store: st, userID: user}
|
||||
}
|
||||
|
||||
func GetNodeService(cfg *store.Config) (NodeService, error) {
|
||||
user := cfg.GetUser()
|
||||
if user == "" {
|
||||
return nil, fmt.Errorf("no user configured: run 'ax user set <username>' first")
|
||||
}
|
||||
if rc, ok := cfg.GetRemoteConfig(); ok {
|
||||
base := fmt.Sprintf("http://%s:%d", rc.Host, rc.Port)
|
||||
return &apiClient{base: base, user: user, http: &http.Client{}}, nil
|
||||
}
|
||||
st, err := store.FindAndOpenSQLiteStore()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &nodeServiceImpl{store: st, userID: user}, nil
|
||||
}
|
||||
|
||||
func GetNodeServiceForUser(user string) (NodeService, error) {
|
||||
if user == "" {
|
||||
return nil, fmt.Errorf("user is required")
|
||||
}
|
||||
st, err := store.FindOrInitSQLiteStore()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &nodeServiceImpl{store: st, userID: user}, nil
|
||||
func NewRemoteNodeService(base, user string) NodeService {
|
||||
return &apiClient{base: base, user: user, http: &http.Client{}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user