From 39039983636a4140450ea693e8ff62f4fe31d184 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 3 Sep 2022 21:29:52 +0700 Subject: [PATCH] docs: comments on functions --- api/handler/health/health.go | 3 +++ api/handler/health/schema.go | 5 ----- api/handler/joke/dependencies.go | 2 ++ api/handler/joke/get.go | 3 +++ api/handler/joke/schema.go | 16 ---------------- api/handler/joke/total.go | 1 + 6 files changed, 9 insertions(+), 21 deletions(-) delete mode 100644 api/handler/health/schema.go delete mode 100644 api/handler/joke/schema.go diff --git a/api/handler/health/health.go b/api/handler/health/health.go index 06eb202..03be5b5 100644 --- a/api/handler/health/health.go +++ b/api/handler/health/health.go @@ -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() diff --git a/api/handler/health/schema.go b/api/handler/health/schema.go deleted file mode 100644 index cb99e1f..0000000 --- a/api/handler/health/schema.go +++ /dev/null @@ -1,5 +0,0 @@ -package health - -type Error struct { - Error string `json:"error"` -} diff --git a/api/handler/joke/dependencies.go b/api/handler/joke/dependencies.go index 8b05fd7..ce8c737 100644 --- a/api/handler/joke/dependencies.go +++ b/api/handler/joke/dependencies.go @@ -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 diff --git a/api/handler/joke/get.go b/api/handler/joke/get.go index 310e682..a8ce427 100644 --- a/api/handler/joke/get.go +++ b/api/handler/joke/get.go @@ -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") diff --git a/api/handler/joke/schema.go b/api/handler/joke/schema.go deleted file mode 100644 index b0180c1..0000000 --- a/api/handler/joke/schema.go +++ /dev/null @@ -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"` -} diff --git a/api/handler/joke/total.go b/api/handler/joke/total.go index 9016f9e..bc250f5 100644 --- a/api/handler/joke/total.go +++ b/api/handler/joke/total.go @@ -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 {