diff --git a/Makefile b/Makefile index 4fccd0f..d55cce2 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ clean: format: mod-tidy go fmt ./... +golines: + golines -w --ignore-generated --chain-split-dots --max-len=80 --reformat-tags . + swagger: swag f -g api.go -d api,output swag i -g api.go -d api,output diff --git a/docs/docs.go b/docs/docs.go index 8dc3691..f6494e2 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,4 +1,5 @@ -// Package docs Code generated by swaggo/swag. DO NOT EDIT +// Code generated by swaggo/swag. DO NOT EDIT. + package docs import "github.com/swaggo/swag" diff --git a/input/chainsync/chainsync.go b/input/chainsync/chainsync.go index 77353d5..cfc3f71 100644 --- a/input/chainsync/chainsync.go +++ b/input/chainsync/chainsync.go @@ -225,14 +225,24 @@ func (c *ChainSync) setupConnection() error { if c.autoReconnect { c.autoReconnectDelay = 0 if c.logger != nil { - c.logger.Infof("reconnecting to %s due to error: %s", c.dialAddress, err) + c.logger.Infof( + "reconnecting to %s due to error: %s", + c.dialAddress, + err, + ) } for { if c.autoReconnectDelay > 0 { - c.logger.Infof("waiting %s to reconnect", c.autoReconnectDelay) + c.logger.Infof( + "waiting %s to reconnect", + c.autoReconnectDelay, + ) time.Sleep(c.autoReconnectDelay) // Double current reconnect delay up to maximum - c.autoReconnectDelay = min(c.autoReconnectDelay*2, maxAutoReconnectDelay) + c.autoReconnectDelay = min( + c.autoReconnectDelay*2, + maxAutoReconnectDelay, + ) } else { // Set initial reconnect delay c.autoReconnectDelay = 1 * time.Second @@ -240,7 +250,10 @@ func (c *ChainSync) setupConnection() error { // Shutdown current connection if err := c.oConn.Close(); err != nil { if c.logger != nil { - c.logger.Warnf("failed to properly close connection: %s", err) + c.logger.Warnf( + "failed to properly close connection: %s", + err, + ) } } // Set the intersect points from the cursor cache @@ -250,7 +263,11 @@ func (c *ChainSync) setupConnection() error { // Restart the connection if err := c.Start(); err != nil { if c.logger != nil { - c.logger.Infof("reconnecting to %s due to error: %s", c.dialAddress, err) + c.logger.Infof( + "reconnecting to %s due to error: %s", + c.dialAddress, + err, + ) } continue } @@ -309,7 +326,11 @@ func (c *ChainSync) handleRollForward( return nil } -func (c *ChainSync) handleBlockFetchBlock(ctx blockfetch.CallbackContext, blockType uint, block ledger.Block) error { +func (c *ChainSync) handleBlockFetchBlock( + ctx blockfetch.CallbackContext, + blockType uint, + block ledger.Block, +) error { blockEvt := event.New( "chainsync.block", time.Now(), @@ -356,7 +377,10 @@ func (c *ChainSync) updateStatus( ) { // Update cursor cache blockHashBytes, _ := hex.DecodeString(blockHash) - c.cursorCache = append(c.cursorCache, ocommon.Point{Slot: slotNumber, Hash: blockHashBytes}) + c.cursorCache = append( + c.cursorCache, + ocommon.Point{Slot: slotNumber, Hash: blockHashBytes}, + ) if len(c.cursorCache) > cursorCacheSize { c.cursorCache = c.cursorCache[len(c.cursorCache)-cursorCacheSize:] } diff --git a/input/chainsync/tx.go b/input/chainsync/tx.go index 958a4e2..a36cd37 100644 --- a/input/chainsync/tx.go +++ b/input/chainsync/tx.go @@ -62,11 +62,11 @@ func NewTransactionEvent( includeCbor bool, ) TransactionEvent { evt := TransactionEvent{ - Transaction: tx, - BlockHash: block.Hash(), - Inputs: tx.Inputs(), - Outputs: tx.Outputs(), - Fee: tx.Fee(), + Transaction: tx, + BlockHash: block.Hash(), + Inputs: tx.Inputs(), + Outputs: tx.Outputs(), + Fee: tx.Fee(), } if includeCbor { evt.TransactionCbor = tx.Cbor() diff --git a/internal/config/config.go b/internal/config/config.go index 72f1323..a832318 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -43,7 +43,7 @@ type Config struct { type ApiConfig struct { ListenAddress string `yaml:"address" envconfig:"API_ADDRESS"` - ListenPort uint `yaml:"port" envconfig:"API_PORT"` + ListenPort uint `yaml:"port" envconfig:"API_PORT"` } type LoggingConfig struct { diff --git a/output/notify/notify.go b/output/notify/notify.go index 15d8368..7275cb7 100644 --- a/output/notify/notify.go +++ b/output/notify/notify.go @@ -55,8 +55,13 @@ func (n *NotifyOutput) Start() error { if err != nil { return err } - if _, err := os.Stat(fmt.Sprintf("%s/%s", userCacheDir, "adder")); os.IsNotExist(err) { - err = os.MkdirAll(fmt.Sprintf("%s/%s", userCacheDir, "adder"), os.ModePerm) + if _, err := os.Stat(fmt.Sprintf("%s/%s", userCacheDir, "adder")); os.IsNotExist( + err, + ) { + err = os.MkdirAll( + fmt.Sprintf("%s/%s", userCacheDir, "adder"), + os.ModePerm, + ) if err != nil { panic(err) } diff --git a/output/push/fcm_repository.go b/output/push/fcm_repository.go index 6fd199f..641f7a4 100644 --- a/output/push/fcm_repository.go +++ b/output/push/fcm_repository.go @@ -60,14 +60,14 @@ func getTokenStore() *TokenStore { return fcmStore } -// @Summary Store FCM Token -// @Description Store a new FCM token -// @Accept json -// @Produce json -// @Param body body TokenRequest true "FCM Token Request" -// @Success 201 {string} string "Created" -// @Failure 400 {object} ErrorResponse -// @Router /fcm [post] +// @Summary Store FCM Token +// @Description Store a new FCM token +// @Accept json +// @Produce json +// @Param body body TokenRequest true "FCM Token Request" +// @Success 201 {string} string "Created" +// @Failure 400 {object} ErrorResponse +// @Router /fcm [post] func storeFCMToken(c *gin.Context) { var req TokenRequest @@ -81,14 +81,14 @@ func storeFCMToken(c *gin.Context) { c.Status(http.StatusCreated) } -// @Summary Get FCM Token -// @Description Get an FCM token by its value -// @Accept json -// @Produce json -// @Param token path string true "FCM Token" -// @Success 200 {object} TokenResponse -// @Failure 404 {object} ErrorResponse -// @Router /fcm/{token} [get] +// @Summary Get FCM Token +// @Description Get an FCM token by its value +// @Accept json +// @Produce json +// @Param token path string true "FCM Token" +// @Success 200 {object} TokenResponse +// @Failure 404 {object} ErrorResponse +// @Router /fcm/{token} [get] func readFCMToken(c *gin.Context) { token := c.Param("token") store := getTokenStore() @@ -100,14 +100,14 @@ func readFCMToken(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"fcmToken": storedToken}) } -// @Summary Delete FCM Token -// @Description Delete an FCM token by its value -// @Accept json -// @Produce json -// @Param token path string true "FCM Token" -// @Success 204 {string} string "No Content" -// @Failure 404 {object} ErrorResponse -// @Router /fcm/{token} [delete] +// @Summary Delete FCM Token +// @Description Delete an FCM token by its value +// @Accept json +// @Produce json +// @Param token path string true "FCM Token" +// @Success 204 {string} string "No Content" +// @Failure 404 {object} ErrorResponse +// @Router /fcm/{token} [delete] func deleteFCMToken(c *gin.Context) { token := c.Param("token") store := getTokenStore()