2022-04-02 12:05:32 -07:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-06-19 22:02:44 -07:00
|
|
|
"net/http"
|
|
|
|
|
2022-04-02 12:05:32 -07:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RootRoutes() chi.Router {
|
|
|
|
app := chi.NewRouter()
|
2022-06-19 22:02:44 -07:00
|
|
|
app.Route("/", func(r chi.Router) {
|
|
|
|
r.Get("/helloworld", helloWorld)
|
|
|
|
r.Get("/ping", ping)
|
|
|
|
r.Route("/hello/{who}", func(r chi.Router) {
|
|
|
|
r.Get("/", helloWho)
|
|
|
|
})
|
2022-04-02 12:05:32 -07:00
|
|
|
})
|
2022-06-19 22:02:44 -07:00
|
|
|
return app
|
|
|
|
}
|
2022-04-02 12:05:32 -07:00
|
|
|
|
2022-06-19 22:02:44 -07:00
|
|
|
// HelloWorld
|
|
|
|
// @Summary Responds back with "Hello world!"
|
|
|
|
// @Produce plain
|
|
|
|
// @Tags debug
|
|
|
|
// @Router /helloworld [get]
|
|
|
|
func helloWorld(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Write([]byte("Hello World!"))
|
|
|
|
}
|
2022-04-02 12:05:32 -07:00
|
|
|
|
2022-06-19 22:02:44 -07:00
|
|
|
// Ping
|
|
|
|
// @Summary Sends back "pong". Good to test with.
|
|
|
|
// @Produce plain
|
|
|
|
// @Tags debug
|
|
|
|
// @Router /ping [get]
|
|
|
|
func ping(w http.ResponseWriter, r *http.Request) {
|
|
|
|
msg := "pong"
|
|
|
|
w.Write([]byte(msg))
|
|
|
|
}
|
|
|
|
|
|
|
|
// HelloWho
|
|
|
|
// @Summary Responds back with "Hello x" depending on param passed in.
|
|
|
|
// @Param who path string true "Who"
|
|
|
|
// @Produce plain
|
|
|
|
// @Tags debug
|
|
|
|
// @Router /hello/{who} [get]
|
|
|
|
func helloWho(w http.ResponseWriter, r *http.Request) {
|
|
|
|
msg := fmt.Sprintf("Hello %v", chi.URLParam(r, "who"))
|
|
|
|
w.Write([]byte(msg))
|
|
|
|
}
|