Base Project

This commit is contained in:
Tran Anh Tuan
2026-05-08 14:32:24 +07:00
parent 5a9249c9ea
commit 6a4a96e0ca
74 changed files with 6749 additions and 0 deletions

42
configs/config.go Normal file
View File

@@ -0,0 +1,42 @@
package configs
import (
"log"
"os"
"wm-backend/configs/constants"
"wm-backend/internal/models"
"github.com/joho/godotenv"
"github.com/spf13/viper"
)
func LoadConfig(path string) (config models.Config, err error) {
// Load environment variables from .env file
err = godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file: %v", err)
}
viper.AddConfigPath(path)
env := os.Getenv("ENV")
if env == constants.ProdEnvironment {
viper.SetConfigName("yaml/config.prod")
} else {
viper.SetConfigName("yaml/config.dev")
}
viper.SetConfigType("yaml")
viper.AutomaticEnv()
// Read the configuration file
if err := viper.ReadInConfig(); err != nil {
return config, err
}
// Unmarshal the configuration into the config struct
if err := viper.Unmarshal(&config); err != nil {
return config, err
}
return config, nil
}

View File

@@ -0,0 +1,22 @@
package constants
const (
DevEnvironment = "dev"
ProdEnvironment = "prod"
)
const (
API_VERSION_1 = "/api/v1"
)
const (
API_GROUP_AUTH = "/auth"
API_GROUP_WAREHOUSE = "/warehouses"
)
const (
API_PATH_PING = "/ping"
API_PATH_DOCS = "/swagger/*any"
API_PATH_AUTH_REGISTER = "/register"
API_PATH_AUTH_LOGIN = "/login"
)

View File

@@ -0,0 +1,71 @@
package constants
// Permission định nghĩa toàn bộ quyền trong hệ thống
// Format: {module}:{action}
// Giá trị string phải KHỚP với seed data trong db/init/init.sql
const (
// ── Warehouse (Kho) ──
PermWarehouseCreate = "warehouse:create"
PermWarehouseRead = "warehouse:read"
PermWarehouseUpdate = "warehouse:update"
PermWarehouseDelete = "warehouse:delete"
// ── Room (Phòng) ──
PermRoomCreate = "room:create"
PermRoomRead = "room:read"
PermRoomUpdate = "room:update"
PermRoomDelete = "room:delete"
// ── Cabinet (Tủ) ──
PermCabinetCreate = "cabinet:create"
PermCabinetRead = "cabinet:read"
PermCabinetUpdate = "cabinet:update"
PermCabinetDelete = "cabinet:delete"
// ── Shelf (Kệ) ──
PermShelfCreate = "shelf:create"
PermShelfRead = "shelf:read"
PermShelfUpdate = "shelf:update"
PermShelfDelete = "shelf:delete"
// ── Container (Vật chứa) ──
PermContainerCreate = "container:create"
PermContainerRead = "container:read"
PermContainerUpdate = "container:update"
PermContainerDelete = "container:delete"
// ── Component Type (Loại linh kiện) ──
PermComponentTypeCreate = "component_type:create"
PermComponentTypeRead = "component_type:read"
PermComponentTypeUpdate = "component_type:update"
PermComponentTypeDelete = "component_type:delete"
// ── Component (Linh kiện) ──
PermComponentCreate = "component:create"
PermComponentRead = "component:read"
PermComponentUpdate = "component:update"
PermComponentDelete = "component:delete"
// ── Invoice (Hóa đơn) ──
PermInvoiceCreate = "invoice:create"
PermInvoiceRead = "invoice:read"
PermInvoiceUpdate = "invoice:update"
PermInvoiceDelete = "invoice:delete"
PermInvoiceApprove = "invoice:approve"
// ── Stock (Kho) ──
PermStockImport = "stock:import"
PermStockExport = "stock:export"
PermStockAdjust = "stock:adjust"
PermStockTransfer = "stock:transfer"
PermStockRead = "stock:read"
// ── User (Người dùng) ──
PermUserCreate = "user:create"
PermUserRead = "user:read"
PermUserUpdate = "user:update"
PermUserDelete = "user:delete"
// ── Role (Vai trò & quyền) ──
PermRoleManage = "role:manage"
)

View File

@@ -0,0 +1,28 @@
server:
host: "localhost"
port: 3000
portfrontend: "http://localhost:8000"
keypassword: ""
admin:
username:
email:
password:
fullname:
jwt:
secretkey:
expirehours:
database:
username:
password:
name:
host:
port:
cache:
username:
password:
host:
port: