feat: copy button
This commit is contained in:
parent
b9d7553420
commit
4b530d332c
5 changed files with 65 additions and 19 deletions
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", Route)
|
||||
http.HandleFunc("/", route)
|
||||
|
||||
err := http.ListenAndServe(":3000", nil)
|
||||
if err != nil {
|
||||
|
|
12
src/route.go
12
src/route.go
|
@ -15,17 +15,17 @@ var routes = []struct {
|
|||
regex *regexp.Regexp
|
||||
handler http.HandlerFunc
|
||||
}{
|
||||
{[]string{"GET"}, URL(""), Index},
|
||||
{[]string{"GET"}, URL("/style\\.css"), Style},
|
||||
{[]string{"GET"}, URL("/static/.+"), Static},
|
||||
{[]string{"GET"}, URL("/[^/]+"), HTML},
|
||||
{[]string{"GET"}, url(""), index},
|
||||
{[]string{"GET"}, url("/style\\.css"), style},
|
||||
{[]string{"GET"}, url("/static/.+"), static},
|
||||
{[]string{"GET"}, url("/[^/]+"), html},
|
||||
}
|
||||
|
||||
func URL(s string) *regexp.Regexp {
|
||||
func url(s string) *regexp.Regexp {
|
||||
return regexp.MustCompile("^" + s + "/?$")
|
||||
}
|
||||
|
||||
func Route(w http.ResponseWriter, r *http.Request) {
|
||||
func route(w http.ResponseWriter, r *http.Request) {
|
||||
for _, rt := range routes {
|
||||
matches := rt.regex.FindStringSubmatch(r.URL.Path)
|
||||
if len(matches) > 0 {
|
||||
|
|
|
@ -5,18 +5,18 @@ import (
|
|||
"path/filepath"
|
||||
)
|
||||
|
||||
func Index(w http.ResponseWriter, r *http.Request) {
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, filepath.Join("html", "index.html"))
|
||||
}
|
||||
|
||||
func Style(w http.ResponseWriter, r *http.Request) {
|
||||
func style(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "/html/style.css")
|
||||
}
|
||||
|
||||
func Static(w http.ResponseWriter, r *http.Request) {
|
||||
func static(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, r.URL.Path)
|
||||
}
|
||||
|
||||
func HTML(w http.ResponseWriter, r *http.Request) {
|
||||
func html(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, filepath.Join("html", r.URL.Path + ".html"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue