hidrocor

commit 001efae63cd727288a60e25f40b6a7823319ae92

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

all: add --wiki flag, add document struct and rig up middleware

 main.go | 43 +++++++++++++++++++++++--------------------


diff --git a/main.go b/main.go
index 46e22384fb6a89092378eac6dc5d6c3ea833c4df..3b2412c666717c56f3ea0696aeec8c10edd8937d 100644
--- a/main.go
+++ b/main.go
@@ -2,18 +2,29 @@ package main
 
 import (
 	"bytes"
+	"flag"
+	"fmt"
+	"html/template"
 	"log"
 	"net/http"
-	"os"
-	"path"
 
 	"github.com/go-chi/chi/v5"
+	"github.com/go-chi/chi/v5/middleware"
 	"github.com/yuin/goldmark"
 	"github.com/yuin/goldmark/extension"
 	"github.com/yuin/goldmark/parser"
 	"github.com/yuin/goldmark/renderer/html"
 )
 
+type Document struct {
+	Title   string
+	Content template.HTML
+}
+
+var (
+	wikiPath string
+)
+
 func requestError(msg string, w http.ResponseWriter) {
 	log.Printf("500 on " + msg)
 	w.WriteHeader(500)
@@ -21,27 +32,19 @@ 	w.Write([]byte("500 Internal Server Error \n"))
 }
 
 func main() {
-	wikiPath := "/home/eletrotupi/sources/cirandas.net-docs"
+	flag.StringVar(&wikiPath, "wiki", wikiPath, "Wiki path")
+	flag.Parse()
+
+	if wikiPath == "" {
+		log.Fatalf("You'll need to point to the location of the wiki (--wiki)")
 
-	md := goldmark.New(
-		goldmark.WithExtensions(
-			extension.GFM,
-			extension.Linkify,
-			extension.Table,
-			extension.TaskList,
-			extension.DefinitionList,
-			extension.Strikethrough,
-			extension.Footnote,
-		),
-		goldmark.WithParserOptions(
-			parser.WithAutoHeadingID(),
-		),
-		goldmark.WithRendererOptions(
-			html.WithHardWraps(),
-		),
-	)
+		return
+	}
 
 	router := chi.NewRouter()
+	router.Use(middleware.RealIP)
+	router.Use(middleware.Logger)
+
 	router.Get("/*", func(w http.ResponseWriter, r *http.Request) {
 		var (
 			buf    bytes.Buffer