barcodes/web/server.go

28 lines
576 B
Go
Raw Normal View History

2023-09-01 21:51:30 +01:00
package web
import (
"fmt"
"net/http"
)
func StartServer() {
2023-09-03 21:41:25 +01:00
// What I want to do here is server from /static
// if the resource exists, else try to render from /templates
// if the template exists. Else return 404.
http.HandleFunc("/", mainHandler)
2023-09-01 21:51:30 +01:00
http.HandleFunc("/help", helpTemplate)
2023-09-01 22:47:46 +01:00
2023-09-01 21:51:30 +01:00
http.HandleFunc("/generate", generateBarcode)
http.HandleFunc("/generate/formatted", generateFormattedBarcode)
2023-09-01 21:51:30 +01:00
port := ":8500"
fmt.Printf("Server listening on port %s\n", port)
err := http.ListenAndServe(port, nil)
if err != nil {
fmt.Println("Error: ", err)
}
}