Skip to content

Commit

Permalink
chore: golines
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 committed Aug 30, 2024
1 parent d483303 commit cc8f3a2
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 40 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 31 additions & 7 deletions input/chainsync/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,35 @@ 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
}
// 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
Expand All @@ -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
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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:]
}
Expand Down
10 changes: 5 additions & 5 deletions input/chainsync/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions output/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
48 changes: 24 additions & 24 deletions output/push/fcm_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit cc8f3a2

Please sign in to comment.