Skip to content

Commit

Permalink
build: add gofmt to format make target (#118)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 authored Dec 20, 2024
1 parent b505ae2 commit c14bf38
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 24 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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,.
Expand Down
3 changes: 2 additions & 1 deletion cmd/bursa/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 7 additions & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
48 changes: 29 additions & 19 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,39 @@ 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
requestBody, _ := json.Marshal(WalletRestoreRequest{
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)
}
Expand All @@ -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,
)
}
})

Expand Down
10 changes: 8 additions & 2 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c14bf38

Please sign in to comment.