A simple web server built with Go that demonstrates basic web functionality including static file serving, form handling, and API endpoints.
- Static file serving
- Form handling with POST requests
- Simple API endpoint (/hello)
- Basic error handling
.
├── main.go # Main server code
├── static/ # Static files directory
│ ├── index.html # Landing page
│ └── form.html # Form page
└── go.mod # Go module file
- Go 1.x or higher
- Basic understanding of Go and web development
- Clone the repository:
git clone <your-repository-url>
cd Go-webserver- Install dependencies:
go mod tidy- Start the server:
go run main.go- The server will start on port 8080. You can access it at:
- Main page: http://localhost:8080
- Form page: http://localhost:8080/form.html
- Hello endpoint: http://localhost:8080/hello
GET /: Serves static files from the static directoryPOST /form: Handles form submissions- Accepts form data with fields:
- name
- address
- Accepts form data with fields:
GET /hello: Returns a simple "hello!" message
- Navigate to http://localhost:8080/form.html
- Fill in the form fields:
- Name
- Address
- Submit the form
- The server will respond with the submitted data
The server includes basic error handling for:
- 404 Not Found errors
- Invalid HTTP methods
- Form parsing errors
Feel free to submit issues and enhancement requests.