Skip to content

Commit

Permalink
feat(api): switch to net/http
Browse files Browse the repository at this point in the history
Signed-off-by: Ales Verbic <[email protected]>
  • Loading branch information
verbotenj committed Jan 2, 2025
1 parent 69388d4 commit e6dd7a4
Show file tree
Hide file tree
Showing 8 changed files with 464 additions and 124 deletions.
23 changes: 17 additions & 6 deletions cmd/bursa/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
package main

import (
"context"
"os"
"os/signal"
"syscall"

"github.com/blinklabs-io/bursa/internal/api"
"github.com/blinklabs-io/bursa/internal/config"
Expand All @@ -29,17 +32,25 @@ func apiCommand() *cobra.Command {
Short: "Runs the api",
Run: func(cmd *cobra.Command, args []string) {
cfg := config.GetConfig()

// Create a context that can be canceled for graceful shutdown
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Handle interrupt signals for graceful shutdown
go func() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan
cancel()
}()

// Start API listener
logger := logging.GetLogger()
// Start API listener
logger.Info("starting API listener on", "address", cfg.Api.ListenAddress, "port", cfg.Api.ListenPort)
if err := api.Start(cfg); err != nil {
if err := api.Start(ctx, cfg, nil, nil); err != nil {
logger.Error("failed to start API:", "error", err)
os.Exit(1)
}

// Wait forever
select {}
},
}
return &apiCommand
Expand Down
8 changes: 7 additions & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const docTemplate = `{
"produces": [
"application/json"
],
"summary": "CreateWallet",
"summary": "Create a wallet",
"responses": {
"200": {
"description": "Ok",
Expand Down Expand Up @@ -119,6 +119,9 @@ const docTemplate = `{
"payment_address": {
"type": "string"
},
"payment_extended_skey": {
"$ref": "#/definitions/bursa.KeyFile"
},
"payment_kvey": {
"$ref": "#/definitions/bursa.KeyFile"
},
Expand All @@ -128,6 +131,9 @@ const docTemplate = `{
"stake_address": {
"type": "string"
},
"stake_extended_skey": {
"$ref": "#/definitions/bursa.KeyFile"
},
"stake_skey": {
"$ref": "#/definitions/bursa.KeyFile"
},
Expand Down
8 changes: 7 additions & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"produces": [
"application/json"
],
"summary": "CreateWallet",
"summary": "Create a wallet",
"responses": {
"200": {
"description": "Ok",
Expand Down Expand Up @@ -115,6 +115,9 @@
"payment_address": {
"type": "string"
},
"payment_extended_skey": {
"$ref": "#/definitions/bursa.KeyFile"
},
"payment_kvey": {
"$ref": "#/definitions/bursa.KeyFile"
},
Expand All @@ -124,6 +127,9 @@
"stake_address": {
"type": "string"
},
"stake_extended_skey": {
"$ref": "#/definitions/bursa.KeyFile"
},
"stake_skey": {
"$ref": "#/definitions/bursa.KeyFile"
},
Expand Down
6 changes: 5 additions & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ definitions:
type: string
payment_address:
type: string
payment_extended_skey:
$ref: '#/definitions/bursa.KeyFile'
payment_kvey:
$ref: '#/definitions/bursa.KeyFile'
payment_skey:
$ref: '#/definitions/bursa.KeyFile'
stake_address:
type: string
stake_extended_skey:
$ref: '#/definitions/bursa.KeyFile'
stake_skey:
$ref: '#/definitions/bursa.KeyFile'
stake_vkey:
Expand Down Expand Up @@ -55,7 +59,7 @@ paths:
description: Ok
schema:
$ref: '#/definitions/bursa.Wallet'
summary: CreateWallet
summary: Create a wallet
/api/wallet/restore:
post:
consumes:
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/spec v0.20.6 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
Expand All @@ -55,11 +56,14 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.10.0 // indirect
github.com/swaggo/http-swagger v1.3.4 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/x448/float16 v0.8.4 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUe
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs=
github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns=
github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZqewK7OKeyA=
github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo=
github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M=
github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I=
github.com/go-openapi/spec v0.20.6 h1:ich1RQ3WDbfoeTqTAb+5EIxNmpKVJZWBNah9RAT0jIQ=
github.com/go-openapi/spec v0.20.6/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
Expand Down Expand Up @@ -306,10 +310,14 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE=
github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg=
github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M=
github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo=
github.com/swaggo/http-swagger v1.3.4 h1:q7t/XLx0n15H1Q9/tk3Y9L4n210XzJF5WtnDX64a5ww=
github.com/swaggo/http-swagger v1.3.4/go.mod h1:9dAh0unqMBAlbp1uE2Uc2mQTxNMU/ha4UbucIg1MFkQ=
github.com/swaggo/swag v1.16.4 h1:clWJtd9LStiG3VeijiCfOVODP6VpHtKdQy9ELFG3s1A=
github.com/swaggo/swag v1.16.4/go.mod h1:VBsHJRsDvfYvqoiMKnsdwhNV9LEMHgEDZcyVYX0sxPg=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
Expand Down
Loading

0 comments on commit e6dd7a4

Please sign in to comment.