diff --git a/Makefile b/Makefile index 4d39b01..f6c5e26 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,10 @@ clean: format: mod-tidy go fmt ./... + gofmt -s -w $(GO_FILES) + +golines: + golines -w --ignore-generated --chain-split-dots --max-len=80 --reformat-tags . swagger: swag f -g api.go -d internal/api,. diff --git a/cmd/bursa/wallet.go b/cmd/bursa/wallet.go index 7a85a1a..8e1e3f1 100644 --- a/cmd/bursa/wallet.go +++ b/cmd/bursa/wallet.go @@ -44,7 +44,8 @@ func walletCreateCommand() *cobra.Command { }, } - walletCreateCommand.PersistentFlags().StringVar(&output, "output", "", "optional path to write files") + walletCreateCommand.PersistentFlags(). + StringVar(&output, "output", "", "optional path to write files") return &walletCreateCommand } diff --git a/internal/api/api.go b/internal/api/api.go index 8e4ed4c..63284ee 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -194,7 +194,10 @@ func handleWalletRestore(c *gin.Context) { // Restore the wallet using the mnemonic wallet, err := bursa.NewDefaultWallet(request.Mnemonic) if err != nil { - c.JSON(http.StatusInternalServerError, gin.H{"error": "Internal server error"}) + c.JSON( + http.StatusInternalServerError, + gin.H{"error": "Internal server error"}, + ) _ = ginmetrics.GetMonitor(). GetMetric("bursa_wallets_fail_count"). Inc(nil) @@ -203,5 +206,7 @@ func handleWalletRestore(c *gin.Context) { // Return the wallet details c.JSON(http.StatusOK, wallet) - _ = ginmetrics.GetMonitor().GetMetric("bursa_wallets_restore_count").Inc(nil) + _ = ginmetrics.GetMonitor(). + GetMetric("bursa_wallets_restore_count"). + Inc(nil) } diff --git a/internal/api/api_test.go b/internal/api/api_test.go index 3260f15..454b01f 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -42,25 +42,27 @@ func TestRestoreWallet(t *testing.T) { t.Parallel() // Create a mock server - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/api/wallet/restore" && r.Method == "POST" { - var request WalletRestoreRequest - if err := json.NewDecoder(r.Body).Decode(&request); err != nil { - http.Error(w, "Invalid request", http.StatusBadRequest) - return - } + server := httptest.NewServer( + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/api/wallet/restore" && r.Method == "POST" { + var request WalletRestoreRequest + if err := json.NewDecoder(r.Body).Decode(&request); err != nil { + http.Error(w, "Invalid request", http.StatusBadRequest) + return + } - // Respond with the mock wallet JSON data - w.WriteHeader(http.StatusOK) - _, err := w.Write([]byte(mockWalletResponseJSON)) - if err != nil { - t.Fatalf("Failed to write response: %v", err) - } + // Respond with the mock wallet JSON data + w.WriteHeader(http.StatusOK) + _, err := w.Write([]byte(mockWalletResponseJSON)) + if err != nil { + t.Fatalf("Failed to write response: %v", err) + } - } else { - w.WriteHeader(http.StatusNotFound) - } - })) + } else { + w.WriteHeader(http.StatusNotFound) + } + }), + ) defer server.Close() // Prepare the request body @@ -68,7 +70,11 @@ func TestRestoreWallet(t *testing.T) { Mnemonic: "depth kitchen crystal history rabbit brief harbor palace tent frog city charge inflict tiger negative young furnace solid august educate bounce canal someone erode", }) - resp, err := http.Post(server.URL+"/api/wallet/restore", "application/json", bytes.NewBuffer(requestBody)) + resp, err := http.Post( + server.URL+"/api/wallet/restore", + "application/json", + bytes.NewBuffer(requestBody), + ) if err != nil { t.Fatalf("Failed to make request: %v", err) } @@ -89,7 +95,11 @@ func TestRestoreWallet(t *testing.T) { } if !reflect.DeepEqual(expectedResponse, actualResponse) { - t.Errorf("Expected response %v, got %v", expectedResponse, actualResponse) + t.Errorf( + "Expected response %v, got %v", + expectedResponse, + actualResponse, + ) } }) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index e997c8d..d6436e3 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -57,10 +57,16 @@ func Run(output string) { fmt.Printf("payment.vkey=%s\n", bursa.GetKeyFile(w.PaymentVKey)) fmt.Printf("payment.skey=%s\n", bursa.GetKeyFile(w.PaymentSKey)) - fmt.Printf("paymentExtended.skey=%s\n", bursa.GetKeyFile(w.PaymentExtendedSKey)) + fmt.Printf( + "paymentExtended.skey=%s\n", + bursa.GetKeyFile(w.PaymentExtendedSKey), + ) fmt.Printf("stake.vkey=%s\n", bursa.GetKeyFile(w.StakeVKey)) fmt.Printf("stake.skey=%s\n", bursa.GetKeyFile(w.StakeSKey)) - fmt.Printf("stakeExtended.skey=%s\n", bursa.GetKeyFile(w.StakeExtendedSKey)) + fmt.Printf( + "stakeExtended.skey=%s\n", + bursa.GetKeyFile(w.StakeExtendedSKey), + ) } else { fmt.Printf("Output dir: %v\n", output) _, err := os.Stat(output)