AnCao/CLAUDE.md
2025-11-03 11:12:37 +08:00

2.2 KiB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

AnKao is a Go web application built using the standard library's net/http package. The project follows a clean architecture pattern with clear separation of concerns.

Architecture

Request Flow

  1. HTTP requests arrive at the server running on port 8080
  2. Requests pass through the Logger middleware (in internal/middleware/)
  3. The router (http.NewServeMux) directs requests to appropriate handlers
  4. Handlers (in internal/handlers/) process requests and return JSON responses

Middleware Pattern

Middleware functions wrap the main handler using the standard middleware pattern:

func Middleware(next http.Handler) http.Handler

Middleware is applied in cmd/server/main.go:20 before starting the server.

Module Structure

  • cmd/server/ - Application entry point, server configuration and routing setup
  • internal/handlers/ - HTTP request handlers, all return JSON responses
  • internal/middleware/ - HTTP middleware chain (currently: logging)
  • internal/models/ - Data models (directory exists but not yet populated)
  • pkg/config/ - Configuration management (directory exists but not yet populated)

Common Commands

Development

# Run the server
go run cmd/server/main.go

# Install/update dependencies
go mod tidy

# Format code
go fmt ./...

# Vet code for common issues
go vet ./...

Building

# Build binary to bin/server
go build -o bin/server cmd/server/main.go

# Run built binary (Windows)
.\bin\server.exe

# Run built binary (Unix)
./bin/server

Testing

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run tests in a specific package
go test ./internal/handlers/

Key Implementation Details

  • The server listens on port :8080 (hardcoded in main.go:23)
  • All responses are JSON with appropriate Content-Type headers
  • Import paths use the module name ankao (defined in go.mod)
  • When adding new handlers, register them in cmd/server/main.go using mux.HandleFunc()
  • Middleware wraps the entire mux, so it applies to all routes