- Go 1.21+ (you have 1.23.0 ✅)
- MySQL 8.0+
- Git
# Make executable and run
chmod +x install-tools.sh
./install-tools.sh
# Or install manually
go install github.com/air-verse/air@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
# Start MySQL (macOS with Homebrew)
brew services start mysql
# Or on Ubuntu/Debian
sudo systemctl start mysql
# Create database
mysql -u root -p -e "CREATE DATABASE social_go CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
# Copy environment file
cp .env.example .env
# Edit with your settings
nano .env
Update these values in .env
:
DATABASE_URL=root:YOUR_PASSWORD@tcp(localhost:3306)/social_go?charset=utf8mb4&parseTime=True&loc=Local
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
# Run all migrations
make migrate-up
# Check migration status
make migrate-status
# Start with hot reload (recommended for development)
make dev
# Or start normally
make run
curl http://localhost:8080/health
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "password123",
"name": "Test User"
}'
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "password123"
}'
make run # Start server locally
make dev # Start with hot reload
make build # Build binary
make test # Run tests
make health # Check server status
make migrate-up # Run all migrations
make migrate-down # Rollback last migration
make migrate-status # Show migration status
make migrate-create NAME=add_field # Create new migration
make db-create # Create database
make db-reset # Drop, create, and migrate
make docker-up # Start all services with Docker
make docker-down # Stop Docker services
make docker-logs # View logs
make fmt # Format code
make lint # Run linter
make test-coverage # Run tests with coverage
make clean # Clean build artifacts
Endpoint | Method | Description | Auth Required |
---|---|---|---|
/health |
GET | Health check | No |
/api/v1/auth/register |
POST | Register user | No |
/api/v1/auth/login |
POST | Login user | No |
/api/v1/auth/refresh |
POST | Refresh token | No |
/api/v1/auth/google |
GET | Google OAuth | No |
/api/v1/auth/apple |
GET | Apple OAuth | No |
/api/v1/profile |
GET | Get user profile | Yes |
/api/v1/profile |
PUT | Update profile | Yes |
/api/v1/logout |
POST | Logout user | Yes |
1. Air tool not found:
go install github.com/air-verse/air@latest
2. Database connection failed:
- Check MySQL is running:
brew services list | grep mysql
- Verify credentials in
.env
- Test connection:
mysql -u root -p
3. Migration failed:
# Check migration status
make migrate-status
# Force to specific version if needed
make migrate-force VERSION=1
4. Port already in use:
# Find process using port 8080
lsof -i :8080
# Kill process
kill -9 <PID>
- Configure OAuth - Add your Google/Apple credentials to
.env
- Add Features - Extend the API with new endpoints
- Deploy - Use Docker compose for production deployment
- Monitor - Add logging and monitoring
social_go/
├── internal/
│ ├── config/ # Configuration management
│ ├── database/ # Database connection
│ ├── handlers/ # HTTP handlers
│ ├── middleware/ # HTTP middleware
│ ├── models/ # Database models
│ ├── repositories/ # Data access layer
│ ├── services/ # Business logic
│ └── utils/ # Utility functions
├── migrations/ # Database migrations
├── pkg/ # Shared packages
├── Makefile # Development commands
└── main.go # Application entry point
Happy coding! 🎉