Initial hello world
This commit is contained in:
44
application/index.go
Normal file
44
application/index.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
lp := filepath.Join("application", "layouts", "main.html")
|
||||
fp := filepath.Join("application", "views", "index.html")
|
||||
|
||||
// Return a 404 if the template doesn't exist
|
||||
info, err := os.Stat(fp)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Return a 404 if the request is for a directory
|
||||
if info.IsDir() {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(lp, fp)
|
||||
if err != nil {
|
||||
// Log the detailed error
|
||||
log.Print(err.Error())
|
||||
// Return a generic "Internal Server Error" message
|
||||
http.Error(w, http.StatusText(500), 500)
|
||||
return
|
||||
}
|
||||
|
||||
err = tmpl.ExecuteTemplate(w, "main.html", nil)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
http.Error(w, http.StatusText(500), 500)
|
||||
}
|
||||
}
|
||||
15
application/layouts/main.html
Normal file
15
application/layouts/main.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Hello, World!</title>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="/static/css/bootstrap.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
{{block "content" .}} {{end}}
|
||||
<!-- Bootstrap JS and dependencies -->
|
||||
<script src="/static/js/bootstrap.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
11
application/server.go
Normal file
11
application/server.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetupAppServer() {
|
||||
fs := http.FileServer(http.Dir("./application/static"))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||
http.HandleFunc("/", index)
|
||||
}
|
||||
10837
application/static/css/bootstrap.css
vendored
Normal file
10837
application/static/css/bootstrap.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5016
application/static/js/bootstrap.js
vendored
Normal file
5016
application/static/js/bootstrap.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10
application/views/index.html
Normal file
10
application/views/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{{define "content"}}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<h1 class="mt-5">Hello, World!</h1>
|
||||
<p class="lead">This is a simple Bootstrap 5 "Hello, World!" page.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user