Debian Codegraph @

CLAUDE.md

raw symbols SCIP
1 CLAUDE.md
2 =========
3
4 This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
5
6 Commands
7 --------
8
9 ### Testing
10
11 ```bash
12 # Run all tests with race detection (requires MinIO server at localhost:9000)
13 SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minioadmin SECRET_KEY=minioadmin ENABLE_HTTPS=1 MINT_MODE=full go test -race -v ./...
14
15 # Run tests without race detection
16 go test ./...
17
18 # Run short tests only (no functional tests)
19 go test -short -race ./...
20
21 # Run functional tests
22 go build -race functional_tests.go
23 SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minioadmin SECRET_KEY=minioadmin ENABLE_HTTPS=1 MINT_MODE=full ./functional_tests
24
25 # Run functional tests without TLS
26 SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minioadmin SECRET_KEY=minioadmin ENABLE_HTTPS=0 MINT_MODE=full ./functional_tests
27 ```
28
29 ### Linting and Code Quality
30
31 ```bash
32 # Run all checks (lint, test, examples, functional tests)
33 make checks
34
35 # Run linter only (includes govet, staticcheck, and other linters)
36 make lint
37
38 # Run golangci-lint directly
39 golangci-lint run --timeout=5m --config ./.golangci.yml
40
41 # Note: 'make vet' is now an alias for 'make lint' for backwards compatibility
42 ```
43
44 ### Building Examples
45
46 ```bash
47 # Build all examples
48 make examples
49
50 # Build a specific example
51 cd examples/s3 && go build -mod=mod putobject.go
52 ```
53
54 Architecture
55 ------------
56
57 ### Core Client Structure
58
59 The MinIO Go SDK is organized around a central `Client` struct (api.go:52) that implements Amazon S3 compatible methods. Key architectural patterns:
60
61 1. **Modular API Organization**: API methods are split into logical files:
62
63 - `api-bucket-*.go`: Bucket operations (lifecycle, encryption, versioning, etc.)
64 - `api-object-*.go`: Object operations (legal hold, retention, tagging, etc.)
65 - `api-get-*.go`, `api-put-*.go`: GET and PUT operations
66 - `api-list.go`: Listing operations
67 - `api-stat.go`: Status/info operations
68
69 2. **Credential Management**: The `pkg/credentials/` package provides various credential providers:
70
71 - Static credentials
72 - Environment variables (AWS/MinIO)
73 - IAM roles
74 - STS (Security Token Service) variants
75 - File-based credentials
76 - Chain provider for fallback mechanisms
77
78 3. **Request Signing**: The `pkg/signer/` package handles AWS signature versions:
79
80 - V2 signatures (legacy)
81 - V4 signatures (standard)
82 - Streaming signatures for large uploads
83
84 4. **Transport Layer**: Custom HTTP transport with:
85
86 - Retry logic with configurable max retries
87 - Health status monitoring
88 - Tracing support via httptrace
89 - Bucket location caching (`bucketLocCache`\)
90 - Session caching for credentials
91
92 5. **Helper Packages**:
93
94 - `pkg/encrypt/`: Server-side encryption utilities
95 - `pkg/notification/`: Event notification handling
96 - `pkg/policy/`: Bucket policy management
97 - `pkg/lifecycle/`: Object lifecycle rules
98 - `pkg/tags/`: Object and bucket tagging
99 - `pkg/s3utils/`: S3 utility functions
100 - `pkg/kvcache/`: Key-value caching
101 - `pkg/singleflight/`: Deduplication of concurrent requests
102
103 ### Testing Strategy
104
105 - Unit tests alongside implementation files (`*_test.go`\)
106 - Comprehensive functional tests in `functional_tests.go` requiring a live MinIO server
107 - Example programs in `examples/` directory demonstrating API usage
108 - Build tag `//go:build mint` for integration tests
109
110 ### Error Handling
111
112 - Custom error types in `api-error-response.go`
113 - HTTP status code mapping
114 - Retry logic for transient failures
115 - Detailed error context preservation
116
117 Important Patterns
118 ------------------
119
120 1. **Context Usage**: All API methods accept `context.Context` for cancellation and timeout control
121 2. **Options Pattern**: Methods use Options structs for optional parameters (e.g., `PutObjectOptions`, `GetObjectOptions`\)
122 3. **Streaming Support**: Large file operations use io.Reader/Writer interfaces for memory efficiency
123 4. **Bucket Lookup Types**: Supports both path-style and virtual-host-style S3 URLs
124 5. **MD5/SHA256 Hashing**: Configurable hash functions for integrity checks via `md5Hasher` and `sha256Hasher`