format fix
This commit is contained in:
parent
245d6e0fa0
commit
73fdf8bb46
1 changed files with 62 additions and 84 deletions
46
main.go
46
main.go
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
|
@ -14,6 +13,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
_ "embed"
|
||||||
|
|
||||||
"github.com/gomarkdown/markdown"
|
"github.com/gomarkdown/markdown"
|
||||||
"github.com/gomarkdown/markdown/html"
|
"github.com/gomarkdown/markdown/html"
|
||||||
|
|
@ -41,9 +41,7 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 { printHelp() }
|
||||||
printHelp()
|
|
||||||
}
|
|
||||||
|
|
||||||
host := "127.0.0.1"
|
host := "127.0.0.1"
|
||||||
port := 8080
|
port := 8080
|
||||||
|
|
@ -52,9 +50,7 @@ func main() {
|
||||||
filesDir := ""
|
filesDir := ""
|
||||||
i := 1
|
i := 1
|
||||||
for {
|
for {
|
||||||
if i >= len(os.Args) {
|
if i >= len(os.Args) { break }
|
||||||
break
|
|
||||||
}
|
|
||||||
switch os.Args[i] {
|
switch os.Args[i] {
|
||||||
case "-h":
|
case "-h":
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -89,12 +85,8 @@ func main() {
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
root = os.Args[i]
|
root = os.Args[i]
|
||||||
if !strings.HasPrefix(root, "/") {
|
if !strings.HasPrefix(root, "/") { root = "/" + root }
|
||||||
root = "/" + root
|
if !strings.HasSuffix(root, "/") { root += "/" }
|
||||||
}
|
|
||||||
if !strings.HasSuffix(root, "/") {
|
|
||||||
root += "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if len(filesDir) > 0 {
|
if len(filesDir) > 0 {
|
||||||
|
|
@ -122,9 +114,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Now hosting \"%s\" at http://%s:%d", filesDir, host, port)
|
fmt.Printf("Now hosting \"%s\" at http://%s:%d", filesDir, host, port)
|
||||||
if root != "/" {
|
if root != "/" { fmt.Printf("%s", root) }
|
||||||
fmt.Printf("%s", root)
|
|
||||||
}
|
|
||||||
fmt.Println(".")
|
fmt.Println(".")
|
||||||
|
|
||||||
http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), HTTPLog(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), HTTPLog(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -212,14 +202,10 @@ func main() {
|
||||||
directories, err := fs.ReadDir(fsDir, ".")
|
directories, err := fs.ReadDir(fsDir, ".")
|
||||||
for _, dir := range directories {
|
for _, dir := range directories {
|
||||||
name := dir.Name()
|
name := dir.Name()
|
||||||
if slices.Contains(ignoredFiles, name) {
|
if slices.Contains(ignoredFiles, name) { continue }
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := dir.Info()
|
info, err := dir.Info()
|
||||||
if err != nil {
|
if err != nil { continue }
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var uri string
|
var uri string
|
||||||
if isRoot {
|
if isRoot {
|
||||||
|
|
@ -300,18 +286,10 @@ func HTTPLog(next http.Handler) http.Handler {
|
||||||
|
|
||||||
statusColour := COL_Reset
|
statusColour := COL_Reset
|
||||||
|
|
||||||
if lrw.Status-600 <= 0 {
|
if lrw.Status - 600 <= 0 { statusColour = COL_Red }
|
||||||
statusColour = COL_Red
|
if lrw.Status - 500 <= 0 { statusColour = COL_Yellow }
|
||||||
}
|
if lrw.Status - 400 <= 0 { statusColour = COL_White }
|
||||||
if lrw.Status-500 <= 0 {
|
if lrw.Status - 300 <= 0 { statusColour = COL_Green }
|
||||||
statusColour = COL_Yellow
|
|
||||||
}
|
|
||||||
if lrw.Status-400 <= 0 {
|
|
||||||
statusColour = COL_White
|
|
||||||
}
|
|
||||||
if lrw.Status-300 <= 0 {
|
|
||||||
statusColour = COL_Green
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("[%s] %s %s - %s%d%s (%sms) (%s)\n",
|
fmt.Printf("[%s] %s %s - %s%d%s (%sms) (%s)\n",
|
||||||
after.Format(time.UnixDate),
|
after.Format(time.UnixDate),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue