commit e59c4d1f5ee12952fa1fbce42b8ebb91e40690fd Author: Vladimir Zagainov Date: Sat Mar 22 18:27:58 2025 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5885be1 --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..5a8e332 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + 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. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..46a3d06 --- /dev/null +++ b/README.md @@ -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 `. +* **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. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a3954e6 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module mrixs.me/teapot-server + +go 1.24.1 diff --git a/teapot-server.go b/teapot-server.go new file mode 100644 index 0000000..7415ccc --- /dev/null +++ b/teapot-server.go @@ -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)) +} diff --git a/teapot.html b/teapot.html new file mode 100644 index 0000000..949d0c6 --- /dev/null +++ b/teapot.html @@ -0,0 +1,68 @@ + + + + + Портал к чайнику открылся! 🚀 + + + +
+

Ошибка 418: Я - чайник

+

+ Похоже, в результате квантового скачка вы обратились не к + серверу, а к параллельной вселенной, где чайники — это основное + информационное устройство. +

+ Чайник +

+ Попробуйте снова, и может вам повезет — вы найдёте путь назад к + серверу! +

+

+ *Спасибо за ваше терпение. Мы работаем над устранением + этого "квантового скачка". +

+
+ +