Skip to content

Commit 9eb1041

Browse files
committed
fix: Format Go code and add golangci-lint config
- Run gofmt on all Go files to fix formatting - Add .golangci.yml configuration file - Ensure all lint checks pass
1 parent 07ef850 commit 9eb1041

14 files changed

Lines changed: 81 additions & 62 deletions

File tree

.golangci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
linters:
2+
enable:
3+
- gofmt
4+
- govet
5+
- errcheck
6+
- staticcheck
7+
- gosimple
8+
- ineffassign
9+
- unused
10+
11+
linters-settings:
12+
errcheck:
13+
check-type-assertions: false
14+
check-blank: false
15+
16+
issues:
17+
exclude-dirs:
18+
- vendor
19+
- e2e
20+
exclude-files:
21+
- ".*\\.pb\\.go$"
22+
- ".*_test\\.go$"

cmd/server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ func setupRoutes(router *gin.Engine, h *handlers.Handlers) {
130130
api.GET("/reports/sales", h.APIReportsSales)
131131
api.GET("/reports/sales/excel", h.APIReportsSalesExcel)
132132
}
133-
}
133+
}

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ require (
77
github.com/google/uuid v1.5.0
88
github.com/joho/godotenv v1.5.1
99
github.com/mattn/go-sqlite3 v1.14.19
10-
github.com/stretchr/testify v1.8.3
1110
)
1211

