Skip to content

Commit

Permalink
perf: gopls help me optimize structs
Browse files Browse the repository at this point in the history
Reordering punsh of structs' fields and deleting unnecessary handler.go
  • Loading branch information
kareemmahlees committed Jun 27, 2024
1 parent a901038 commit f621bea
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 74 deletions.
2 changes: 1 addition & 1 deletion internal/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func TestInitDBConn(t *testing.T) {
malformedConnUrl := "postgres://malformed"
cfg = utils.NewPGConfig(&malformedConnUrl, nil)

conn, err = InitDBConn(lib.PSQL, cfg)
_, err = InitDBConn(lib.PSQL, cfg)
assert.Error(t, err)
}
2 changes: 1 addition & 1 deletion internal/handlers/defaultHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func (h *DefaultHandler) healthCheck(w http.ResponseWriter, r *http.Request) {

type APIInfoResult struct {
Author string `json:"author"`
Year int `json:"yeaer"`
Contact string `json:"contact"`
Repo string `json:"repo"`
Year int `json:"yeaer"`
}

// Get info about the api
Expand Down
4 changes: 2 additions & 2 deletions internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (

type Server struct {
storage db.Storage
port int
router *chi.Mux
listenCh chan bool
port int
}

func NewServer(storage db.Storage, port int, listenCh chan bool) *Server {
r := chi.NewRouter()
return &Server{storage, port, r, listenCh}
return &Server{storage, r, listenCh, port}
}

func (s *Server) Serve() error {
Expand Down
4 changes: 2 additions & 2 deletions lib/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
)

type ErrorResponse struct {
Error bool `json:"error"`
Value interface{} `json:"value"`
FailedField string `json:"failed_field"`
Tag string `json:"tag"`
Value interface{} `json:"value"`
Error bool `json:"error"`
}

var validate *validator.Validate
Expand Down
2 changes: 1 addition & 1 deletion models/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ type SuccessResp struct {
}

type ErrResp struct {
Code int `json:"code"`
Message any `json:"message"`
Code int `json:"code"`
}
8 changes: 4 additions & 4 deletions models/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ type ListTablesResp struct {
}

type TableInfoResp struct {
Key any `db:"key" json:"key"`
Default any `db:"default" json:"default"`
Name string `db:"name" json:"name"`
Type string `db:"type" json:"type"`
Nullable string `db:"nullable" json:"nullable"`
Key any `db:"key" json:"key"`
Default any `db:"default" json:"default"`
}

type CreateTablePayload struct {
ColName string `json:"column_name" validate:"required,alphanum"`
Type string `json:"type" validate:"required,ascii"`
Nullable interface{} `json:"nullable" validate:"omitempty,boolean"`
Default interface{} `json:"default" validate:"omitempty,alphanum" `
Unique interface{} `json:"unique" validate:"omitempty,boolean"`
ColName string `json:"column_name" validate:"required,alphanum"`
Type string `json:"type" validate:"required,ascii"`
}

type CreateTableResp struct {
Expand Down
25 changes: 0 additions & 25 deletions utils/handlers.go

This file was deleted.

38 changes: 0 additions & 38 deletions utils/handlers_test.go

This file was deleted.

0 comments on commit f621bea

Please sign in to comment.