mirror of
https://git.numenor-labs.us/dsfx.git
synced 2025-04-29 08:10:34 +00:00
refactor(cmd/dsfxctl,internal/client): use single file
This commit is contained in:
parent
defca2fa74
commit
87587bb02f
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"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/system"
|
||||
)
|
||||
|
@ -14,17 +14,46 @@ import (
|
||||
"koti.casa/numenor-labs/dsfx/internal/lib/network"
|
||||
"koti.casa/numenor-labs/dsfx/internal/lib/storage/scoped"
|
||||
"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.
|
||||
type Client struct {
|
||||
// resources
|
||||
disk disk.Disk
|
||||
system system.System
|
||||
// configuration
|
||||
conf conf.Conf
|
||||
conf Conf
|
||||
// storage scopes
|
||||
configScope disk.Disk
|
||||
}
|
||||
@ -32,7 +61,7 @@ type Client struct {
|
||||
// New creates a new Client instance with the provided disk, system, and
|
||||
// configuration.
|
||||
func New(disk disk.Disk, system system.System) *Client {
|
||||
conf := conf.FromSystem(system)
|
||||
conf := loadConfigFromSystem(system)
|
||||
|
||||
return &Client{
|
||||
// resources
|
@ -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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user