Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nevinmathew/simple-web-server
This is a basic Golang web server that serves static files. This is a minimal web server, handle simple HTTP requests, & manage shared variables safely using mutexes to prevent race conditions.
https://github.com/nevinmathew/simple-web-server
go golang mutex race-conditions web-server
Last synced: 8 days ago
JSON representation
This is a basic Golang web server that serves static files. This is a minimal web server, handle simple HTTP requests, & manage shared variables safely using mutexes to prevent race conditions.
- Host: GitHub
- URL: https://github.com/nevinmathew/simple-web-server
- Owner: nevinmathew
- Created: 2023-01-16T06:14:19.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T03:00:22.000Z (about 1 year ago)
- Last Synced: 2024-11-07T10:20:36.656Z (about 2 months ago)
- Topics: go, golang, mutex, race-conditions, web-server
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple-Web-Server
## Overview
This is a simple Golang web server application that serves static files and provides a few basic HTTP endpoints. It demonstrates the use of the Go programming language for building web applications.## Table of Contents
- [Features](#features)
- [Usage](#usage)## Features
- **Static File Server**: The web server serves static files from the `./static` directory, which can be useful for hosting HTML, CSS, JavaScript, and other assets for a website.
- **"Hi" Endpoint**: Accessing the `/hi` endpoint responds with a simple "Hi" message, showcasing how to handle HTTP requests and provide responses.
- **Increment Counter Endpoint**: Accessing the `/increment` endpoint increments a counter and returns the updated counter value. This demonstrates the use of mutexes to safely manipulate shared variables in a multi-threaded environment. The use of a mutex highlights the importance of guarding against race conditions in web server applications.
## Usage
- Access the static files by visiting the root URL (e.g., [http://localhost:5000/](http://localhost:5000/)).
- Get a "Hi" message by visiting [http://localhost:5000/hi](http://localhost:5000/hi).
- Increment the counter by visiting [http://localhost:5000/increment](http://localhost:5000/increment). Each time you access this endpoint, the counter value will increase and be displayed on the page, with proper locking to avoid race conditions.