Skip to content

Commit

Permalink
chore: make format golines swagger (#123)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored Jan 15, 2025
1 parent d0adbcf commit 9caf747
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
20 changes: 15 additions & 5 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ type WalletRestoreRequest struct {
// @contact.url https://blinklabs.io
// @contact.email support@blinklabs.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// Define Prometheus metrics
var (
Expand All @@ -86,7 +86,11 @@ func init() {

// Start initializes and starts the HTTP servers for the API and metrics
// Listeners can be passed in for testing purposes to provide ephermeral ports
func Start(ctx context.Context, cfg *config.Config, apiListener, metricsListener net.Listener) error {
func Start(
ctx context.Context,
cfg *config.Config,
apiListener, metricsListener net.Listener,
) error {
logger := logging.GetLogger()
accessLogger := logging.GetAccessLogger()

Expand Down Expand Up @@ -125,7 +129,11 @@ func Start(ctx context.Context, cfg *config.Config, apiListener, metricsListener
var err error
if metricsListener == nil {
err = http.ListenAndServe(
fmt.Sprintf("%s:%d", cfg.Metrics.ListenAddress, cfg.Metrics.ListenPort),
fmt.Sprintf(
"%s:%d",
cfg.Metrics.ListenAddress,
cfg.Metrics.ListenPort,
),
metricsMux,
)
} else {
Expand Down Expand Up @@ -232,7 +240,9 @@ func handleWalletCreate(w http.ResponseWriter, r *http.Request) {
if err != nil {
logger.Error("failed to initialize wallet", "error", err)
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(fmt.Sprintf("failed to initialize wallet: %s", err)))
_, _ = w.Write(
[]byte(fmt.Sprintf("failed to initialize wallet: %s", err)),
)
// Increment fail counter
walletsFailCounter.Inc()
return
Expand Down
20 changes: 15 additions & 5 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ var mockWalletResponseJSON = `{
}
}`

func startAPI(t *testing.T) (apiBaseURL, metricsBaseURL string, cleanup func()) {
func startAPI(
t *testing.T,
) (apiBaseURL, metricsBaseURL string, cleanup func()) {
t.Helper()

// Create listeners for API and metrics with ephemeral ports
Expand Down Expand Up @@ -292,7 +294,9 @@ func TestWalletCreateIncrementsCounter(t *testing.T) {
"Expected `bursa_wallets_created_count` to be registered initially")

// Call /api/wallet/create to create a wallet
createWalletResp, err := http.Get(fmt.Sprintf("%s/api/wallet/create", apiBaseURL))
createWalletResp, err := http.Get(
fmt.Sprintf("%s/api/wallet/create", apiBaseURL),
)
assert.NoError(t, err, "failed to call /api/wallet/create endpoint")
assert.Equal(t, http.StatusOK, createWalletResp.StatusCode,
"expected /api/wallet/create to return 200 on success")
Expand All @@ -311,8 +315,12 @@ func TestWalletCreateIncrementsCounter(t *testing.T) {

// Verify that the counter incremented by 1
expected := initialCount + 1
assert.Equal(t, expected, newCount,
"bursa_wallets_created_count should have incremented by 1 after creating a wallet")
assert.Equal(
t,
expected,
newCount,
"bursa_wallets_created_count should have incremented by 1 after creating a wallet",
)
}

func TestCreateWalletReturnsMnemonic(t *testing.T) {
Expand Down Expand Up @@ -341,7 +349,9 @@ func TestCreateWalletReturnsMnemonic(t *testing.T) {

mnemonicVal, ok := createWalletResponse["mnemonic"]
if !ok {
t.Errorf("Expected key 'mnemonic' in createWalletResponse, but it was missing")
t.Errorf(
"Expected key 'mnemonic' in createWalletResponse, but it was missing",
)
} else {
mnemonicStr, isString := mnemonicVal.(string)
if !isString || mnemonicStr == "" {
Expand Down

0 comments on commit 9caf747

Please sign in to comment.