TTime/backend/cmd/main.go

35 lines
733 B
Go
Raw Normal View History

2024-02-12 12:40:49 +01:00
package main
import (
"fmt"
"io"
"net/http"
"tmp/internal/database"
_ "github.com/mattn/go-sqlite3"
)
// This is what a handler looks like
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Request received")
io.WriteString(w, "This is my website!\n")
}
func main() {
database.DbConnect()
// Mounting the handler
fs := http.FileServer(http.Dir("static"))
http.Handle("/", fs)
http.HandleFunc("/hello", handler)
// Start the server on port 8080
2024-02-12 17:20:42 +01:00
println("Currently listening on http://localhost:8080")
println("Visit http://localhost:8080/hello to see the handler in action")
2024-02-12 17:23:42 +01:00
println("Press Ctrl+C to stop the server")
2024-02-12 12:40:49 +01:00
err := http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}
}