docs: comments on functions
This commit is contained in:
parent
af4789b6f2
commit
3903998363
|
@ -9,11 +9,14 @@ import (
|
|||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
// Dependencies provides a struct for dependency injection
|
||||
// on health package
|
||||
type Dependencies struct {
|
||||
Bucket *minio.Client
|
||||
Cache *redis.Client
|
||||
}
|
||||
|
||||
// Health provides a http handler for healthcheck
|
||||
func (d *Dependencies) Health(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), time.Second*15)
|
||||
defer cancel()
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package health
|
||||
|
||||
type Error struct {
|
||||
Error string `json:"error"`
|
||||
}
|
|
@ -6,6 +6,8 @@ import (
|
|||
"github.com/minio/minio-go/v7"
|
||||
)
|
||||
|
||||
// Dependencies provides a struct for dependency injection
|
||||
// on joke package
|
||||
type Dependencies struct {
|
||||
Redis *redis.Client
|
||||
Memory *bigcache.BigCache
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// TodayJoke provides http handler for today's joke
|
||||
func (d *Dependencies) TodayJoke(w http.ResponseWriter, r *http.Request) {
|
||||
joke, contentType, err := core.GetTodaysJoke(r.Context(), d.Bucket, d.Redis, d.Memory)
|
||||
if err != nil {
|
||||
|
@ -22,6 +23,7 @@ func (d *Dependencies) TodayJoke(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write(joke)
|
||||
}
|
||||
|
||||
// SingleJoke provides http handler for acquiring random single joke
|
||||
func (d *Dependencies) SingleJoke(w http.ResponseWriter, r *http.Request) {
|
||||
joke, contentType, err := core.GetRandomJoke(r.Context(), d.Bucket, d.Redis, d.Memory)
|
||||
if err != nil {
|
||||
|
@ -37,6 +39,7 @@ func (d *Dependencies) SingleJoke(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
}
|
||||
|
||||
// JokeByID provides http handler for acquiring a joke by ID
|
||||
func (d *Dependencies) JokeByID(w http.ResponseWriter, r *http.Request) {
|
||||
id := chi.URLParamFromCtx(r.Context(), "id")
|
||||
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package joke
|
||||
|
||||
type ResponseJoke struct {
|
||||
Link string `json:"link,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type Today struct {
|
||||
Date string `redis:"today:date"`
|
||||
Image string `redis:"today:image"`
|
||||
ContentType string `redis:"today:contentType"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Error string `json:"error"`
|
||||
}
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
// TotalJokes provides a HTTP handler for acquiring total jokes
|
||||
func (d *Dependencies) TotalJokes(w http.ResponseWriter, r *http.Request) {
|
||||
total, err := core.GetTotalJoke(r.Context(), d.Bucket, d.Redis, d.Memory)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue