# chain-mark **Repository Path**: QiyanLiu/chain-mark ## Basic Information - **Project Name**: chain-mark - **Description**: Designed specifically for Java developers who are transitioning to Go. It implements a complete backend system for a "Daily Check-in" application, demonstrating how to build a service using Go - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-20 - **Last Updated**: 2026-05-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: Gin, gorm, Go语言 ## README # Chain-Mark: Go Learning Project for Java Developers ## Introduction Welcome! This project is designed specifically for **Java developers** who are transitioning to **Go (Golang)**. It implements a complete backend system for a "Daily Check-in" application, demonstrating how to build a production-ready web service using the Go ecosystem. The project uses the most popular "Spring Boot equivalent" stack in Go: - **Web Framework**: [Gin](https://github.com/gin-gonic/gin) (Fast, HTTP web framework) - **ORM**: [GORM](https://gorm.io/) (The fantastic ORM library for Golang) - **Database**: MySQL + Redis - **Authentication**: JWT-based stateless authentication ## Purpose & Learning Goals The main goal is to map Java concepts to Go implementations: - **Controller/Service/DAO Layers** -> Handlers / Services / Repositories - **Dependency Injection (DI)** -> Manual wiring (No "Magic" Annotations like `@Autowired`) - **Entities & DTOs** -> Structs in `domain/model` - **Exception Handling** -> Go Error Handling & Custom Middleware ## Directory Structure A clean, standard Go project layout (following `golang-standards/project-layout`): ```text . ├── api/ # [Controller Layer] HTTP Handlers (User, Checkin, Point) ├── router/ # [Configuration] Route definitions & Middleware setup ├── internal/ # Private application code │ ├── bootstrap/ # [DI Container] Application initialization & wiring │ ├── domain/ # [Domain Layer] Interfaces & Models │ │ ├── model/ # Data structures │ │ │ ├── entity/ # DB Entities (mapped to tables) │ │ │ └── pojo/ # DTOs (Request/Response objects) │ │ └── repository/ # Repository Interfaces │ ├── service/ # [Service Layer] Business logic interfaces & implementations │ └── infrastructure/ # [Infra Layer] Implementation details │ ├── config/ # Configuration loading │ └── persistence/# GORM Repository implementations & Transaction Manager ├── pkg/ # Public library code (Utils) │ ├── jwt/ # JWT Token handling │ └── response/ # Standard API Response wrapper ├── task/ # Background tasks (Cron jobs) └── main.go # Entry point ``` ## Architecture & Design Patterns ### 1. Layered Architecture (MVC-like) Just like in Spring, we strictly separate concerns: - **API Layer (`api/`)**: Handles HTTP requests, parses parameters (DTOs), and calls services. - **Service Layer (`internal/service/`)**: Contains business logic. - **Repository Layer (`internal/infrastructure/persistence/`)**: Handles database operations using GORM. ### 2. Dependency Injection (DI) Unlike Spring's runtime reflection-based DI, Go prefers **explicit dependency injection**. - Check `internal/bootstrap/app.go`. - You will see how we manually create Repositories, inject them into Services, and inject Services into Handlers. - **Benefit**: Compilation-time safety and no "magic". ### 3. Singleton Pattern All Services and Repositories are initialized as **Singletons** during the application startup (`bootstrap`) and shared across requests. ### 4. Transaction Management We implement a custom `TransactionManager` in `infrastructure/persistence` to handle transactions across the service layer, similar to `@Transactional` but explicit. ## API Summary The project provides RESTful APIs organized by functional modules. ### User Module - **Register**: `POST /api/v1/user/register` - Create a new account. - **Login**: `POST /api/v1/user/login` - Authenticate and get JWT token. - **Refresh Token**: `POST /api/v1/user/refresh` - Refresh expired access token. - **Get Profile**: `GET /api/v1/user/get` - Retrieve current user information. ### Check-in Module - **Daily Check-in**: `POST /api/v1/checkin/do` - Check in for today. - **Retroactive**: `POST /api/v1/checkin/retroactive` - Make up for a missed day (uses points). - **Calendar**: `GET /api/v1/checkin/calendar` - Get check-in status for a specific month. ### Point Module - **Summary**: `GET /api/v1/point/summary` - View total available points. - **History**: `GET /api/v1/point/records` - View point change history (earned/consumed). ## Getting Started 1. **Clone the repo** 2. **Configure Database**: Update `config.yaml` (or similar) with your MySQL credentials. 3. **Run the Application**: ```bash go run main.go ``` 4. **Test**: Use Postman or curl to hit `http://localhost:8080`. --- *Happy Coding! Enjoy your journey from Java to Go!*