A modern Go template featuring WebSocket support and Prisma Go client for efficient database operations.
- WebSocket Integration: Real-time bidirectional communication
- Prisma Go Client: Type-safe database operations
- RESTful API: Simple and clean HTTP endpoints
- Database Integration: Efficient database operations using Prisma Go client
- Modern Architecture: Follows Go best practices
- Go 1.16 or higher
- Prisma Go client
- Database (PostgreSQL recommended)
- Clone the repository
git clone https://github.com/yourusername/project-name
cd project-name
- Install dependencies
go mod download
- Set up your environment variables
cp .env.example .env
# Edit .env with your database credentials
- Generate Prisma Go client
go run github.com/steebchen/prisma-client-go generate
- Start the server
go run main.go
.
├── main.go
├── client.go
├── manager.go
├── events.go
├── config/
│ └── database.go
├── controller/
│ └── user_controller.go
├── data/
│ └── request/
│ ├── user_create_req.go
│ └── user_update_req.go
│ └── response/
│ ├── user_response.go
│ └── web_response.go
├── helper/
│ └── json.go
├── repository/
│ ├── post_repo.go
│ └── user_repo_impl.go
├── service/
│ ├── user_service_impl.go
│ └── user_service.go
├── model/
│ ├── file.go
│ ├── user.go
│ └── room.go
├── prisma/
│ ├── schema.prisma
│ └── migrations/
├── pkg/
│ ├── database/
│ └── websocket/
├── .env.example
├── go.mod
└── README.md
Connect to the WebSocket endpoint:
const ws = new WebSocket('ws://localhost:8080/ws');
Example of using Prisma Go client:
// Create a new user
user, err := client.User.CreateOne(
db.User.Email.Set("[email protected]"),
db.User.Name.Set("John Doe"),
).Exec(ctx)
// Find a user
user, err := client.User.FindFirst(
db.User.Email.Equals("[email protected]"),
).Exec(ctx)
// Update a user
user, err := client.User.FindUnique(
db.User.ID.Equals("user-id"),
).Update(
db.User.Name.Set("Jane Doe"),
).Exec(ctx)
Method | Endpoint | Description |
---|---|---|
GET | /api/users | Get all users |
POST | /api/users | Create new user |
GET | /api/users/:id | Get user by ID |
PUT | /api/users/:id | Update user |
DELETE | /api/users/:id | Delete user |
WS | /ws | WebSocket connection |
Required environment variables:
DATABASE_URL="postgresql://username:password@localhost:5432/dbname"
PORT=8080
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.