Skip to content

Commit

Permalink
webapi: Add Listen to webapi Config.
Browse files Browse the repository at this point in the history
No need for this value to be passed in separately, it can be passed in
the same as every other config value.
  • Loading branch information
jholdstock committed Sep 14, 2023
1 parent a33bcbc commit d1766c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cmd/vspd/vspd.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (v *vspd) run() int {

// Create and start webapi server.
apiCfg := webapi.Config{
Listen: v.cfg.Listen,
VSPFee: v.cfg.VSPFee,
Network: v.cfg.network,
SupportEmail: v.cfg.SupportEmail,
Expand All @@ -152,7 +153,7 @@ func (v *vspd) run() int {
MaxVoteChangeRecords: maxVoteChangeRecords,
VspdVersion: version.String(),
}
err = webapi.Start(ctx, requestShutdown, &shutdownWg, v.cfg.Listen, v.db, v.cfg.logger("API"),
err = webapi.Start(ctx, requestShutdown, &shutdownWg, v.db, v.cfg.logger("API"),
v.dcrd, v.wallets, apiCfg)
if err != nil {
v.log.Errorf("Failed to initialize webapi: %v", err)
Expand Down
7 changes: 4 additions & 3 deletions internal/webapi/webapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

type Config struct {
Listen string
VSPFee float64
Network *config.Network
FeeAccountName string
Expand Down Expand Up @@ -75,7 +76,7 @@ type server struct {
}

func Start(ctx context.Context, requestShutdown func(), shutdownWg *sync.WaitGroup,
listen string, vdb *database.VspDatabase, log slog.Logger, dcrd rpc.DcrdConnect,
vdb *database.VspDatabase, log slog.Logger, dcrd rpc.DcrdConnect,
wallets rpc.WalletConnect, cfg Config) error {

s := &server{
Expand Down Expand Up @@ -122,11 +123,11 @@ func Start(ctx context.Context, requestShutdown func(), shutdownWg *sync.WaitGro

// Create TCP listener.
var listenConfig net.ListenConfig
listener, err := listenConfig.Listen(ctx, "tcp", listen)
listener, err := listenConfig.Listen(ctx, "tcp", cfg.Listen)
if err != nil {
return err
}
log.Infof("Listening on %s", listen)
log.Infof("Listening on %s", cfg.Listen)

srv := http.Server{
Handler: s.router(cookieSecret, dcrd, wallets),
Expand Down

0 comments on commit d1766c3

Please sign in to comment.