Go server draft
This commit is contained in:
parent
51faa74cd8
commit
29d5885b67
7 changed files with 148 additions and 0 deletions
32
backend/cmd/main.go
Normal file
32
backend/cmd/main.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
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() {
|
||||
println("Starting server...")
|
||||
database.DbConnect()
|
||||
|
||||
// Mounting the handler
|
||||
fs := http.FileServer(http.Dir("static"))
|
||||
http.Handle("/", fs)
|
||||
http.HandleFunc("/hello", handler)
|
||||
|
||||
// Start the server on port 8080
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue