refactor: documentation & tidy up some code
This commit is contained in:
parent
8ac21a1046
commit
ccaead16ea
|
@ -24,12 +24,15 @@ $ go build main.go
|
|||
| [gofiber/fiber](https://github.com/gofiber/fiber) | `v2.14.0` | Framework |
|
||||
| [jackc/pgx](https://github.com/jackc/pgx) | `v4.11.0` | Database |
|
||||
| [go-redis/redis](https://github.com/go-redis/redis) | `v8.11.0` | Cache |
|
||||
| [patrickmn/go-cache](https://github.com/patrickmn/go-cache) | `v2.1.0+incompatible` | Cache |
|
||||
| [joho/godotenv](https://github.com/joho/godotenv) | `v1.3.0` | Config |
|
||||
| [getsentry/sentry-go](https://github.com/getsentry/sentry-go) | `v0.11.0` | Logging |
|
||||
| [aldy505/phc-crypto](https://github.com/aldy505/phc-crypto) | `v1.1.0` | Utils |
|
||||
| [Masterminds/squirrel](https://github.com/Masterminds/squirrel ) | `v1.5.0` | Utils |
|
||||
| [aldy505/bob](https://github.com/aldy505/bob) | `v0.0.1` | Utils |
|
||||
| [gojek/heimdall](github.com/gojek/heimdall) | `v7.0.2` | Utils |
|
||||
| [gojek/heimdall](https://github.com/gojek/heimdall) | `v7.0.2` | Utils |
|
||||
| [georgysavva/scany](https://github.com/georgysavva/scany) | `v0.2.9` | Utils |
|
||||
| [stretchr/testify](https://github.com/stretchr/testify) | `v1.5.1` | Tests |
|
||||
|
||||
## Directory structure
|
||||
|
||||
|
@ -38,6 +41,7 @@ $ go build main.go
|
|||
├── app
|
||||
│ └── v1
|
||||
│ ├── app.go - v1 application entry point
|
||||
│ ├── core - Pure business logic
|
||||
│ ├── handler - Route handler
|
||||
│ ├── middleware - App middleware handler
|
||||
│ ├── models - Output and input schema
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
// GetAllJSONJokes
|
||||
// GetAllJSONJokes fetch the database for all the jokes then output it as a JSON []byte.
|
||||
// Keep in mind, you will need to store it to memory yourself.
|
||||
func GetAllJSONJokes(db *pgxpool.Pool) ([]byte, error) {
|
||||
var jokes []models.Joke
|
||||
results, err := db.Query(context.Background(), "SELECT \"id\",\"link\" FROM \"jokesbapak2\" ORDER BY \"id\"")
|
||||
|
@ -32,7 +33,7 @@ func GetAllJSONJokes(db *pgxpool.Pool) ([]byte, error) {
|
|||
return data, nil
|
||||
}
|
||||
|
||||
// GetRandomJokeFromCache
|
||||
// GetRandomJokeFromCache returns a link string of a random joke from cache.
|
||||
func GetRandomJokeFromCache(memory *cache.Cache) (string, error) {
|
||||
jokes, found := memory.Get("jokes")
|
||||
if !found {
|
||||
|
@ -62,6 +63,7 @@ func CheckJokesCache(memory *cache.Cache) bool {
|
|||
return found
|
||||
}
|
||||
|
||||
// GetCachedJokeByID returns a link string of a certain ID from cache.
|
||||
func GetCachedJokeByID(memory *cache.Cache, id int) (string, error) {
|
||||
jokes, found := memory.Get("jokes")
|
||||
if !found {
|
||||
|
|
|
@ -22,6 +22,7 @@ func AddNewJoke(c *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// TODO: Implement solution if the link provided already exists.
|
||||
_, err = db.Query(context.Background(), sql, args...)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -9,5 +9,6 @@ import (
|
|||
func Health(app *fiber.App) *fiber.App {
|
||||
// Health check
|
||||
app.Get("/health", handler.Health)
|
||||
|
||||
return app
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue