refactor(cmd/dsfxctl,internal/client): use single file

This commit is contained in:
Dustin Stiles 2025-03-22 13:39:45 -04:00
parent defca2fa74
commit 87587bb02f
Signed by: duwstiles
GPG Key ID: BCD9912EC231FC87
3 changed files with 34 additions and 39 deletions

View File

@ -3,7 +3,7 @@ package main
import ( import (
"context" "context"
"koti.casa/numenor-labs/dsfx/internal/client/client" "koti.casa/numenor-labs/dsfx/internal/client"
"koti.casa/numenor-labs/dsfx/internal/lib/disk" "koti.casa/numenor-labs/dsfx/internal/lib/disk"
"koti.casa/numenor-labs/dsfx/internal/lib/system" "koti.casa/numenor-labs/dsfx/internal/lib/system"
) )

View File

@ -14,17 +14,46 @@ import (
"koti.casa/numenor-labs/dsfx/internal/lib/network" "koti.casa/numenor-labs/dsfx/internal/lib/network"
"koti.casa/numenor-labs/dsfx/internal/lib/storage/scoped" "koti.casa/numenor-labs/dsfx/internal/lib/storage/scoped"
"koti.casa/numenor-labs/dsfx/internal/lib/system" "koti.casa/numenor-labs/dsfx/internal/lib/system"
"koti.casa/numenor-labs/dsfx/internal/client/conf"
) )
const (
// DefaultConfigDir is the default directory for the dsfxctl configuration.
DefaultConfigDir = "/etc/dsfxctl"
// DefaultHost is the default host for the dsfxctl application.
DefaultHost = "0.0.0.0"
)
// Conf holds the configuration for the dsfxctl application.
type Conf struct {
// Directories
ConfigDir string
// Networking
Host string
}
func loadConfigFromSystem(sys system.System) Conf {
var c Conf
c.ConfigDir = sys.GetEnv("DSFXCTL_CONFIG_DIR")
if c.ConfigDir == "" {
c.ConfigDir = DefaultConfigDir
}
c.Host = sys.GetEnv("DSFXCTL_HOST")
if c.Host == "" {
c.Host = DefaultHost
}
return c
}
// Client represents the client application for dsfxctl. // Client represents the client application for dsfxctl.
type Client struct { type Client struct {
// resources // resources
disk disk.Disk disk disk.Disk
system system.System system system.System
// configuration // configuration
conf conf.Conf conf Conf
// storage scopes // storage scopes
configScope disk.Disk configScope disk.Disk
} }
@ -32,7 +61,7 @@ type Client struct {
// New creates a new Client instance with the provided disk, system, and // New creates a new Client instance with the provided disk, system, and
// configuration. // configuration.
func New(disk disk.Disk, system system.System) *Client { func New(disk disk.Disk, system system.System) *Client {
conf := conf.FromSystem(system) conf := loadConfigFromSystem(system)
return &Client{ return &Client{
// resources // resources

View File

@ -1,34 +0,0 @@
package conf
import "koti.casa/numenor-labs/dsfx/internal/lib/system"
const (
// DefaultConfigDir is the default directory for the dsfxctl configuration.
DefaultConfigDir = "/etc/dsfxctl"
// DefaultHost is the default host for the dsfxctl application.
DefaultHost = "0.0.0.0"
)
// Conf holds the configuration for the dsfxctl application.
type Conf struct {
// Directories
ConfigDir string
// Networking
Host string
}
func FromSystem(sys system.System) Conf {
var c Conf
c.ConfigDir = sys.GetEnv("DSFXCTL_CONFIG_DIR")
if c.ConfigDir == "" {
c.ConfigDir = DefaultConfigDir
}
c.Host = sys.GetEnv("DSFXCTL_HOST")
if c.Host == "" {
c.Host = DefaultHost
}
return c
}