Skip to content

Commit

Permalink
code cleanup for latest version of service patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
ardan-bkennedy committed Jan 22, 2024
1 parent 3f78400 commit bbcdcd9
Show file tree
Hide file tree
Showing 373 changed files with 84,725 additions and 18,581 deletions.
2 changes: 0 additions & 2 deletions app/cli/liars/board/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ const (

var words = []string{"", "one's", "two's", "three's", "four's", "five's", "six's"}

// =============================================================================

// Board represents the game board and all its state.
type Board struct {
accountID common.Address
Expand Down
2 changes: 0 additions & 2 deletions app/cli/liars/board/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ func (*Board) fmtAddress(address common.Address) string {
return fmt.Sprintf("%s..%s", address.Hex()[:5], address.Hex()[39:])
}

// =============================================================================

// drawGameBox draws the game box.
func (b *Board) drawGameBox(white bool) {
x := 1
Expand Down
4 changes: 1 addition & 3 deletions app/cli/liars/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,8 @@ func (e *Engine) Reconcile() (Status, error) {
return status, nil
}

// =============================================================================

// do makes the actual http call to the engine.
func (e Engine) do(url string, result interface{}, input []byte) error {
func (e *Engine) do(url string, result interface{}, input []byte) error {
var req *http.Request
var err error

Expand Down
10 changes: 5 additions & 5 deletions app/cli/liars/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {

func run() error {

// =========================================================================
// -------------------------------------------------------------------------
// Parse flags for settings.

flags, args, err := settings.Parse()
Expand All @@ -37,7 +37,7 @@ func run() error {
return nil
}

// =========================================================================
// -------------------------------------------------------------------------
// Establish a client connection to the game engine.

eng := engine.New(args.Engine)
Expand All @@ -46,7 +46,7 @@ func run() error {
return fmt.Errorf("connect to game engine: %w", err)
}

// =========================================================================
// -------------------------------------------------------------------------
// Create the board and initialize the display.

board, err := board.New(eng, token.Address)
Expand All @@ -55,7 +55,7 @@ func run() error {
}
defer board.Shutdown()

// =========================================================================
// -------------------------------------------------------------------------
// Establish a websocket connection to capture the game events.

teardown, err := eng.Events(board.Events)
Expand All @@ -64,7 +64,7 @@ func run() error {
}
defer teardown()

// =========================================================================
// -------------------------------------------------------------------------
// Start handling board input.

<-board.Run()
Expand Down
2 changes: 0 additions & 2 deletions app/cli/liars/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ func PrintUsage() {
fmt.Print(usage)
}

// =============================================================================

// Flags represents the flags that were provided.
type Flags map[string]struct{}

Expand Down
10 changes: 5 additions & 5 deletions app/services/engine/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
"time"

"github.com/ardanlabs/ethereum/currency"
"github.com/ardanlabs/liarsdice/app/services/engine/handlers/debug/checkgrp"
v1 "github.com/ardanlabs/liarsdice/app/services/engine/handlers/v1"
"github.com/ardanlabs/liarsdice/app/services/engine/handlers/v1/checkgrp"
"github.com/ardanlabs/liarsdice/business/core/bank"
"github.com/ardanlabs/liarsdice/business/web/auth"
"github.com/ardanlabs/liarsdice/business/web/v1/auth"
"github.com/ardanlabs/liarsdice/business/web/v1/mid"
"github.com/ardanlabs/liarsdice/foundation/events"
"github.com/ardanlabs/liarsdice/foundation/logger"
"github.com/ardanlabs/liarsdice/foundation/web"
"go.uber.org/zap"
)

// Options represent optional parameters.
Expand All @@ -35,7 +35,7 @@ func WithCORS(origin string) func(opts *Options) {
// APIMuxConfig contains all the mandatory systems required by handlers.
type APIMuxConfig struct {
Shutdown chan os.Signal
Log *zap.SugaredLogger
Log *logger.Logger
Auth *auth.Auth
Converter *currency.Converter
Bank *bank.Bank
Expand Down Expand Up @@ -124,7 +124,7 @@ func DebugStandardLibraryMux() *http.ServeMux {
// debug application routes for the service. This bypassing the use of the
// DefaultServerMux. Using the DefaultServerMux would be a security risk since
// a dependency could inject a handler into our service without us knowing it.
func DebugMux(build string, log *zap.SugaredLogger) http.Handler {
func DebugMux(build string, log *logger.Logger) http.Handler {
mux := DebugStandardLibraryMux()

// Register debug check endpoints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"net/http"
"os"

"go.uber.org/zap"
"github.com/ardanlabs/liarsdice/foundation/logger"
)

// Handlers manages the set of check endpoints.
type Handlers struct {
Build string
Log *zap.SugaredLogger
Log *logger.Logger
}

// Readiness checks if the database is ready and if not will return a 500 status.
Expand All @@ -29,10 +29,10 @@ func (h Handlers) Readiness(w http.ResponseWriter, r *http.Request) {
}

if err := response(w, statusCode, data); err != nil {
h.Log.Errorw("readiness", "ERROR", err)
h.Log.Error(r.Context(), "readiness", "ERROR", err)
}

h.Log.Infow("readiness", "statusCode", statusCode, "method", r.Method, "path", r.URL.Path, "remoteaddr", r.RemoteAddr)
h.Log.Info(r.Context(), "readiness", "statusCode", statusCode, "method", r.Method, "path", r.URL.Path, "remoteaddr", r.RemoteAddr)
}

// Liveness returns simple status info if the service is alive. If the
Expand Down Expand Up @@ -65,12 +65,12 @@ func (h Handlers) Liveness(w http.ResponseWriter, r *http.Request) {

statusCode := http.StatusOK
if err := response(w, statusCode, data); err != nil {
h.Log.Errorw("liveness", "ERROR", err)
h.Log.Error(r.Context(), "liveness", "ERROR", err)
}

// THIS IS A FREE TIMER. WE COULD UPDATE THE METRIC GOROUTINE COUNT HERE.

h.Log.Infow("liveness", "statusCode", statusCode, "method", r.Method, "path", r.URL.Path, "remoteaddr", r.RemoteAddr)
h.Log.Info(r.Context(), "liveness", "statusCode", statusCode, "method", r.Method, "path", r.URL.Path, "remoteaddr", r.RemoteAddr)
}

func response(w http.ResponseWriter, statusCode int, data any) error {
Expand Down
Loading

0 comments on commit bbcdcd9

Please sign in to comment.