Skip to content

Commit

Permalink
client,webserver: re-work to modify config per JoeGruff suggestions #2
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-warrior777 committed Jan 31, 2025
1 parent 88abb68 commit 6fcf4ef
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
14 changes: 12 additions & 2 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ type Config struct {
WebConfig
LogConfig
MMConfig
AppVersion string
// AppData and ConfigPath should be parsed from the command-line,
// as it makes no sense to set these in the config file itself. If no values
// are assigned, defaults will be used.
Expand All @@ -163,7 +164,7 @@ type Config struct {
// Web creates a configuration for the webserver. This is a Config method
// instead of a WebConfig method because Language is an app-level setting used
// by both core and rpcserver.
func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc bool, appVersion string) *webserver.Config {
func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc bool) *webserver.Config {
addr := cfg.WebAddr
host, _, err := net.SplitHostPort(addr)
if err == nil && host != "" {
Expand Down Expand Up @@ -195,9 +196,11 @@ func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc boo
UTC: utc,
CertFile: certFile,
KeyFile: keyFile,
NoEmbed: cfg.NoEmbedSite,
HttpProf: cfg.HTTPProfile,
AppVersion: cfg.AppVersion,
Language: cfg.Language,
Tor: cfg.Tor,
AppVersion: appVersion,
}
}

Expand Down Expand Up @@ -351,9 +354,16 @@ func ResolveConfig(appData string, cfg *Config) error {
cfg.MMConfig.EventLogDBPath = defaultMMEventLogDBPath
}

cfg.AppVersion = userAppVersion(Version)
return nil
}

// userAppVersion returns a simple user-facing version: maj.min.patch.
func userAppVersion(fullVersion string) string {
parts := strings.Split(fullVersion, "-")
return parts[0]
}

// setNet sets the filepath for the network directory and some network specific
// files. It returns a suggested path for the database file and a log file. If
// using a file rotator, the directory of the log filepath as parsed by
Expand Down
6 changes: 1 addition & 5 deletions client/cmd/bisonw-desktop/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import (
"runtime"
"runtime/debug"
"runtime/pprof"
"strings"
"sync"
"sync/atomic"
"syscall"
Expand Down Expand Up @@ -223,10 +222,7 @@ func mainCore() error {
}()
}

parts := strings.Split(app.Version, "-")
userAppVersion := parts[0]

webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc, userAppVersion))
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc))
if err != nil {
return fmt.Errorf("failed creating web server: %w", err)
}
Expand Down
8 changes: 1 addition & 7 deletions client/cmd/bisonw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func runCore(cfg *app.Config) error {
}

if !cfg.NoWeb {
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc, userAppVersion(app.Version)))
webSrv, err := webserver.New(cfg.Web(clientCore, marketMaker, logMaker.Logger("WEB"), utc))
if err != nil {
return fmt.Errorf("failed creating web server: %w", err)
}
Expand Down Expand Up @@ -231,9 +231,3 @@ func promptShutdown(clientCore *core.Core) bool {
fmt.Println("Shutdown aborted.")
return false
}

// userAppVersion returns a simplified version string for end users.
func userAppVersion(fullAppVersion string) string {
parts := strings.Split(fullAppVersion, "-")
return parts[0]
}
15 changes: 8 additions & 7 deletions client/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ type Config struct {
CustomSiteDir string
Language string
Logger dex.Logger
UTC bool // for stdout http request logging
UTC bool // for stdout http request logging
AppVersion string // user app version for UI
CertFile string
KeyFile string
// NoEmbed indicates to serve files from the system disk rather than the
Expand All @@ -240,10 +241,9 @@ type Config struct {
// should be used by default since site files from older distributions may
// be present on the disk. When NoEmbed is true, this also implies reloading
// and execution of html templates on each request.
NoEmbed bool
HttpProf bool
Tor bool
AppVersion string
NoEmbed bool
HttpProf bool
Tor bool
}

type valStamp struct {
Expand Down Expand Up @@ -277,8 +277,9 @@ type WebServer struct {
bondBufMtx sync.Mutex
bondBuf map[uint32]valStamp

appVersion string

useDEXBranding bool
appVersion string
}

// New is the constructor for a new WebServer. CustomSiteDir in the Config can
Expand Down Expand Up @@ -404,8 +405,8 @@ func New(cfg *Config) (*WebServer, error) {
cachedPasswords: make(map[string]*cachedPassword),
tor: cfg.Tor,
bondBuf: map[uint32]valStamp{},
useDEXBranding: useDEXBranding,
appVersion: cfg.AppVersion,
useDEXBranding: useDEXBranding,
}
s.lang.Store(lang)

Expand Down

0 comments on commit 6fcf4ef

Please sign in to comment.