This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
adlin/token-validator/static.go

167 lines
5.1 KiB
Go
Raw Normal View History

// +build !dev
2018-02-20 12:49:03 +00:00
package main
import (
"fmt"
2018-02-20 12:49:03 +00:00
"net/http"
"path"
2019-03-13 21:06:35 +00:00
"strings"
"strconv"
2018-02-20 12:49:03 +00:00
"github.com/julienschmidt/httprouter"
)
//go:generate go-bindata -ignore "\\.go|\\.less" -pkg "main" -o "bindata.go" htdocs/...
//go:generate go fmt bindata.go
2018-02-20 12:49:03 +00:00
func init() {
2019-03-13 21:06:35 +00:00
Router().GET("/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "text/css")
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
})
Router().GET("/fonts/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
})
Router().GET("/img/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
2018-02-20 12:49:03 +00:00
})
2019-03-13 21:06:35 +00:00
Router().GET("/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "text/javascript")
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
})
Router().GET("/views/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "text/html")
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
})
Router().GET("/dashboard/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset("htdocs/dashboard.html"); err != nil {
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
} else {
w.Write(data)
}
})
Router().GET("/dashboard/:where", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if _, err := strconv.ParseInt(string(ps.ByName("where")), 10, 64); err != nil {
2019-03-13 21:06:35 +00:00
http.NotFound(w, r)
} else {
if data, err := Asset("htdocs/dashboard.html"); err != nil {
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
} else {
w.Write(data)
}
2019-03-13 21:06:35 +00:00
}
})
Router().GET("/dashboard/:where/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if ps.ByName("where") == "css" {
w.Header().Set("Content-Type", "text/css")
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/dashboard"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
} else if ps.ByName("where") == "js" {
w.Header().Set("Content-Type", "text/javascript")
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/dashboard"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
2019-03-13 21:06:35 +00:00
} else {
http.NotFound(w, r)
2019-03-13 21:06:35 +00:00
}
})
2019-03-13 21:06:35 +00:00
Router().GET("/maatma/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset("htdocs/maatma.html"); err != nil {
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
} else {
w.Write(data)
}
})
Router().GET("/maatma/auth", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset("htdocs/maatma.html"); err != nil {
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
} else {
w.Write(data)
}
})
Router().GET("/maatma/domains", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset("htdocs/maatma.html"); err != nil {
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
} else {
w.Write(data)
}
})
Router().GET("/maatma/tunnels", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset("htdocs/maatma.html"); err != nil {
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
} else {
w.Write(data)
}
})
Router().GET("/maatma/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "text/css")
2019-03-13 21:06:35 +00:00
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
2018-02-20 12:49:03 +00:00
})
2019-03-13 21:06:35 +00:00
Router().GET("/maatma/fonts/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
2018-02-20 12:49:03 +00:00
})
2019-03-13 21:06:35 +00:00
Router().GET("/maatma/img/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
2018-02-20 12:49:03 +00:00
})
2019-03-13 21:06:35 +00:00
Router().GET("/maatma/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "text/javascript")
2019-03-13 21:06:35 +00:00
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
2018-02-20 12:49:03 +00:00
})
2019-03-13 21:06:35 +00:00
Router().GET("/maatma/views/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "text/html")
2019-03-13 21:06:35 +00:00
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/maatma"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
2018-02-20 12:49:03 +00:00
})
}
func sanitizeStaticOptions() error {
return nil
}