re-write with std usage of net/http
This commit is contained in:
parent
c107d94b11
commit
81bc046237
10 changed files with 419 additions and 97 deletions
80
README.md
80
README.md
|
@ -1,24 +1,31 @@
|
|||
# Playground GO
|
||||
|
||||
A simple web server implementation in Go that demonstrates basic HTTP server concepts.
|
||||
A modern web server implementation in Go that demonstrates production-ready HTTP server concepts.
|
||||
|
||||
## Overview
|
||||
|
||||
This project implements a basic HTTP server that:
|
||||
- Listens on a specified address and port
|
||||
- Handles HTTP requests
|
||||
This project implements a robust HTTP server that:
|
||||
- Listens on a configurable port
|
||||
- Handles HTTP requests with a custom router
|
||||
- Processes requests concurrently using goroutines
|
||||
- Implements middleware for logging and request processing
|
||||
- Provides graceful shutdown capabilities
|
||||
- Uses structured logging
|
||||
- Follows clean architecture principles
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
.
|
||||
├── main.go # Application entry point
|
||||
├── server/
|
||||
│ ├── server.go # Server implementation
|
||||
│ └── handler.go # HTTP request handlers
|
||||
├── go.mod # Go module definition
|
||||
└── README.md # This file
|
||||
├── main.go # Application entry point
|
||||
├── handlers/ # HTTP request handlers
|
||||
├── middleware/ # HTTP middleware components
|
||||
├── logger/ # Structured logging implementation
|
||||
├── internal/ # Internal packages and configuration
|
||||
├── static/ # Static file serving
|
||||
├── go.mod # Go module definition
|
||||
├── .gitignore # Git ignore rules
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
@ -27,38 +34,49 @@ This project implements a basic HTTP server that:
|
|||
|
||||
## Usage
|
||||
|
||||
1. Import the server package in your Go code:
|
||||
|
||||
```go
|
||||
import "your-module-name/server"
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://github.com/yourusername/playground-go.git
|
||||
cd playground-go
|
||||
```
|
||||
|
||||
2. Create a new server instance:
|
||||
|
||||
```go
|
||||
server := server.NewServer(":8080") // Listen on port 8080
|
||||
2. Run the server:
|
||||
```bash
|
||||
go run main.go
|
||||
```
|
||||
|
||||
3. Start the server:
|
||||
|
||||
```go
|
||||
server.ListenAndServe()
|
||||
```
|
||||
The server will start on the configured port (default: 8080).
|
||||
|
||||
## Features
|
||||
|
||||
- Concurrent request handling using goroutines
|
||||
- HTTP request processing
|
||||
- Graceful error handling
|
||||
- Simple and clean API design
|
||||
- Graceful server shutdown
|
||||
- Structured logging
|
||||
- Middleware support for request processing
|
||||
- Configuration management
|
||||
- Clean architecture with separated concerns
|
||||
- Static file serving
|
||||
- Error handling and logging
|
||||
|
||||
## Configuration
|
||||
|
||||
The server can be configured through environment variables:
|
||||
- `PORT`: The port number to listen on (default: 8080)
|
||||
- Additional configuration options can be added in the `internal/config` package
|
||||
|
||||
## Error Handling
|
||||
|
||||
The server includes basic error handling for:
|
||||
- Address binding errors
|
||||
- Request processing errors
|
||||
- HTTP response errors
|
||||
The server includes comprehensive error handling for:
|
||||
- Server startup and shutdown
|
||||
- Request processing
|
||||
- Configuration loading
|
||||
- Graceful shutdown with timeout
|
||||
- Structured error logging
|
||||
|
||||
## Contributing
|
||||
|
||||
Feel free to submit issues and enhancement requests!
|
||||
Feel free to submit issues and enhancement requests! When contributing, please:
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a new branch for your feature
|
||||
3. Submit a pull request with a clear description of your changes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue