project setup

This commit is contained in:
Settel 2021-07-28 22:21:14 +02:00
commit 68625c63d6
6 changed files with 111 additions and 0 deletions

10
client/dist/index.html vendored Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>KnYC</title>
</head>
<body>
KnYC
</body>
</html>

24
server/Makefile Normal file
View File

@ -0,0 +1,24 @@
info:
@echo available targets:
@perl -ne 'm/^([a-zA-Z0-9\-]+):/ && print(" $$1\n");' Makefile
build:
go build knyc.go
run:
go run knyc.go
run-loop:
pexec -R -c -e TARGET \
-r _run-endless-loop \
-r _run-inotify-restart \
-- $(MAKE) '$$TARGET'
run-standalone:
./knyc
_run-endless-loop:
while true; do $(MAKE) run || sleep 3; done
_run-inotify-restart:
inotifyloop . curl -s http://localhost:32039/__intern__/exit

3
server/go.mod Normal file
View File

@ -0,0 +1,3 @@
module sirlab.de/go/knyc
go 1.16

27
server/handler/authmux.go Normal file
View File

@ -0,0 +1,27 @@
package handler
import (
"net/http"
)
type AuthMux struct {
mux *http.ServeMux
}
func NewAuthMux() *AuthMux {
return &(AuthMux{
mux: http.NewServeMux(),
})
}
func (authMux *AuthMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
authMux.mux.ServeHTTP(w, r)
}
func (authMux *AuthMux) PublicHandleFunc(pattern string, handlerFunc func(http.ResponseWriter, *http.Request)) {
authMux.mux.HandleFunc(pattern, handlerFunc)
}
func (authMux *AuthMux) PublicHandle(pattern string, handler http.Handler) {
authMux.mux.Handle(pattern, handler)
}

View File

@ -0,0 +1,23 @@
package handler
import (
"fmt"
"net/http"
"os"
"time"
)
func Exit(_ http.ResponseWriter, _ *http.Request) {
os.Exit(0)
}
func CreateVersionHandler() func(w http.ResponseWriter, r *http.Request) {
startTime := time.Now().Unix()
return func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%d\n", startTime)
}
}
func IsLoggedIn(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintf(w, "ok")
}

24
server/knyc.go Normal file
View File

@ -0,0 +1,24 @@
package main
import (
"fmt"
"net/http"
"sirlab.de/go/knyc/handler"
)
func main() {
app := handler.NewAuthMux()
http.Handle("/", app)
app.PublicHandleFunc("/__intern__/exit", handler.Exit)
// hanlde login page
fsHandler := http.FileServer(http.Dir("../client/dist/"))
// default handler
app.PublicHandle("/", fsHandler)
// start listening
fmt.Println("http://localhost:32039")
http.ListenAndServe(":32039", nil)
}