1312
require (
1413
github.com/bytedance/sonic v1.9.1 // indirect
1514
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
16-
github.com/davecgh/go-spew v1.1.1 // indirect
1715
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
1816
github.com/gin-contrib/sse v0.1.0 // indirect
1917
github.com/go-playground/locales v0.14.1 // indirect
@@ -27,7 +25,6 @@ require (
2725
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2826
github.com/modern-go/reflect2 v1.0.2 // indirect
2927
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
30-
github.com/pmezard/go-difflib v1.0.0 // indirect
3128
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
3229
github.com/ugorji/go/codec v1.2.11 // indirect
3330
golang.org/x/arch v0.3.0 // indirect

internal/config/config.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ import (
55
)
66

77
type Config struct {
8-
DatabasePath string
9-
Port string
8+
DatabasePath string
9+
Port string
1010
ReceiptPrinterHost string
1111
ReceiptPrinterPort string
12-
QRCodeSize int
13-
AllowedIPPrefix string
14-
EncryptionKey string
12+
QRCodeSize int
13+
AllowedIPPrefix string
14+
EncryptionKey string
1515
}
1616

1717
func New() *Config {
1818
return &Config{
19-
DatabasePath: getEnv("DATABASE_PATH", "./kidspos.db"),
20-
Port: getEnv("PORT", "8080"),
19+
DatabasePath: getEnv("DATABASE_PATH", "./kidspos.db"),
20+
Port: getEnv("PORT", "8080"),
2121
ReceiptPrinterHost: getEnv("RECEIPT_PRINTER_HOST", "localhost"),
2222
ReceiptPrinterPort: getEnv("RECEIPT_PRINTER_PORT", "9100"),
23-
QRCodeSize: getEnvAsInt("QR_CODE_SIZE", 200),
24-
AllowedIPPrefix: getEnv("ALLOWED_IP_PREFIX", "192.168."),
25-
EncryptionKey: getEnv("ENCRYPTION_KEY", "DefaultKidsPOSKey123!@#"),
23+
QRCodeSize: getEnvAsInt("QR_CODE_SIZE", 200),
24+
AllowedIPPrefix: getEnv("ALLOWED_IP_PREFIX", "192.168."),
25+
EncryptionKey: getEnv("ENCRYPTION_KEY", "DefaultKidsPOSKey123!@#"),
2626
}
2727
}
2828

@@ -36,4 +36,4 @@ func getEnv(key, defaultValue string) string {
3636
func getEnvAsInt(key string, defaultValue int) int {
3737
// Simple implementation for now
3838
return defaultValue
39-
}
39+
}

internal/handlers/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,4 @@ func (h *Handlers) APIReportsSales(c *gin.Context) {
294294
func (h *Handlers) APIReportsSalesExcel(c *gin.Context) {
295295
// TODO: Implement Excel generation
296296
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented"})
297-
}
297+
}

internal/handlers/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,4 @@ func (h *Handlers) ReportsSales(c *gin.Context) {
377377
func atoi(s string) int {
378378
i, _ := strconv.Atoi(s)
379379
return i
380-
}
380+
}

internal/handlers/handlers_simple_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ func TestHandlers_Creation(t *testing.T) {
1010
if h == nil {
1111
t.Error("Failed to create handlers")
1212
}
13-
}
13+
}

internal/models/models.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,59 @@ import (
77

88
// Item represents a product item
99
type Item struct {
10-
ID int `json:"id" db:"id"`
11-
ItemID string `json:"itemId" db:"itemId"`
12-
Name string `json:"name" db:"name"`
13-
Price int `json:"price" db:"price"`
14-
Stock int `json:"stock" db:"stock"`
15-
IsDeleted bool `json:"isDeleted" db:"isDeleted"`
16-
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
17-
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
10+
ID int `json:"id" db:"id"`
11+
ItemID string `json:"itemId" db:"itemId"`
12+
Name string `json:"name" db:"name"`
13+
Price int `json:"price" db:"price"`
14+
Stock int `json:"stock" db:"stock"`
15+
IsDeleted bool `json:"isDeleted" db:"isDeleted"`
16+
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
17+
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
1818
}
1919

2020
// Store represents a store
2121
type Store struct {
22-
ID int `json:"id" db:"id"`
23-
StoreID string `json:"storeId" db:"storeId"`
24-
Name string `json:"name" db:"name"`
25-
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
26-
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
22+
ID int `json:"id" db:"id"`
23+
StoreID string `json:"storeId" db:"storeId"`
24+
Name string `json:"name" db:"name"`
25+
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
26+
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
2727
}
2828

2929
// Staff represents a staff member
3030
type Staff struct {
31-
ID int `json:"id" db:"id"`
32-
StaffID string `json:"staffId" db:"staffId"`
33-
Name string `json:"name" db:"name"`
34-
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
35-
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
31+
ID int `json:"id" db:"id"`
32+
StaffID string `json:"staffId" db:"staffId"`
33+
Name string `json:"name" db:"name"`
34+
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
35+
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
3636
}
3737

3838
// Sale represents a sale transaction
3939
type Sale struct {
40-
ID int `json:"id" db:"id"`
41-
StoreID int `json:"storeId" db:"storeId"`
42-
StaffID int `json:"staffId" db:"staffId"`
43-
TotalPrice int `json:"totalPrice" db:"totalPrice"`
44-
Deposit int `json:"deposit" db:"deposit"`
45-
SaleAt time.Time `json:"saleAt" db:"saleAt"`
46-
Details []SaleDetail `json:"details,omitempty"`
47-
Store *Store `json:"store,omitempty"`
48-
Staff *Staff `json:"staff,omitempty"`
49-
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
50-
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
40+
ID int `json:"id" db:"id"`
41+
StoreID int `json:"storeId" db:"storeId"`
42+
StaffID int `json:"staffId" db:"staffId"`
43+
TotalPrice int `json:"totalPrice" db:"totalPrice"`
44+
Deposit int `json:"deposit" db:"deposit"`
45+
SaleAt time.Time `json:"saleAt" db:"saleAt"`
46+
Details []SaleDetail `json:"details,omitempty"`
47+
Store *Store `json:"store,omitempty"`
48+
Staff *Staff `json:"staff,omitempty"`
49+
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
50+
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
5151
}
5252

5353
// SaleDetail represents a sale detail item
5454
type SaleDetail struct {
55-
ID int `json:"id" db:"id"`
56-
SaleID int `json:"saleId" db:"saleId"`
57-
ItemID int `json:"itemId" db:"itemId"`
58-
Quantity int `json:"quantity" db:"quantity"`
59-
Price int `json:"price" db:"price"`
60-
Item *Item `json:"item,omitempty"`
61-
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
62-
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
55+
ID int `json:"id" db:"id"`
56+
SaleID int `json:"saleId" db:"saleId"`
57+
ItemID int `json:"itemId" db:"itemId"`
58+
Quantity int `json:"quantity" db:"quantity"`
59+
Price int `json:"price" db:"price"`
60+
Item *Item `json:"item,omitempty"`
61+
CreatedAt time.Time `json:"createdAt" db:"createdAt"`
62+
UpdatedAt time.Time `json:"updatedAt" db:"updatedAt"`
6363
}
6464

6565
// Setting represents a configuration setting
@@ -103,4 +103,4 @@ func (nt NullTime) Value() (driver.Value, error) {
103103
return nil, nil
104104
}
105105
return nt.Time, nil
106-
}
106+
}

internal/models/models_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,4 @@ func BenchmarkNullTime_Value(b *testing.B) {
311311
for i := 0; i < b.N; i++ {
312312
_, _ = nt.Value()
313313
}
314-
}
314+
}

internal/repository/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,4 @@ func RunMigrations(db *sql.DB) error {
133133
}
134134

135135
return nil
136-
}
136+
}

0 commit comments

Comments
 (0)