-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (66 loc) · 1.92 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"flag"
"log"
"net/http"
"os"
"path/filepath"
"github.com/a-h/templ"
"github.com/gouae/golang.ae/internal/template"
)
var (
safeURL templ.SafeURL = templ.SafeURL("/")
navbar []template.NavbarItem = []template.NavbarItem{
{Name: "Organizers", Link: safeURL},
{Name: "Meetups", Link: safeURL},
{Name: "Projects", Link: safeURL},
{Name: "Gallery", Link: safeURL},
{Name: "Contact", Link: safeURL},
}
socials []template.Social = []template.Social{
{Icon: "fa-twitter", Link: templ.SafeURL("/twitter")},
{Icon: "fa-whatsapp", Link: templ.SafeURL("/whatsapp")},
{Icon: "fa-linkedin", Link: templ.SafeURL("/linkedin")},
{Icon: "fa-discord", Link: templ.SafeURL("/discord")},
{Icon: "fa-github", Link: templ.SafeURL("/github")},
}
)
func server(port string) {
mux := http.NewServeMux()
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
template.Home("golang.ae", navbar, socials).Render(context.Background(), w)
})
mux.HandleFunc("GET /public/", func(w http.ResponseWriter, r *http.Request) {
filePath := r.URL.Path[len("/public/"):]
fullPath := filepath.Join(".", "public", filePath)
http.ServeFile(w, r, fullPath)
})
log.Printf("Server is running on http://localhost:%s\n", port)
log.Fatal(http.ListenAndServe(":"+port, mux))
}
func static() {
f, err := os.Create("index.html")
if err != nil {
log.Fatalf("failed to create output file: %v", err)
}
f.WriteString("<!-- AUTO GENERATED BY GOUAE -->\n")
err = template.Home("golang.ae", navbar, socials).Render(context.Background(), f)
if err != nil {
log.Fatalf("failed to write output file: %v", err)
}
}
func main() {
portFlag := flag.String("port", "8080", "The port to listen on")
staticFlag := flag.Bool("static", false, "The mode to run in")
flag.Parse()
if *staticFlag {
static()
} else {
server(*portFlag)
}
}