fix: updated readme and added envrc example
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
# Server Configuration
|
||||||
|
export ADDR=":8080"
|
||||||
|
export EXTERNAL_URL="localhost:8080"
|
||||||
|
export FRONTEND_URL="http://localhost:5173"
|
||||||
|
export ENV="development"
|
||||||
|
export ALLOWED_ORIGINS="https://*,http://*" # TODO: Change to the actual allowed origins on production
|
||||||
|
|
||||||
|
# Database Configuration
|
||||||
|
export DB_ADDR="postgres://postgres:postgres@localhost:5432/lk_tmpl?sslmode=disable"
|
||||||
|
export DB_MAX_OPEN_CONNS="30"
|
||||||
|
export DB_MAX_IDLE_CONNS="30"
|
||||||
|
export DB_MAX_IDLE_TIME="15m"
|
||||||
|
|
||||||
|
# Redis Configuration
|
||||||
|
export REDIS_ADDR="localhost:6379"
|
||||||
|
export REDIS_PASSWORD=""
|
||||||
|
export REDIS_DB="0"
|
||||||
|
export REDIS_ENABLED="false"
|
||||||
|
|
||||||
|
# Authentication
|
||||||
|
export BASIC_AUTH_USERNAME="admin"
|
||||||
|
export BASIC_AUTH_PASSWORD="admin"
|
||||||
|
export AUTH_TOKEN_SECRET="your-secret-key-here"
|
||||||
|
export AUTH_TOKEN_EXP="24h"
|
||||||
|
export AUTH_TOKEN_ISS="lkapi"
|
||||||
|
export AUTH_TOKEN_AUD="lkapi"
|
||||||
|
|
||||||
|
# Email Configuration
|
||||||
|
export FROM_EMAIL="[email protected]"
|
||||||
|
export SENDGRID_API_KEY="your-sendgrid-api-key"
|
||||||
|
|
||||||
|
# Rate Limiter
|
||||||
|
export RATE_LIMITER_REQS_COUNT="20"
|
||||||
|
export RATE_LIMITER_TIME_FRAME="1m"
|
||||||
|
export RATE_LIMITER_ENABLED="true"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# LK API Template
|
# LK API Template
|
||||||
|
|
||||||
A modern, production-ready API template built with Go and React, featuring comprehensive authentication, mailing capabilities, and automatic API documentation.
|
A modern, production-ready API template built with Go and Nuxt 3, featuring comprehensive authentication, mailing capabilities, and automatic API documentation.
|
||||||
|
|
||||||
## 🚀 Features
|
## 🚀 Features
|
||||||
|
|
||||||
@@ -28,11 +28,17 @@ A modern, production-ready API template built with Go and React, featuring compr
|
|||||||
|
|
||||||
## 📋 Prerequisites
|
## 📋 Prerequisites
|
||||||
|
|
||||||
- Go 1.21 or higher
|
- Go 1.23.4 or higher
|
||||||
- Node.js 18 or higher
|
- Bun 1.0 or higher (for frontend development)
|
||||||
- PostgreSQL
|
- Docker and Docker Compose
|
||||||
- Redis
|
|
||||||
- SendGrid API key (for email functionality)
|
- SendGrid API key (for email functionality)
|
||||||
|
- Platform-specific requirements:
|
||||||
|
- **Mac/Linux**:
|
||||||
|
- direnv (for environment management)
|
||||||
|
- make
|
||||||
|
- **Windows**:
|
||||||
|
- Git Bash, WSL2, or PowerShell
|
||||||
|
- make (optional, commands can be run manually)
|
||||||
|
|
||||||
## 🛠️ Installation
|
## 🛠️ Installation
|
||||||
|
|
||||||
@@ -43,49 +49,206 @@ git clone https://github.com/FernandoJVideira/LK_API_Temp.git
|
|||||||
cd LK_API_Temp
|
cd LK_API_Temp
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Install backend dependencies:
|
2. Install Bun (if not already installed):
|
||||||
|
|
||||||
|
**Mac/Linux**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go mod download
|
curl -fsSL https://bun.sh/install | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Install frontend dependencies:
|
**Windows**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd web
|
# Install WSL2 first if not already installed
|
||||||
npm install
|
# Then run the same command as Mac/Linux inside WSL2
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Set up environment variables:
|
3. Set up environment variables:
|
||||||
|
|
||||||
|
**Mac/Linux with direnv**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .envrc.example .envrc
|
||||||
|
# Edit .envrc with your configuration
|
||||||
|
direnv allow
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows or alternative setup**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
# Edit .env with your configuration
|
# Edit .env with your configuration
|
||||||
```
|
```
|
||||||
|
|
||||||
|
4. Install backend dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go mod download
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Install frontend dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd web
|
||||||
|
bun install
|
||||||
|
```
|
||||||
|
|
||||||
## 🚀 Development
|
## 🚀 Development
|
||||||
|
|
||||||
|
### Infrastructure
|
||||||
|
|
||||||
|
**Mac/Linux**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start services
|
||||||
|
make start
|
||||||
|
|
||||||
|
# Stop services
|
||||||
|
make stop
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows (without make)**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start services
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# Stop services
|
||||||
|
docker-compose down
|
||||||
|
```
|
||||||
|
|
||||||
|
### Database Management
|
||||||
|
|
||||||
|
**Mac/Linux**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create new migration
|
||||||
|
make migration name=your_migration_name
|
||||||
|
|
||||||
|
# Run migrations
|
||||||
|
make migrate-up
|
||||||
|
|
||||||
|
# Rollback migrations
|
||||||
|
make migrate-down
|
||||||
|
|
||||||
|
# Seed database
|
||||||
|
make seed
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows (without make)**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create new migration
|
||||||
|
go run ./cmd/migrate create your_migration_name
|
||||||
|
|
||||||
|
# Run migrations
|
||||||
|
go run ./cmd/migrate up
|
||||||
|
|
||||||
|
# Rollback migrations
|
||||||
|
go run ./cmd/migrate down
|
||||||
|
|
||||||
|
# Seed database
|
||||||
|
go run ./cmd/migrate seed
|
||||||
|
```
|
||||||
|
|
||||||
### Backend
|
### Backend
|
||||||
|
|
||||||
Run the backend server with hot reload:
|
**Mac/Linux**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# Install Air (if not already installed)
|
||||||
|
go install github.com/cosmtrek/air@latest
|
||||||
|
|
||||||
|
# Run with hot reload
|
||||||
air
|
air
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Windows**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install Air (if not already installed)
|
||||||
|
go install github.com/cosmtrek/air@latest
|
||||||
|
|
||||||
|
# Run with hot reload (Git Bash or WSL)
|
||||||
|
air
|
||||||
|
|
||||||
|
# Alternative without Air
|
||||||
|
go run ./cmd/api
|
||||||
|
```
|
||||||
|
|
||||||
The API will be available at `http://localhost:8080` with the base path `/v1`.
|
The API will be available at `http://localhost:8080` with the base path `/v1`.
|
||||||
|
|
||||||
### Frontend
|
### Frontend
|
||||||
|
|
||||||
Run the frontend development server:
|
All platforms:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd web
|
cd web
|
||||||
npm run dev
|
bun run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
The frontend will be available at `http://localhost:3000` (default Nuxt port).
|
The frontend will be available at `http://localhost:3000`.
|
||||||
|
|
||||||
|
For other frontend commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build for production
|
||||||
|
bun run build
|
||||||
|
|
||||||
|
# Preview production build
|
||||||
|
bun run preview
|
||||||
|
|
||||||
|
# Lint
|
||||||
|
bun run lint
|
||||||
|
|
||||||
|
# Type check
|
||||||
|
bun run typecheck
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: Bun provides significantly faster installation and execution times compared to npm or yarn. It also includes built-in TypeScript support and other optimizations for modern web development.
|
||||||
|
|
||||||
|
## 🔧 Environment Configuration
|
||||||
|
|
||||||
|
### Using direnv (Mac/Linux recommended)
|
||||||
|
|
||||||
|
The `.envrc` file is used with direnv to automatically load environment variables when entering the project directory. Example configuration:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Server
|
||||||
|
export ADDR=:8080
|
||||||
|
export EXTERNAL_URL=localhost:8080
|
||||||
|
export FRONTEND_URL=http://localhost:3000
|
||||||
|
export ENV=development
|
||||||
|
|
||||||
|
# Database
|
||||||
|
export DB_ADDR=postgres://postgres:postgres@localhost:5432/lk_tmpl?sslmode=disable
|
||||||
|
export DB_MAX_OPEN_CONNS=30
|
||||||
|
export DB_MAX_IDLE_CONNS=30
|
||||||
|
export DB_MAX_IDLE_TIME=15m
|
||||||
|
|
||||||
|
# Additional variables...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using .env file (Windows or alternative)
|
||||||
|
|
||||||
|
The same variables should be set in your `.env` file without the `export` keyword:
|
||||||
|
|
||||||
|
```env
|
||||||
|
ADDR=:8080
|
||||||
|
EXTERNAL_URL=localhost:8080
|
||||||
|
FRONTEND_URL=http://localhost:3000
|
||||||
|
ENV=development
|
||||||
|
# Additional variables...
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔍 Monitoring
|
||||||
|
|
||||||
|
- Redis Commander UI: `http://localhost:8081`
|
||||||
|
- Mac/Linux: Access directly
|
||||||
|
- Windows: If using WSL2, use the WSL2 IP address instead of localhost
|
||||||
|
- Metrics and debugging endpoints available through expvar
|
||||||
|
|
||||||
## 📚 API Documentation
|
## 📚 API Documentation
|
||||||
|
|
||||||
The API documentation is automatically generated using Swagger. Once the server is running, you can access the Swagger UI at: `http://localhost:8080/v1/swagger/index.html#/`
|
The API documentation is automatically generated using Swagger. Once the server is running, you can access the Swagger UI at: `http://localhost:8080/v1/swagger/index.html#/`
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ type CreateCommentPayload struct {
|
|||||||
Content string `json:"content" validate:"required, max=1000"`
|
Content string `json:"content" validate:"required, max=1000"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateComment godo
|
// CreateComment godoc
|
||||||
//
|
//
|
||||||
// @Summary Creates a new Comment
|
// @Summary Creates a new Comment
|
||||||
// @Description Creates a new Comment
|
// @Description Creates a new Comment
|
||||||
|
|||||||
Reference in New Issue
Block a user