34 lines
689 B
Go
34 lines
689 B
Go
|
package router
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"sap-cds-search/cmd/search"
|
||
|
"sap-cds-search/cmd/ui"
|
||
|
|
||
|
"github.com/go-chi/chi"
|
||
|
)
|
||
|
|
||
|
func Load() *chi.Mux {
|
||
|
r := chi.NewRouter()
|
||
|
r.Group(func(r chi.Router) {
|
||
|
ui.Load()
|
||
|
r.Get("/", handleRoot)
|
||
|
r.Route("/search", func(r chi.Router) {
|
||
|
r.Get("/", search.HandleSearch)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
r.Handle("/ui/css/*", http.StripPrefix("/ui/css", http.FileServer(http.Dir("./cmd/ui/css"))))
|
||
|
r.Handle("/ui/svg/*", http.StripPrefix("/ui/svg", http.FileServer(http.Dir("./cmd/ui/svg"))))
|
||
|
return r
|
||
|
}
|
||
|
|
||
|
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
||
|
err := ui.Template.ExecuteTemplate(w, "main", nil)
|
||
|
if err != nil {
|
||
|
fmt.Println(err)
|
||
|
return
|
||
|
}
|
||
|
}
|