feat: UI design
This commit is contained in:
parent
f389c9c876
commit
6e0ce47f91
6 changed files with 331 additions and 10 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
|
@ -9,6 +11,7 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/knadh/koanf"
|
||||
)
|
||||
|
||||
|
|
@ -18,6 +21,10 @@ var (
|
|||
// Version and date of the build. This is injected at build-time.
|
||||
buildVersion = "unknown"
|
||||
buildDate = "unknown"
|
||||
//go:embed assets/*
|
||||
assetsDir embed.FS
|
||||
//go:embed index.html
|
||||
html []byte
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -26,11 +33,30 @@ func main() {
|
|||
// Initialize app.
|
||||
app := app.New(logger, buildVersion)
|
||||
|
||||
// Register handles.
|
||||
// Register router instance.
|
||||
r := chi.NewRouter()
|
||||
r.Get("/", wrap(app, handleIndex))
|
||||
r.Get("/ping/", wrap(app, handleHealthCheck))
|
||||
r.Post("/lookup/", wrap(app, handleLookup))
|
||||
|
||||
// Register middlewares
|
||||
r.Use(middleware.RequestID)
|
||||
r.Use(middleware.RealIP)
|
||||
r.Use(middleware.Logger)
|
||||
r.Use(middleware.Recoverer)
|
||||
|
||||
// Frontend Handlers.
|
||||
assets, _ := fs.Sub(assetsDir, "assets")
|
||||
r.Get("/assets/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
fs := http.StripPrefix("/assets/", http.FileServer(http.FS(assets)))
|
||||
fs.ServeHTTP(w, r)
|
||||
})
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
w.Write(html)
|
||||
})
|
||||
|
||||
// API Handlers.
|
||||
r.Get("/api/", wrap(app, handleIndexAPI))
|
||||
r.Get("/api/ping/", wrap(app, handleHealthCheck))
|
||||
r.Post("/api/lookup/", wrap(app, handleLookup))
|
||||
|
||||
// HTTP Server.
|
||||
srv := &http.Server{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue