Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run golines #150

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions cmd/tx-submit-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ var cmdlineFlags struct {
}

func main() {
flag.StringVar(&cmdlineFlags.configFile, "config", "", "path to config file to load")
flag.StringVar(
&cmdlineFlags.configFile,
"config",
"",
"path to config file to load",
)
flag.Parse()

// Load config
Expand All @@ -54,17 +59,32 @@ func main() {

// Start debug listener
if cfg.Debug.ListenPort > 0 {
logger.Infof("starting debug listener on %s:%d", cfg.Debug.ListenAddress, cfg.Debug.ListenPort)
logger.Infof(
"starting debug listener on %s:%d",
cfg.Debug.ListenAddress,
cfg.Debug.ListenPort,
)
go func() {
err := http.ListenAndServe(fmt.Sprintf("%s:%d", cfg.Debug.ListenAddress, cfg.Debug.ListenPort), nil)
err := http.ListenAndServe(
fmt.Sprintf(
"%s:%d",
cfg.Debug.ListenAddress,
cfg.Debug.ListenPort,
),
nil,
)
if err != nil {
logger.Fatalf("failed to start debug listener: %s", err)
}
}()
}

// Start API listener
logger.Infof("starting API listener on %s:%d", cfg.Api.ListenAddress, cfg.Api.ListenPort)
logger.Infof(
"starting API listener on %s:%d",
cfg.Api.ListenAddress,
cfg.Api.ListenPort,
)
if err := api.Start(cfg); err != nil {
logger.Fatalf("failed to start API: %s", err)
}
Expand Down
17 changes: 13 additions & 4 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ func handleHasTx(c *gin.Context) {
cborData, err := cbor.Marshal(txHash)
if err != nil {
logger.Errorf("failed to encode transaction hash to CBOR: %s", err)
c.JSON(400, fmt.Sprintf("failed to encode transaction hash to CBOR: %s", err))
c.JSON(
400,
fmt.Sprintf("failed to encode transaction hash to CBOR: %s", err),
)
return
}

Expand Down Expand Up @@ -279,7 +282,9 @@ func handleSubmitTx(c *gin.Context) {
ouroboros.WithNodeToNode(false),
ouroboros.WithLocalTxSubmissionConfig(
localtxsubmission.NewConfig(
localtxsubmission.WithTimeout(time.Duration(cfg.Node.Timeout)*time.Second),
localtxsubmission.WithTimeout(
time.Duration(cfg.Node.Timeout)*time.Second,
),
),
),
)
Expand All @@ -293,7 +298,9 @@ func handleSubmitTx(c *gin.Context) {
if err := oConn.Dial("tcp", fmt.Sprintf("%s:%d", cfg.Node.Address, cfg.Node.Port)); err != nil {
logger.Errorf("failure connecting to node via TCP: %s", err)
c.JSON(500, "failure communicating with node")
_ = ginmetrics.GetMonitor().GetMetric("tx_submit_fail_count").Inc(nil)
_ = ginmetrics.GetMonitor().
GetMetric("tx_submit_fail_count").
Inc(nil)
return
}
} else {
Expand All @@ -310,7 +317,9 @@ func handleSubmitTx(c *gin.Context) {
if ok {
logger.Errorf("failure communicating with node: %s", err)
c.JSON(500, "failure communicating with node")
_ = ginmetrics.GetMonitor().GetMetric("tx_submit_fail_count").Inc(nil)
_ = ginmetrics.GetMonitor().
GetMetric("tx_submit_fail_count").
Inc(nil)
}
}()
defer func() {
Expand Down
18 changes: 9 additions & 9 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ type Config struct {

type LoggingConfig struct {
Healthchecks bool `yaml:"healthchecks" envconfig:"LOGGING_HEALTHCHECKS"`
Level string `yaml:"level" envconfig:"LOGGING_LEVEL"`
Level string `yaml:"level" envconfig:"LOGGING_LEVEL"`
}

type ApiConfig struct {
ListenAddress string `yaml:"address" envconfig:"API_LISTEN_ADDRESS"`
ListenPort uint `yaml:"port" envconfig:"API_LISTEN_PORT"`
ListenPort uint `yaml:"port" envconfig:"API_LISTEN_PORT"`
}

type DebugConfig struct {
ListenAddress string `yaml:"address" envconfig:"DEBUG_ADDRESS"`
ListenPort uint `yaml:"port" envconfig:"DEBUG_PORT"`
ListenPort uint `yaml:"port" envconfig:"DEBUG_PORT"`
}

type MetricsConfig struct {
ListenAddress string `yaml:"address" envconfig:"METRICS_LISTEN_ADDRESS"`
ListenPort uint `yaml:"port" envconfig:"METRICS_LISTEN_PORT"`
ListenPort uint `yaml:"port" envconfig:"METRICS_LISTEN_PORT"`
}

type NodeConfig struct {
Network string `yaml:"network" envconfig:"CARDANO_NETWORK"`
Network string `yaml:"network" envconfig:"CARDANO_NETWORK"`
NetworkMagic uint32 `yaml:"networkMagic" envconfig:"CARDANO_NODE_NETWORK_MAGIC"`
Address string `yaml:"address" envconfig:"CARDANO_NODE_SOCKET_TCP_HOST"`
Port uint `yaml:"port" envconfig:"CARDANO_NODE_SOCKET_TCP_PORT"`
SocketPath string `yaml:"socketPath" envconfig:"CARDANO_NODE_SOCKET_PATH"`
Timeout uint `yaml:"timeout" envconfig:"CARDANO_NODE_SOCKET_TIMEOUT"`
Address string `yaml:"address" envconfig:"CARDANO_NODE_SOCKET_TCP_HOST"`
Port uint `yaml:"port" envconfig:"CARDANO_NODE_SOCKET_TCP_PORT"`
SocketPath string `yaml:"socketPath" envconfig:"CARDANO_NODE_SOCKET_PATH"`
Timeout uint `yaml:"timeout" envconfig:"CARDANO_NODE_SOCKET_TIMEOUT"`
}

// Singleton config instance with default values
Expand Down
8 changes: 6 additions & 2 deletions internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func Setup(cfg *config.LoggingConfig) {
// Change timestamp key name
loggerConfig.EncoderConfig.TimeKey = "timestamp"
// Use a human readable time format
loggerConfig.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout(time.RFC3339)
loggerConfig.EncoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout(
time.RFC3339,
)

// Set level
if cfg.Level != "" {
Expand Down Expand Up @@ -63,5 +65,7 @@ func GetDesugaredLogger() *zap.Logger {
}

func GetAccessLogger() *zap.Logger {
return globalLogger.Desugar().With(zap.String("type", "access")).WithOptions(zap.WithCaller(false))
return globalLogger.Desugar().
With(zap.String("type", "access")).
WithOptions(zap.WithCaller(false))
}
Loading