Unit Converter Web Form
Build a small web app in Go with a form for converting units: length (meters, feet, miles and more), weight (kilograms, pounds, ounces) and temperature (Celsius, Fahrenheit, Kelvin). You type a value, choose the units and submit, and the page shows the result. Everything runs on the server with Go's standard library, with no frameworks and no JavaScript: net/http serves the pages and html/template renders them. It's a good first web project in Go: you'll learn how HTTP handlers work, how to read form data, how templates display data safely, and how to show helpful error messages.
- Estimate
- ~9h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
net/http · html/template
Project roadmap
- 01
Start a web server
~1hRun go mod init, then write a main.go that starts an HTTP server on port 8080 with http.ListenAndServe and a handler for / that responds with a short text message. Done when: go run . works and opening http://localhost:8080 in the browser shows the message.
- 02
Render the form with a template
~1.5hCreate templates/index.html with a form: a number input for the value, a select for the category (length, weight, temperature), selects for the from and to units, and a Convert button that submits with POST. Parse the template once at startup with template.ParseFiles and render it in the / handler. Done when: the page shows the form in the browser.
- 03
Write the conversions
~2hIn convert.go, write the conversion logic. For length and weight, store how much each unit is worth in a base unit (meters, kilograms) in a map, and convert through the base unit. Temperature needs formulas, so convert through Celsius. Return an error for units that don't belong to the chosen category. Done when: the functions give correct results, for example 1 mile = 1609.34 m and 100 °C = 212 °F.
- 04
Handle the form and show the result
~1.5hWhen the form is submitted, read the values with r.FormValue, convert the value with strconv.ParseFloat, run the conversion and render the same template with the result, like 5 miles = 8.05 km. Keep the user's inputs filled in after submitting. Done when: submitting the form shows the correct result on the page.
- 05
Show errors and add styling
~1.5hShow a readable error next to the form when the value is empty or not a number, or the units don't match the category, instead of a broken page. Add a small CSS file served with http.FileServer from a static/ folder so the form looks tidy. Done when: invalid input shows a clear message and the page is styled.
- 06
Add tests
~1.5hWrite table-driven tests in convert_test.go for several conversions in each category and for invalid unit combinations. Add one handler test with net/http/httptest that posts a form and checks the result text appears in the response. Done when: go test ./... passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack