This project is a basic web server written in Go. It demonstrates how to handle HTTP requests, serve static files, and create custom handlers for specific routes.
The web server provides the following functionalities:
- Serves static files from the
./static
directory. - Handles form submissions through a
/form
endpoint. - Responds to a simple GET request at the
/hello
endpoint.
-
Static File Server:
- The root path (
/
) serves static files from the./static
directory. - This is useful for serving HTML, CSS, JavaScript, images, and other assets.
- The root path (
-
Form Handling:
- The
/form
endpoint accepts POST requests and parses form data. - It extracts
name
andaddress
from the form submission and responds with the provided values.
- The
-
Hello Handler:
- The
/hello
endpoint accepts GET requests. - It responds with a simple "Hello!" message.
- If the path is incorrect or a method other than GET is used, an appropriate HTTP error is returned.
- The
-
formHandler
Function:- Parses form data and extracts values for
name
andaddress
. - Responds with the parsed data or an error message if parsing fails.
- Parses form data and extracts values for
-
helloHandler
Function:- Handles requests to the
/hello
path. - Returns a "Hello!" response for GET requests and a 404 or method-not-allowed response for other cases.
- Handles requests to the
-
main
Function:- Sets up the file server and maps the endpoints to their respective handler functions.
- Starts the server on port 8080.