made cross-platform development easier
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
4b5e6a50ff
commit
9d56ca63af
5 changed files with 85 additions and 22 deletions
38
main.go
38
main.go
|
@ -1,16 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"arimelody.me/arimelody.me/api/v1/music"
|
||||
|
||||
"fmt"
|
||||
"html/template"
|
||||
"os"
|
||||
"net/http"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"arimelody.me/arimelody.me/api/v1/music"
|
||||
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
|
@ -20,14 +20,14 @@ import (
|
|||
const PORT int = 8080
|
||||
|
||||
var mime_types = map[string]string{
|
||||
"css": "text/css; charset=utf-8",
|
||||
"png": "image/png",
|
||||
"jpg": "image/jpg",
|
||||
"css": "text/css; charset=utf-8",
|
||||
"png": "image/png",
|
||||
"jpg": "image/jpg",
|
||||
"webp": "image/webp",
|
||||
"html": "text/html",
|
||||
"asc": "text/plain",
|
||||
"pub": "text/plain",
|
||||
"js": "application/javascript",
|
||||
"asc": "text/plain",
|
||||
"pub": "text/plain",
|
||||
"js": "application/javascript",
|
||||
}
|
||||
|
||||
var templates = template.Must(template.ParseFiles(
|
||||
|
@ -47,13 +47,13 @@ func log_request(req *http.Request, code int, start_time time.Time) {
|
|||
}
|
||||
|
||||
fmt.Printf("[%s] %s %s - %d (%sms) (%s)\n",
|
||||
now.Format(time.UnixDate),
|
||||
req.Method,
|
||||
req.URL.Path,
|
||||
now.Format(time.UnixDate),
|
||||
req.Method,
|
||||
req.URL.Path,
|
||||
code,
|
||||
elapsed,
|
||||
req.Header["User-Agent"][0],
|
||||
)
|
||||
req.Header["User-Agent"][0],
|
||||
)
|
||||
}
|
||||
|
||||
func web_handler(writer http.ResponseWriter, req *http.Request) {
|
||||
|
@ -155,7 +155,7 @@ func static_handler(writer http.ResponseWriter, req *http.Request) int {
|
|||
}
|
||||
|
||||
// setting MIME types
|
||||
filetype := filename[strings.LastIndex(filename, ".") + 1:]
|
||||
filetype := filename[strings.LastIndex(filename, ".")+1:]
|
||||
if mime_type, ok := mime_types[filetype]; ok {
|
||||
writer.Header().Set("Content-Type", mime_type)
|
||||
} else {
|
||||
|
@ -172,7 +172,7 @@ func parse_markdown(md []byte) []byte {
|
|||
doc := p.Parse(md)
|
||||
|
||||
htmlFlags := html.CommonFlags
|
||||
opts := html.RendererOptions{ Flags: htmlFlags }
|
||||
opts := html.RendererOptions{Flags: htmlFlags}
|
||||
renderer := html.NewRenderer(opts)
|
||||
|
||||
return markdown.Render(doc, renderer)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue