Skip to content

Commit

Permalink
Split service into packages (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz authored Jun 17, 2024
1 parent 29e1845 commit d06b421
Show file tree
Hide file tree
Showing 111 changed files with 5,103 additions and 4,699 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: mkdir frontend/dist && touch frontend/dist/tmp && go test
run: mkdir frontend/dist && touch frontend/dist/tmp && go test ./...
- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v6
id: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/multiplatform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Run tests
run: mkdir frontend/dist && touch frontend/dist/tmp && go test
run: mkdir frontend/dist && touch frontend/dist/tmp && go test ./...
- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v6
id: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package-raspberry-pi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
GOARM: 6
CGO_ENABLED: 1
CC: ${{ github.workspace }}/armv6-unknown-linux-gnueabihf/bin/armv6-unknown-linux-gnueabihf-gcc
run: go build -tags skip_breez,netgo -v -o nostr-wallet-connect
run: go build -tags skip_breez,netgo -v -o nostr-wallet-connect cmd/http/main.go

- name: Find and copy shared libraries
run: |
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"editor.defaultFormatter": "golang.go"
},
"editor.formatOnSave": true,
"go.buildTags": "http,wails",
"typescript.preferences.importModuleSpecifier": "non-relative",
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ COPY . .
# Copy frontend dist files into the container
COPY --from=frontend /build/frontend/dist ./frontend/dist

RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build -o main .
RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build -o main cmd/http/main.go

RUN cp `find /go/pkg/mod/github.com/breez/ |grep linux-amd64 |grep libbreez_sdk_bindings.so` ./
RUN cp `find /go/pkg/mod/github.com/get\!alby/ | grep x86_64-unknown-linux-gnu | grep libglalby_bindings.so` ./
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ As data storage SQLite is used.
# edit the config for your needs
vim .env

#### Optional Requirements

See [Greenlight](./README_GREENLIGHT.md)

## Development

### Required Software
Expand All @@ -53,7 +49,7 @@ See [Greenlight](./README_GREENLIGHT.md)

2. Compile the frontend or run `touch frontend/dist/tmp` to ensure there are embeddable files available.

3. `go run .`
3. `go run cmd/http/main.go`

### React Frontend (HTTP mode)

Expand All @@ -77,7 +73,7 @@ _If you get a blank screen, try running in your normal terminal (outside of vsco
### Build and run locally (HTTP mode)

$ mkdir tmp
$ go build -o main
$ go build -o main cmd/http/main.go
$ cp main tmp
$ cp .env tmp
$ cd tmp
Expand All @@ -90,7 +86,11 @@ _If you get a blank screen, try running in your normal terminal (outside of vsco

### Testing

$ go test
$ go test ./...

#### Test matching regular expression

$ go test ./... -run TestHandleGetInfoEvent

### Profiling

Expand Down Expand Up @@ -363,8 +363,9 @@ LDK logs:
- install nvm (curl script)
- with nvm, choose node lts
- install yarn (via npm)
- then run yarn build
- go run .
- run `(cd frontend && yarn install`
- run `(cd frontend && yarn build:http)`
- run `go run cmd/http/main.go`

### Docker

Expand Down
17 changes: 0 additions & 17 deletions README_GREENLIGHT.md

This file was deleted.

16 changes: 7 additions & 9 deletions alby/alby_http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ import (
"net/http"

"github.com/getAlby/nostr-wallet-connect/config"
"github.com/getAlby/nostr-wallet-connect/logger"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)

type AlbyHttpService struct {
albyOAuthSvc AlbyOAuthService
logger *logrus.Logger
appConfig *config.AppConfig
}

func NewAlbyHttpService(albyOAuthSvc AlbyOAuthService, logger *logrus.Logger, appConfig *config.AppConfig) *AlbyHttpService {
func NewAlbyHttpService(albyOAuthSvc AlbyOAuthService, appConfig *config.AppConfig) *AlbyHttpService {
return &AlbyHttpService{
albyOAuthSvc: albyOAuthSvc,
logger: logger,
appConfig: appConfig,
}
}
Expand All @@ -36,7 +34,7 @@ func (albyHttpSvc *AlbyHttpService) albyCallbackHandler(c echo.Context) error {

err := albyHttpSvc.albyOAuthSvc.CallbackHandler(c.Request().Context(), code)
if err != nil {
albyHttpSvc.logger.WithError(err).Error("Failed to handle Alby OAuth callback")
logger.Logger.WithError(err).Error("Failed to handle Alby OAuth callback")
return c.JSON(http.StatusInternalServerError, ErrorResponse{
Message: fmt.Sprintf("Failed to handle Alby OAuth callback: %s", err.Error()),
})
Expand All @@ -59,7 +57,7 @@ func (albyHttpSvc *AlbyHttpService) albyCallbackHandler(c echo.Context) error {
func (albyHttpSvc *AlbyHttpService) albyMeHandler(c echo.Context) error {
me, err := albyHttpSvc.albyOAuthSvc.GetMe(c.Request().Context())
if err != nil {
albyHttpSvc.logger.WithError(err).Error("Failed to request alby me endpoint")
logger.Logger.WithError(err).Error("Failed to request alby me endpoint")
return c.JSON(http.StatusInternalServerError, ErrorResponse{
Message: fmt.Sprintf("Failed to request alby me endpoint: %s", err.Error()),
})
Expand All @@ -71,7 +69,7 @@ func (albyHttpSvc *AlbyHttpService) albyMeHandler(c echo.Context) error {
func (albyHttpSvc *AlbyHttpService) albyBalanceHandler(c echo.Context) error {
balance, err := albyHttpSvc.albyOAuthSvc.GetBalance(c.Request().Context())
if err != nil {
albyHttpSvc.logger.WithError(err).Error("Failed to request alby balance endpoint")
logger.Logger.WithError(err).Error("Failed to request alby balance endpoint")
return c.JSON(http.StatusInternalServerError, ErrorResponse{
Message: fmt.Sprintf("Failed to request alby balance endpoint: %s", err.Error()),
})
Expand All @@ -92,7 +90,7 @@ func (albyHttpSvc *AlbyHttpService) albyPayHandler(c echo.Context) error {

err := albyHttpSvc.albyOAuthSvc.SendPayment(c.Request().Context(), payRequest.Invoice)
if err != nil {
albyHttpSvc.logger.WithError(err).Error("Failed to request alby pay endpoint")
logger.Logger.WithError(err).Error("Failed to request alby pay endpoint")
return c.JSON(http.StatusInternalServerError, ErrorResponse{
Message: fmt.Sprintf("Failed to request alby pay endpoint: %s", err.Error()),
})
Expand All @@ -104,7 +102,7 @@ func (albyHttpSvc *AlbyHttpService) albyPayHandler(c echo.Context) error {
func (albyHttpSvc *AlbyHttpService) albyLinkAccountHandler(c echo.Context) error {
err := albyHttpSvc.albyOAuthSvc.LinkAccount(c.Request().Context())
if err != nil {
albyHttpSvc.logger.WithError(err).Error("Failed to connect alby account")
logger.Logger.WithError(err).Error("Failed to connect alby account")
return err
}

Expand Down
Loading

0 comments on commit d06b421

Please sign in to comment.