summaryrefslogtreecommitdiff
path: root/server/main.go
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-01-12 17:24:25 -0600
committersanine <sanine.not@pm.me>2023-01-12 17:24:25 -0600
commit655cd79991ec9204afb9f5acf52495c13af14d25 (patch)
treec2f441e09ce65337bb622183107a77c40c0dad0b /server/main.go
parent35de9c18b9c9ce7d466e5aecec0b4becde2795bb (diff)
begin go refactorgo-dynamic
Diffstat (limited to 'server/main.go')
-rw-r--r--server/main.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/server/main.go b/server/main.go
new file mode 100644
index 0000000..63aadb5
--- /dev/null
+++ b/server/main.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+ "flag"
+ "path/filepath"
+ log "github.com/sirupsen/logrus"
+)
+
+
+func main() {
+ log.SetFormatter(&log.TextFormatter{
+ FullTimestamp: true,
+ });
+
+ pathFlag := flag.String(
+ "path", "data", "the path to load site data from",
+ );
+ addrFlag := flag.String(
+ "addr", "127.0.0.1:8080", "the address to serve from",
+ );
+ flag.Parse();
+ log.Infof("data path: %v", *pathFlag);
+ log.Infof("serving from %v", *addrFlag);
+
+ mux := http.NewServeMux()
+ mux.HandleFunc("/ip", func(w http.ResponseWriter, req *http.Request) {
+ fmt.Fprintf(w, "%v", req.RemoteAddr);
+ });
+ mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
+ if req.URL.Path != "/" {
+ path := filepath.Join(*pathFlag, req.URL.Path);
+ Serve(w, req, path);
+ } else {
+ Serve(w, req, filepath.Join(*pathFlag, "index.md"));
+ }
+ });
+
+ server := http.Server{
+ Addr: *addrFlag,
+ Handler: mux,
+ };
+ err := server.ListenAndServe();
+ if err != nil {
+ log.Fatal(err);
+ }
+}