Initial commit

This commit is contained in:
2025-03-22 18:27:58 +03:00
commit e59c4d1f5e
6 changed files with 187 additions and 0 deletions

28
.gitignore vendored Normal file
View File

@@ -0,0 +1,28 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
go.work.sum
# env file
.env
# GoLand
.idea/

14
LICENSE.md Normal file
View File

@@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

40
README.md Normal file
View File

@@ -0,0 +1,40 @@
# Teapot Server
## Description
This is a simple "teapot server" project, inspired by the classic XKCD comic. It's designed to be a minimal HTTP server that responds with a 418 I'm teapot status and a humorous message about quantum fluctuations. The primary purpose is for demonstration and learning purposes, showcasing basic Go web development concepts.
## Usage
1. **Clone the repository:**
```bash
git clone https://gitea.mrixs.me/Mrixs/teapot-server.git
cd teapot-server
```
2. **Build the server:**
```bash
go build .
```
3. **Run the server:**
```bash
./teapot-server
```
4. **Access the server:** Open your web browser and navigate to `http://localhost:8080`. You should see a message about quantum fluctuations.
## Technical Details
* **Language:** Go (Golang)
* **Dependencies:** None (uses standard library only)
* **Port:** The server listens on port 8080 by default. This can be configured via command line argument `--port <port>`.
* **Error Handling:** Basic error handling is implemented to catch potential issues during startup and runtime.
## Contributing
Feel free to contribute by submitting bug reports or feature requests. Pull requests are welcome!
## License
This project is licensed under the [WTFPL License](LICENSE.md). See the `LICENSE` file for details.

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module mrixs.me/teapot-server
go 1.24.1

34
teapot-server.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
// Read the HTML content from the file
content, err := ioutil.ReadFile("teapot.html")
if err != nil {
http.Error(w, "Internal Server Error: Could not read HTML file", http.StatusInternalServerError)
log.Println("Error reading HTML file:", err)
return
}
// Write the content to the response writer
w.WriteHeader(http.StatusTeapot) // Set the 418 status code
fmt.Fprintf(w, string(content)) //Write the entire content as a string
}
func main() {
portPtr := flag.Int("port", 8080, "Port to listen on")
flag.Parse()
port := *portPtr // Dereference the pointer
fmt.Printf("Server listening on port %d...\n", port)
http.HandleFunc("/", handler) // Register the handler for all requests on root path "/"
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
}

68
teapot.html Normal file

File diff suppressed because one or more lines are too long