|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Gorush is a push notification microserver written in Go that supports sending notifications to iOS (APNS), Android (FCM), and Huawei (HMS) devices. It provides both HTTP REST API and gRPC interfaces for sending push notifications. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +### Core Components |
| 12 | + |
| 13 | +- **main.go**: Entry point that handles CLI flags, configuration loading, and server initialization |
| 14 | +- **config/**: Configuration management with YAML support and environment variable overrides |
| 15 | +- **core/**: Core abstractions for queue, storage, and health check interfaces |
| 16 | +- **notify/**: Push notification implementations for different platforms (APNS, FCM, HMS) |
| 17 | +- **router/**: HTTP server setup using Gin framework with REST endpoints |
| 18 | +- **rpc/**: gRPC server implementation with protocol buffer definitions |
| 19 | +- **status/**: Application statistics and metrics collection |
| 20 | +- **storage/**: Multiple storage backends (memory, Redis, BoltDB, BuntDB, LevelDB, BadgerDB) |
| 21 | +- **logx/**: Logging utilities and interfaces |
| 22 | + |
| 23 | +### Key Features |
| 24 | + |
| 25 | +- Multi-platform support (iOS APNS, Android FCM, Huawei HMS) |
| 26 | +- Multiple queue engines (local channels, NSQ, NATS, Redis streams) |
| 27 | +- Configurable storage backends for statistics |
| 28 | +- Prometheus metrics support |
| 29 | +- gRPC and REST API interfaces |
| 30 | +- Docker and Kubernetes deployment support |
| 31 | +- AWS Lambda support |
| 32 | + |
| 33 | +## Development Commands |
| 34 | + |
| 35 | +### Building |
| 36 | + |
| 37 | +```bash |
| 38 | +# Build for current platform |
| 39 | +make build |
| 40 | + |
| 41 | +# Build for specific platforms |
| 42 | +make build_linux_amd64 |
| 43 | +make build_darwin_arm64 |
| 44 | +make build_linux_lambda |
| 45 | + |
| 46 | +# Install locally |
| 47 | +make install |
| 48 | +``` |
| 49 | + |
| 50 | +### Testing |
| 51 | + |
| 52 | +```bash |
| 53 | +# Run tests (requires FCM_CREDENTIAL and FCM_TEST_TOKEN environment variables) |
| 54 | +make test |
| 55 | + |
| 56 | +# Check required environment variables first |
| 57 | +make init |
| 58 | +``` |
| 59 | + |
| 60 | +### Development Tools |
| 61 | + |
| 62 | +```bash |
| 63 | +# Run with hot reload |
| 64 | +make dev |
| 65 | + |
| 66 | +# Clean build artifacts |
| 67 | +make clean |
| 68 | + |
| 69 | +# Check available commands |
| 70 | +make help |
| 71 | +``` |
| 72 | + |
| 73 | +### Linting and Code Quality |
| 74 | + |
| 75 | +```bash |
| 76 | +# The project uses golangci-lint with configuration in .golangci.yml |
| 77 | +# Run linting (if golangci-lint is installed): |
| 78 | +golangci-lint run |
| 79 | + |
| 80 | +# Supported linters include: bodyclose, errcheck, gosec, govet, staticcheck, etc. |
| 81 | +# Formatters: gofmt, gofumpt, goimports |
| 82 | +``` |
| 83 | + |
| 84 | +### Protocol Buffers |
| 85 | + |
| 86 | +```bash |
| 87 | +# Install protoc dependencies |
| 88 | +make proto_install |
| 89 | + |
| 90 | +# Generate Go protobuf files |
| 91 | +make generate_proto_go |
| 92 | + |
| 93 | +# Generate JavaScript protobuf files |
| 94 | +make generate_proto_js |
| 95 | + |
| 96 | +# Generate all protobuf files |
| 97 | +make generate_proto |
| 98 | +``` |
| 99 | + |
| 100 | +## Configuration |
| 101 | + |
| 102 | +The application uses YAML configuration files. See `config/testdata/config.yml` for the complete configuration example. |
| 103 | + |
| 104 | +Key configuration sections: |
| 105 | + |
| 106 | +- **core**: Server settings, workers, queue configuration |
| 107 | +- **grpc**: gRPC server settings |
| 108 | +- **android**: Firebase Cloud Messaging settings |
| 109 | +- **ios**: Apple Push Notification settings |
| 110 | +- **huawei**: Huawei Mobile Services settings |
| 111 | +- **queue**: Queue engine configuration (local/nsq/nats/redis) |
| 112 | +- **stat**: Statistics storage backend configuration |
| 113 | +- **log**: Logging configuration |
| 114 | + |
| 115 | +## Running the Server |
| 116 | + |
| 117 | +### Basic Usage |
| 118 | + |
| 119 | +```bash |
| 120 | +# Use default config |
| 121 | +./gorush |
| 122 | + |
| 123 | +# Use custom config file |
| 124 | +./gorush -c config.yml |
| 125 | + |
| 126 | +# CLI notification examples |
| 127 | +./gorush -android -m "Hello World" --fcm-key /path/to/key.json -t "device_token" |
| 128 | +./gorush -ios -m "Hello World" -i /path/to/cert.pem -t "device_token" |
| 129 | +``` |
| 130 | + |
| 131 | +### Docker |
| 132 | + |
| 133 | +```bash |
| 134 | +docker run --name gorush -p 80:8088 appleboy/gorush |
| 135 | +``` |
| 136 | + |
| 137 | +## API Endpoints |
| 138 | + |
| 139 | +### REST API |
| 140 | + |
| 141 | +- `GET /api/stat/go` - Go runtime statistics |
| 142 | +- `GET /api/stat/app` - Application push statistics |
| 143 | +- `GET /api/config` - Current configuration |
| 144 | +- `POST /api/push` - Send push notifications |
| 145 | +- `GET /metrics` - Prometheus metrics |
| 146 | +- `GET /healthz` - Health check |
| 147 | + |
| 148 | +### gRPC |
| 149 | + |
| 150 | +Enable gRPC server in config and use port 9000 by default. Protocol definitions are in `rpc/proto/`. |
| 151 | + |
| 152 | +## Testing Requirements |
| 153 | + |
| 154 | +Tests require FCM credentials and test tokens: |
| 155 | + |
| 156 | +```bash |
| 157 | +export FCM_CREDENTIAL="/path/to/firebase-credentials.json" |
| 158 | +export FCM_TEST_TOKEN="your_test_device_token" |
| 159 | +``` |
| 160 | + |
| 161 | +## Build Tags |
| 162 | + |
| 163 | +- Default: `sqlite` tag enabled |
| 164 | +- `lambda` tag: For AWS Lambda builds |
| 165 | +- Custom tags can be set with `TAGS` environment variable |
0 commit comments