template bits
This commit is contained in:
parent
be5840ff3a
commit
3dfa497689
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -16,5 +16,8 @@
|
|||
# vendor/
|
||||
|
||||
# sensitive data that shouldn't be pushed
|
||||
data/*
|
||||
data/
|
||||
config.yml
|
||||
|
||||
# build bits
|
||||
resources/build/
|
36
main.go
36
main.go
|
@ -2,20 +2,24 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"html"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"text/template"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Config types
|
||||
// ------------
|
||||
type ServerConfig struct {
|
||||
Name string
|
||||
Homepage string
|
||||
}
|
||||
type AdminConfig struct {
|
||||
WebRoot string
|
||||
Port int
|
||||
LogPath string
|
||||
}
|
||||
type AuthConfig struct {
|
||||
GiteaURL string
|
||||
|
@ -39,15 +43,31 @@ func loadConfig() (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := loadConfig()
|
||||
if err != nil {
|
||||
log.Fatal("oh no !!!")
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
path := r.URL.Path
|
||||
var tmpl string
|
||||
if path == "/" {
|
||||
tmpl = "templates/home.html"
|
||||
} else {
|
||||
tmpl = fmt.Sprintf("templates/%s", path)
|
||||
}
|
||||
t, _ := template.ParseFiles(tmpl)
|
||||
t.Execute(w, config)
|
||||
}
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||||
})
|
||||
func main() {
|
||||
err := loadConfig()
|
||||
fmt.Print(config)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("couldn't load config: %s", err)
|
||||
}
|
||||
|
||||
http.Handle("/resources/",
|
||||
http.StripPrefix("/resources/",
|
||||
http.FileServer(http.Dir("./resources"))))
|
||||
|
||||
http.HandleFunc("/", handler)
|
||||
|
||||
err = http.ListenAndServe(":8080", nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
body {
|
||||
color: purple;
|
||||
}
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
7
tailwind.config.js
Normal file
7
tailwind.config.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
module.exports = {
|
||||
content: ["./templates/*.html"],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
|
@ -1,14 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
|
||||
<title>{ server.name } Admin Panel</title>
|
||||
<title>{{.Server.Name}} Admin Panel</title>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
|
||||
<script src='main.js'></script>
|
||||
<link rel='stylesheet' type='text/css' media='screen' href='/resources/main.css'>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<body>
|
||||
<h1 class="text-3xl font-bold underline">
|
||||
Hello world!
|
||||
</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user