App stuff
This commit is contained in:
parent
a8355da398
commit
caabd6d740
4 changed files with 78 additions and 5 deletions
10
clicked.go
Normal file
10
clicked.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func handleClicked(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "Clicked")
|
||||
}
|
34
index.go
Normal file
34
index.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var index_template *template.Template
|
||||
|
||||
type indexData struct {
|
||||
Time string
|
||||
}
|
||||
|
||||
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
||||
//if index_template == nil {
|
||||
// tmpl, err := template.ParseFiles("templates/index.html")
|
||||
// if err != nil {
|
||||
// http.Error(w, "Couldn't parse template file", http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// index_template = tmpl
|
||||
//}
|
||||
|
||||
tmpl, err := template.ParseFiles("templates/index.html")
|
||||
if err != nil {
|
||||
http.Error(w, "Couldn't parse template file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tmpl.Execute(w, indexData{Time: time.Now().Format(time.Stamp)})
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to execute template", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
20
main.go
20
main.go
|
@ -1,12 +1,22 @@
|
|||
package main
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
log.Printf("Defaulting to port %s \n", port)
|
||||
}
|
||||
|
||||
http.HandleFunc("/", handleRoot)
|
||||
http.ListenAndServe("0.0.0.0:8000", nil)
|
||||
}
|
||||
|
||||
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
||||
http.HandleFunc("/clicked", handleClicked)
|
||||
if err := http.ListenAndServe(":"+port, nil); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
19
templates/index.html
Normal file
19
templates/index.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Import htmx even if not used yet -->
|
||||
<script src="https://unpkg.com/htmx.org@1.9.5"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<style>
|
||||
* {
|
||||
font-family: Cantarell, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to Evilthings.net</h1>
|
||||
<p style="font-size: x-small">This webpage is still under construction</p>
|
||||
<p>Evilthings will be the studio name under which <a href="https://mstar.evilthings.net">mStar</a> will release software</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue