the shrimplest admin api you've ever seen
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
1cbcece3d2
commit
c5a2491627
5 changed files with 266 additions and 12 deletions
43
main.go
43
main.go
|
@ -1,20 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"arimelody.me/arimelody.me/api/v1/music"
|
||||
"arimelody.me/arimelody.me/api"
|
||||
"arimelody.me/arimelody.me/api/v1/music"
|
||||
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
)
|
||||
|
||||
const PORT int = 8080
|
||||
|
@ -94,6 +95,14 @@ func handle_request(writer http.ResponseWriter, req *http.Request) {
|
|||
return music_gateway_handler(writer, req, root)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(uri, "/admin") {
|
||||
return admin_handler(writer, req, root)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(uri, "/api") {
|
||||
return api.Handle(writer, req, root)
|
||||
}
|
||||
|
||||
return static_handler(writer, req, root)
|
||||
}(writer, req)
|
||||
|
||||
|
@ -138,6 +147,16 @@ func music_gateway_handler(writer http.ResponseWriter, req *http.Request, root *
|
|||
return 200
|
||||
}
|
||||
|
||||
func admin_handler(writer http.ResponseWriter, req *http.Request, root *template.Template) int {
|
||||
admin_template := template.Must(root.ParseFiles("views/admin.html"))
|
||||
err := admin_template.Execute(writer, nil)
|
||||
if err != nil {
|
||||
http.Error(writer, err.Error(), http.StatusInternalServerError)
|
||||
return 500
|
||||
}
|
||||
return 200
|
||||
}
|
||||
|
||||
func static_handler(writer http.ResponseWriter, req *http.Request, root *template.Template) int {
|
||||
filename := "public/" + req.URL.Path[1:]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue