From 77ab717416828c5cc23b76f42fea27d5abe1d2eb Mon Sep 17 00:00:00 2001 From: William Kennedy Date: Wed, 20 Mar 2024 20:05:37 -0400 Subject: [PATCH] removed v1 folders --- app/services/engine/{v1 => }/build/all/all.go | 6 +- .../{v1 => }/handlers/checkgrp/checkgrp.go | 0 .../{v1 => }/handlers/checkgrp/route.go | 0 .../{v1 => }/handlers/gamegrp/events.go | 2 +- .../{v1 => }/handlers/gamegrp/gamegrp.go | 80 +++++++++---------- .../{v1 => }/handlers/gamegrp/models.go | 0 .../engine/{v1 => }/handlers/gamegrp/route.go | 4 +- app/services/engine/main.go | 8 +- business/data/dbtest/dbtest.go | 2 +- business/web/{v1 => }/auth/auth.go | 0 business/web/{v1 => }/auth/auth_test.go | 2 +- business/web/{v1 => }/auth/errors.go | 0 .../{v1 => }/auth/rego/authentication.rego | 0 business/web/{v1 => }/auth/rules.go | 0 business/web/{v1 => }/debug/debug.go | 0 business/web/{v1/v1.go => errs/errs.go} | 22 +---- business/web/{v1 => }/metrics/metrics.go | 0 business/web/{v1 => }/mid/auth.go | 2 +- business/web/{v1 => }/mid/cors.go | 0 business/web/{v1 => }/mid/errors.go | 18 ++--- business/web/{v1 => }/mid/logger.go | 0 business/web/{v1 => }/mid/metrics.go | 2 +- business/web/{v1 => }/mid/mid.go | 2 +- business/web/{v1 => }/mid/panics.go | 2 +- business/web/{v1 => }/mux/mux.go | 4 +- business/web/page/page.go | 20 +++++ 26 files changed, 89 insertions(+), 87 deletions(-) rename app/services/engine/{v1 => }/build/all/all.go (80%) rename app/services/engine/{v1 => }/handlers/checkgrp/checkgrp.go (100%) rename app/services/engine/{v1 => }/handlers/checkgrp/route.go (100%) rename app/services/engine/{v1 => }/handlers/gamegrp/events.go (98%) rename app/services/engine/{v1 => }/handlers/gamegrp/gamegrp.go (80%) rename app/services/engine/{v1 => }/handlers/gamegrp/models.go (100%) rename app/services/engine/{v1 => }/handlers/gamegrp/route.go (96%) rename business/web/{v1 => }/auth/auth.go (100%) rename business/web/{v1 => }/auth/auth_test.go (98%) rename business/web/{v1 => }/auth/errors.go (100%) rename business/web/{v1 => }/auth/rego/authentication.rego (100%) rename business/web/{v1 => }/auth/rules.go (100%) rename business/web/{v1 => }/debug/debug.go (100%) rename business/web/{v1/v1.go => errs/errs.go} (65%) rename business/web/{v1 => }/metrics/metrics.go (100%) rename business/web/{v1 => }/mid/auth.go (91%) rename business/web/{v1 => }/mid/cors.go (100%) rename business/web/{v1 => }/mid/errors.go (82%) rename business/web/{v1 => }/mid/logger.go (100%) rename business/web/{v1 => }/mid/metrics.go (90%) rename business/web/{v1 => }/mid/mid.go (92%) rename business/web/{v1 => }/mid/panics.go (92%) rename business/web/{v1 => }/mux/mux.go (93%) create mode 100644 business/web/page/page.go diff --git a/app/services/engine/v1/build/all/all.go b/app/services/engine/build/all/all.go similarity index 80% rename from app/services/engine/v1/build/all/all.go rename to app/services/engine/build/all/all.go index 313305cb..0bb62dec 100644 --- a/app/services/engine/v1/build/all/all.go +++ b/app/services/engine/build/all/all.go @@ -2,9 +2,9 @@ package all import ( - "github.com/ardanlabs/liarsdice/app/services/engine/v1/handlers/checkgrp" - "github.com/ardanlabs/liarsdice/app/services/engine/v1/handlers/gamegrp" - "github.com/ardanlabs/liarsdice/business/web/v1/mux" + "github.com/ardanlabs/liarsdice/app/services/engine/handlers/checkgrp" + "github.com/ardanlabs/liarsdice/app/services/engine/handlers/gamegrp" + "github.com/ardanlabs/liarsdice/business/web/mux" "github.com/ardanlabs/liarsdice/foundation/web" ) diff --git a/app/services/engine/v1/handlers/checkgrp/checkgrp.go b/app/services/engine/handlers/checkgrp/checkgrp.go similarity index 100% rename from app/services/engine/v1/handlers/checkgrp/checkgrp.go rename to app/services/engine/handlers/checkgrp/checkgrp.go diff --git a/app/services/engine/v1/handlers/checkgrp/route.go b/app/services/engine/handlers/checkgrp/route.go similarity index 100% rename from app/services/engine/v1/handlers/checkgrp/route.go rename to app/services/engine/handlers/checkgrp/route.go diff --git a/app/services/engine/v1/handlers/gamegrp/events.go b/app/services/engine/handlers/gamegrp/events.go similarity index 98% rename from app/services/engine/v1/handlers/gamegrp/events.go rename to app/services/engine/handlers/gamegrp/events.go index 14e2b5f0..84b62604 100644 --- a/app/services/engine/v1/handlers/gamegrp/events.go +++ b/app/services/engine/handlers/gamegrp/events.go @@ -6,7 +6,7 @@ import ( "fmt" "sync" - "github.com/ardanlabs/liarsdice/business/web/v1/mid" + "github.com/ardanlabs/liarsdice/business/web/mid" "github.com/google/uuid" ) diff --git a/app/services/engine/v1/handlers/gamegrp/gamegrp.go b/app/services/engine/handlers/gamegrp/gamegrp.go similarity index 80% rename from app/services/engine/v1/handlers/gamegrp/gamegrp.go rename to app/services/engine/handlers/gamegrp/gamegrp.go index 916078ca..05583dd1 100644 --- a/app/services/engine/v1/handlers/gamegrp/gamegrp.go +++ b/app/services/engine/handlers/gamegrp/gamegrp.go @@ -16,9 +16,9 @@ import ( "github.com/ardanlabs/ethereum/currency" "github.com/ardanlabs/liarsdice/business/core/bank" "github.com/ardanlabs/liarsdice/business/core/game" - v1 "github.com/ardanlabs/liarsdice/business/web/v1" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" - "github.com/ardanlabs/liarsdice/business/web/v1/mid" + "github.com/ardanlabs/liarsdice/business/web/auth" + "github.com/ardanlabs/liarsdice/business/web/errs" + "github.com/ardanlabs/liarsdice/business/web/mid" "github.com/ardanlabs/liarsdice/foundation/logger" "github.com/ardanlabs/liarsdice/foundation/web" "github.com/ethereum/go-ethereum/common" @@ -44,12 +44,12 @@ type handlers struct { func (h *handlers) connect(ctx context.Context, w http.ResponseWriter, r *http.Request) error { address, err := validateSignature(ctx, h.log, r, h.connectTimeout, h.bank.Client().ChainID()) if err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } token, err := generateToken(h.auth, h.activeKID, address) if err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } data := struct { @@ -182,7 +182,7 @@ func (h *handlers) configuration(ctx context.Context, w http.ResponseWriter, r * func (h *handlers) usd2Wei(ctx context.Context, w http.ResponseWriter, r *http.Request) error { usd, err := strconv.ParseFloat(web.Param(r, "usd"), 64) if err != nil { - return v1.NewTrustedError(fmt.Errorf("converting usd: %s", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("converting usd: %s", err), http.StatusBadRequest) } wei := h.converter.USD2Wei(big.NewFloat(usd)) @@ -215,7 +215,7 @@ func (h *handlers) state(ctx context.Context, w http.ResponseWriter, r *http.Req gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) @@ -235,13 +235,13 @@ func (h *handlers) state(ctx context.Context, w http.ResponseWriter, r *http.Req func (h *handlers) newGame(ctx context.Context, w http.ResponseWriter, r *http.Request) error { g, err := game.New(ctx, h.log, h.converter, h.storer, h.bank, mid.GetSubject(ctx), h.anteUSD) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to create game: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to create game: %w", err), http.StatusBadRequest) } subjectID := mid.GetSubject(ctx).String() if err := evts.addPlayerToGame(g.ID(), subjectID); err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to add player %q to game: %w", subjectID, err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to add player %q to game: %w", subjectID, err), http.StatusBadRequest) } web.SetParam(r, "id", g.ID().String()) @@ -253,12 +253,12 @@ func (h *handlers) newGame(ctx context.Context, w http.ResponseWriter, r *http.R func (h *handlers) join(ctx context.Context, w http.ResponseWriter, r *http.Request) error { gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) if err != nil { - return v1.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) } n, err := evts.numberOfPlayers(g.ID()) @@ -267,17 +267,17 @@ func (h *handlers) join(ctx context.Context, w http.ResponseWriter, r *http.Requ } if n == 5 { - return v1.NewTrustedError(errors.New("max players sitting"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("max players sitting"), http.StatusBadRequest) } subjectID := mid.GetSubject(ctx) if err := g.AddAccount(ctx, subjectID); err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } if err := evts.addPlayerToGame(g.ID(), subjectID.String()); err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to add player %q to game: %w", subjectID, err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to add player %q to game: %w", subjectID, err), http.StatusBadRequest) } evts.send(ctx, g.ID(), "join") @@ -289,16 +289,16 @@ func (h *handlers) join(ctx context.Context, w http.ResponseWriter, r *http.Requ func (h *handlers) startGame(ctx context.Context, w http.ResponseWriter, r *http.Request) error { gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) if err != nil { - return v1.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) } if err := g.StartGame(ctx); err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } evts.send(ctx, g.ID(), "start") @@ -310,16 +310,16 @@ func (h *handlers) startGame(ctx context.Context, w http.ResponseWriter, r *http func (h *handlers) rollDice(ctx context.Context, w http.ResponseWriter, r *http.Request) error { gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) if err != nil { - return v1.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) } if err := g.RollDice(ctx, mid.GetSubject(ctx)); err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } evts.send(ctx, g.ID(), "rolldice") @@ -331,28 +331,28 @@ func (h *handlers) rollDice(ctx context.Context, w http.ResponseWriter, r *http. func (h *handlers) bet(ctx context.Context, w http.ResponseWriter, r *http.Request) error { gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) if err != nil { - return v1.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) } number, err := strconv.Atoi(web.Param(r, "number")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("converting number: %s", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("converting number: %s", err), http.StatusBadRequest) } suit, err := strconv.Atoi(web.Param(r, "suit")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("converting suit: %s", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("converting suit: %s", err), http.StatusBadRequest) } address := mid.GetSubject(ctx) if err := g.Bet(ctx, address, number, suit); err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } evts.send(ctx, g.ID(), "bet", "index", g.State().Cups[address].OrderIdx) @@ -364,20 +364,20 @@ func (h *handlers) bet(ctx context.Context, w http.ResponseWriter, r *http.Reque func (h *handlers) callLiar(ctx context.Context, w http.ResponseWriter, r *http.Request) error { gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) if err != nil { - return v1.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) } if _, _, err := g.CallLiar(ctx, mid.GetSubject(ctx)); err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } if _, err := g.NextRound(ctx); err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } evts.send(ctx, g.ID(), "callliar") @@ -389,19 +389,19 @@ func (h *handlers) callLiar(ctx context.Context, w http.ResponseWriter, r *http. func (h *handlers) reconcile(ctx context.Context, w http.ResponseWriter, r *http.Request) error { gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) if err != nil { - return v1.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) } ctx, cancel := context.WithTimeout(ctx, h.bankTimeout) defer cancel() if _, _, err := g.Reconcile(ctx); err != nil { - return v1.NewTrustedError(err, http.StatusInternalServerError) + return errs.NewTrustedError(err, http.StatusInternalServerError) } evts.send(ctx, g.ID(), "reconcile") @@ -418,7 +418,7 @@ func (h *handlers) balance(ctx context.Context, w http.ResponseWriter, r *http.R balanceGWei, err := h.bank.AccountBalance(ctx, mid.GetSubject(ctx)) if err != nil { - return v1.NewTrustedError(err, http.StatusInternalServerError) + return errs.NewTrustedError(err, http.StatusInternalServerError) } resp := struct { @@ -434,16 +434,16 @@ func (h *handlers) balance(ctx context.Context, w http.ResponseWriter, r *http.R func (h *handlers) nextTurn(ctx context.Context, w http.ResponseWriter, r *http.Request) error { gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) if err != nil { - return v1.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) } if err := g.NextTurn(ctx); err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } evts.send(ctx, g.ID(), "nextturn") @@ -457,23 +457,23 @@ func (h *handlers) nextTurn(ctx context.Context, w http.ResponseWriter, r *http. func (h *handlers) updateOut(ctx context.Context, w http.ResponseWriter, r *http.Request) error { gameID, err := uuid.Parse(web.Param(r, "id")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("unable to parse game id: %w", err), http.StatusBadRequest) } g, err := game.Tables.Retrieve(gameID) if err != nil { - return v1.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) + return errs.NewTrustedError(errors.New("no game exists"), http.StatusBadRequest) } outs, err := strconv.Atoi(web.Param(r, "outs")) if err != nil { - return v1.NewTrustedError(fmt.Errorf("converting outs: %s", err), http.StatusBadRequest) + return errs.NewTrustedError(fmt.Errorf("converting outs: %s", err), http.StatusBadRequest) } address := mid.GetSubject(ctx) if err := g.ApplyOut(ctx, address, outs); err != nil { - return v1.NewTrustedError(err, http.StatusBadRequest) + return errs.NewTrustedError(err, http.StatusBadRequest) } evts.send(ctx, g.ID(), "outs") diff --git a/app/services/engine/v1/handlers/gamegrp/models.go b/app/services/engine/handlers/gamegrp/models.go similarity index 100% rename from app/services/engine/v1/handlers/gamegrp/models.go rename to app/services/engine/handlers/gamegrp/models.go diff --git a/app/services/engine/v1/handlers/gamegrp/route.go b/app/services/engine/handlers/gamegrp/route.go similarity index 96% rename from app/services/engine/v1/handlers/gamegrp/route.go rename to app/services/engine/handlers/gamegrp/route.go index ab46faa4..7577369f 100644 --- a/app/services/engine/v1/handlers/gamegrp/route.go +++ b/app/services/engine/handlers/gamegrp/route.go @@ -7,8 +7,8 @@ import ( "github.com/ardanlabs/ethereum/currency" "github.com/ardanlabs/liarsdice/business/core/bank" "github.com/ardanlabs/liarsdice/business/core/game/stores/gamedb" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" - "github.com/ardanlabs/liarsdice/business/web/v1/mid" + "github.com/ardanlabs/liarsdice/business/web/auth" + "github.com/ardanlabs/liarsdice/business/web/mid" "github.com/ardanlabs/liarsdice/foundation/logger" "github.com/ardanlabs/liarsdice/foundation/web" "github.com/gorilla/websocket" diff --git a/app/services/engine/main.go b/app/services/engine/main.go index 0ffdaada..07b83754 100644 --- a/app/services/engine/main.go +++ b/app/services/engine/main.go @@ -16,13 +16,13 @@ import ( "github.com/ardanlabs/conf/v3" "github.com/ardanlabs/ethereum" "github.com/ardanlabs/ethereum/currency" - "github.com/ardanlabs/liarsdice/app/services/engine/v1/build/all" + "github.com/ardanlabs/liarsdice/app/services/engine/build/all" scbank "github.com/ardanlabs/liarsdice/business/contract/go/bank" "github.com/ardanlabs/liarsdice/business/core/bank" "github.com/ardanlabs/liarsdice/business/data/sqldb" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" - "github.com/ardanlabs/liarsdice/business/web/v1/debug" - "github.com/ardanlabs/liarsdice/business/web/v1/mux" + "github.com/ardanlabs/liarsdice/business/web/auth" + "github.com/ardanlabs/liarsdice/business/web/debug" + "github.com/ardanlabs/liarsdice/business/web/mux" "github.com/ardanlabs/liarsdice/foundation/keystore" "github.com/ardanlabs/liarsdice/foundation/logger" "github.com/ardanlabs/liarsdice/foundation/web" diff --git a/business/data/dbtest/dbtest.go b/business/data/dbtest/dbtest.go index 2b88abd2..a889674e 100644 --- a/business/data/dbtest/dbtest.go +++ b/business/data/dbtest/dbtest.go @@ -11,7 +11,7 @@ import ( "github.com/ardanlabs/liarsdice/business/data/migrate" "github.com/ardanlabs/liarsdice/business/data/sqldb" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" + "github.com/ardanlabs/liarsdice/business/web/auth" "github.com/ardanlabs/liarsdice/foundation/docker" "github.com/ardanlabs/liarsdice/foundation/logger" "github.com/ardanlabs/liarsdice/foundation/web" diff --git a/business/web/v1/auth/auth.go b/business/web/auth/auth.go similarity index 100% rename from business/web/v1/auth/auth.go rename to business/web/auth/auth.go diff --git a/business/web/v1/auth/auth_test.go b/business/web/auth/auth_test.go similarity index 98% rename from business/web/v1/auth/auth_test.go rename to business/web/auth/auth_test.go index 68aaade4..20f591b9 100644 --- a/business/web/v1/auth/auth_test.go +++ b/business/web/auth/auth_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" + "github.com/ardanlabs/liarsdice/business/web/auth" "github.com/ardanlabs/liarsdice/foundation/logger" "github.com/golang-jwt/jwt/v4" "github.com/jmoiron/sqlx" diff --git a/business/web/v1/auth/errors.go b/business/web/auth/errors.go similarity index 100% rename from business/web/v1/auth/errors.go rename to business/web/auth/errors.go diff --git a/business/web/v1/auth/rego/authentication.rego b/business/web/auth/rego/authentication.rego similarity index 100% rename from business/web/v1/auth/rego/authentication.rego rename to business/web/auth/rego/authentication.rego diff --git a/business/web/v1/auth/rules.go b/business/web/auth/rules.go similarity index 100% rename from business/web/v1/auth/rules.go rename to business/web/auth/rules.go diff --git a/business/web/v1/debug/debug.go b/business/web/debug/debug.go similarity index 100% rename from business/web/v1/debug/debug.go rename to business/web/debug/debug.go diff --git a/business/web/v1/v1.go b/business/web/errs/errs.go similarity index 65% rename from business/web/v1/v1.go rename to business/web/errs/errs.go index 490aa43a..8a23067c 100644 --- a/business/web/v1/v1.go +++ b/business/web/errs/errs.go @@ -1,5 +1,5 @@ -// Package v1 provides types and support related to web v1 functionality. -package v1 +// Package errs provides types and support related to web v1 functionality. +package errs import "errors" @@ -42,21 +42,3 @@ func GetTrustedError(err error) *TrustedError { } return te } - -// PageDocument is the form used for API responses from query API calls. -type PageDocument[T any] struct { - Items []T `json:"items"` - Total int `json:"total"` - Page int `json:"page"` - RowsPerPage int `json:"rowsPerPage"` -} - -// NewPageDocument constructs a response value for a web paging trusted. -func NewPageDocument[T any](items []T, total int, page int, rowsPerPage int) PageDocument[T] { - return PageDocument[T]{ - Items: items, - Total: total, - Page: page, - RowsPerPage: rowsPerPage, - } -} diff --git a/business/web/v1/metrics/metrics.go b/business/web/metrics/metrics.go similarity index 100% rename from business/web/v1/metrics/metrics.go rename to business/web/metrics/metrics.go diff --git a/business/web/v1/mid/auth.go b/business/web/mid/auth.go similarity index 91% rename from business/web/v1/mid/auth.go rename to business/web/mid/auth.go index 31e43a3b..f3ec487d 100644 --- a/business/web/v1/mid/auth.go +++ b/business/web/mid/auth.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" + "github.com/ardanlabs/liarsdice/business/web/auth" "github.com/ardanlabs/liarsdice/foundation/web" ) diff --git a/business/web/v1/mid/cors.go b/business/web/mid/cors.go similarity index 100% rename from business/web/v1/mid/cors.go rename to business/web/mid/cors.go diff --git a/business/web/v1/mid/errors.go b/business/web/mid/errors.go similarity index 82% rename from business/web/v1/mid/errors.go rename to business/web/mid/errors.go index 4af6e671..41a0d187 100644 --- a/business/web/v1/mid/errors.go +++ b/business/web/mid/errors.go @@ -4,8 +4,8 @@ import ( "context" "net/http" - v1 "github.com/ardanlabs/liarsdice/business/web/v1" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" + "github.com/ardanlabs/liarsdice/business/web/auth" + "github.com/ardanlabs/liarsdice/business/web/errs" "github.com/ardanlabs/liarsdice/foundation/logger" "github.com/ardanlabs/liarsdice/foundation/validate" "github.com/ardanlabs/liarsdice/foundation/web" @@ -20,16 +20,16 @@ func Errors(log *logger.Logger) web.MidHandler { if err := handler(ctx, w, r); err != nil { log.Error(ctx, "message", "msg", err) - var er v1.ErrorResponse + var er errs.ErrorResponse var status int switch { - case v1.IsTrustedError(err): - trsErr := v1.GetTrustedError(err) + case errs.IsTrustedError(err): + trsErr := errs.GetTrustedError(err) if validate.IsFieldErrors(trsErr.Err) { fieldErrors := validate.GetFieldErrors(trsErr.Err) - er = v1.ErrorResponse{ + er = errs.ErrorResponse{ Error: "data validation error", Fields: fieldErrors.Fields(), } @@ -37,19 +37,19 @@ func Errors(log *logger.Logger) web.MidHandler { break } - er = v1.ErrorResponse{ + er = errs.ErrorResponse{ Error: trsErr.Error(), } status = trsErr.Status case auth.IsAuthError(err): - er = v1.ErrorResponse{ + er = errs.ErrorResponse{ Error: http.StatusText(http.StatusUnauthorized), } status = http.StatusUnauthorized default: - er = v1.ErrorResponse{ + er = errs.ErrorResponse{ Error: http.StatusText(http.StatusInternalServerError), } status = http.StatusInternalServerError diff --git a/business/web/v1/mid/logger.go b/business/web/mid/logger.go similarity index 100% rename from business/web/v1/mid/logger.go rename to business/web/mid/logger.go diff --git a/business/web/v1/mid/metrics.go b/business/web/mid/metrics.go similarity index 90% rename from business/web/v1/mid/metrics.go rename to business/web/mid/metrics.go index 05434b79..075fd1a4 100644 --- a/business/web/v1/mid/metrics.go +++ b/business/web/mid/metrics.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/ardanlabs/liarsdice/business/web/v1/metrics" + "github.com/ardanlabs/liarsdice/business/web/metrics" "github.com/ardanlabs/liarsdice/foundation/web" ) diff --git a/business/web/v1/mid/mid.go b/business/web/mid/mid.go similarity index 92% rename from business/web/v1/mid/mid.go rename to business/web/mid/mid.go index 8fb29a44..dca3d341 100644 --- a/business/web/v1/mid/mid.go +++ b/business/web/mid/mid.go @@ -4,7 +4,7 @@ package mid import ( "context" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" + "github.com/ardanlabs/liarsdice/business/web/auth" "github.com/ethereum/go-ethereum/common" ) diff --git a/business/web/v1/mid/panics.go b/business/web/mid/panics.go similarity index 92% rename from business/web/v1/mid/panics.go rename to business/web/mid/panics.go index acccaa8f..54545b2e 100644 --- a/business/web/v1/mid/panics.go +++ b/business/web/mid/panics.go @@ -6,7 +6,7 @@ import ( "net/http" "runtime/debug" - "github.com/ardanlabs/liarsdice/business/web/v1/metrics" + "github.com/ardanlabs/liarsdice/business/web/metrics" "github.com/ardanlabs/liarsdice/foundation/web" ) diff --git a/business/web/v1/mux/mux.go b/business/web/mux/mux.go similarity index 93% rename from business/web/v1/mux/mux.go rename to business/web/mux/mux.go index c5ad3865..ffc4ebf9 100644 --- a/business/web/v1/mux/mux.go +++ b/business/web/mux/mux.go @@ -9,8 +9,8 @@ import ( "github.com/ardanlabs/ethereum/currency" "github.com/ardanlabs/liarsdice/business/core/bank" - "github.com/ardanlabs/liarsdice/business/web/v1/auth" - "github.com/ardanlabs/liarsdice/business/web/v1/mid" + "github.com/ardanlabs/liarsdice/business/web/auth" + "github.com/ardanlabs/liarsdice/business/web/mid" "github.com/ardanlabs/liarsdice/foundation/logger" "github.com/ardanlabs/liarsdice/foundation/web" "github.com/jmoiron/sqlx" diff --git a/business/web/page/page.go b/business/web/page/page.go new file mode 100644 index 00000000..52087c15 --- /dev/null +++ b/business/web/page/page.go @@ -0,0 +1,20 @@ +// Package page provides query paging support. +package page + +// Document is the form used for API responses from query API calls. +type Document[T any] struct { + Items []T `json:"items"` + Total int `json:"total"` + Page int `json:"page"` + RowsPerPage int `json:"rowsPerPage"` +} + +// NewDocument constructs a response value for a web paging trusted. +func NewDocument[T any](items []T, total int, page int, rowsPerPage int) Document[T] { + return Document[T]{ + Items: items, + Total: total, + Page: page, + RowsPerPage: rowsPerPage, + } +}