feat: working app

This commit is contained in:
Reinaldy Rafli 2021-07-15 01:17:01 +07:00
parent 94b31717f0
commit 4858eaf42e
17 changed files with 238 additions and 104 deletions

View File

@ -1,7 +1,8 @@
package v1
import (
"github.com/aldy505/jokes-bapak2-api/api/app/v1/routes"
"jokes-bapak2-api/app/v1/routes"
"github.com/gofiber/fiber/v2"
)

View File

@ -3,7 +3,8 @@ package handler
import (
"context"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/models"
"jokes-bapak2-api/app/v1/models"
"github.com/gofiber/fiber/v2"
)
@ -14,7 +15,7 @@ func AddNewJoke(c *fiber.Ctx) error {
return err
}
sql, args, err := psql.Insert("jokesbapak2").Columns("link", "key").Values(body.Link, body.Key).ToSql()
sql, args, err := psql.Insert("jokesbapak2").Columns("link", "creator").Values(body.Link, c.Locals("userID")).ToSql()
if err != nil {
return err
}

View File

@ -3,8 +3,9 @@ package handler
import (
"context"
"jokes-bapak2-api/app/v1/models"
"github.com/Masterminds/squirrel"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/models"
"github.com/gofiber/fiber/v2"
)

View File

@ -2,55 +2,74 @@ package handler
import (
"context"
"io/ioutil"
"log"
"time"
"github.com/Masterminds/squirrel"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/cache"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/database"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/utils"
"github.com/gofiber/fiber/v2"
)
"jokes-bapak2-api/app/v1/models"
"jokes-bapak2-api/app/v1/platform/cache"
"jokes-bapak2-api/app/v1/platform/database"
"jokes-bapak2-api/app/v1/utils"
type Today struct {
link string `redis:"link"`
date string `redis:"date"`
}
"github.com/Masterminds/squirrel"
"github.com/gofiber/fiber/v2"
"github.com/gojek/heimdall/v7/httpclient"
)
var psql = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
var db = database.New()
var redis = cache.New()
var client = httpclient.NewClient(httpclient.WithHTTPTimeout(10 * time.Second))
func TodayJoke(c *fiber.Ctx) error {
// check from redis if today's joke already exists
// send the joke if exists
// get a new joke if it's not, then send it.
var joke Today
err := redis.MGet(context.Background(), "today:link", "today:date").Scan(&joke)
var joke models.Today
err := redis.MGet(context.Background(), "today:link", "today:date", "today:image", "today:contentType").Scan(&joke)
if err != nil {
return err
}
eq, err := utils.IsToday(joke.date)
eq, err := utils.IsToday(joke.Date)
if err != nil {
return err
}
if eq {
c.Attachment(joke.link)
return c.SendStatus(fiber.StatusOK)
log.Println("through cached")
c.Set("Content-Type", joke.ContentType)
return c.Status(fiber.StatusOK).Send([]byte(joke.Image))
} else {
var link string
err := db.QueryRow(context.Background(), "SELECT link FROM jokesbapak2 WHERE random() < 0.01 LIMIT 1").Scan(&link)
err := db.QueryRow(context.Background(), "SELECT link FROM jokesbapak2 ORDER BY random() LIMIT 1").Scan(&link)
if err != nil {
return err
}
response, err := client.Get(link, nil)
if err != nil {
return err
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
now := time.Now().UTC().Format(time.RFC3339)
err = redis.MSet(context.Background(), "today:link", link, "today:date", now).Err()
err = redis.MSet(context.Background(), map[string]interface{}{
"today:link": link,
"today:date": now,
"today:image": string(data),
"today:contentType": response.Header.Get("content-type"),
}).Err()
if err != nil {
return err
}
c.Attachment(link)
return c.SendStatus(fiber.StatusOK)
c.Set("Content-Type", response.Header.Get("content-type"))
return c.Status(fiber.StatusOK).Send(data)
}
}
@ -60,12 +79,24 @@ func SingleJoke(c *fiber.Ctx) error {
// fetch the image url
// send the image as proxied file
var link string
err := db.QueryRow(context.Background(), "SELECT link FROM jokesbapak2 WHERE random() < 0.01 LIMIT 1").Scan(&link)
err := db.QueryRow(context.Background(), "SELECT \"link\" FROM \"jokesbapak2\" ORDER BY random() LIMIT 1").Scan(&link)
if err != nil {
return err
}
c.Attachment(link)
return c.SendStatus(fiber.StatusOK)
// Get image data
response, err := client.Get(link, nil)
if err != nil {
return err
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
c.Set("Content-Type", response.Header.Get("content-type"))
return c.Status(fiber.StatusOK).Send(data)
}
func JokeByID(c *fiber.Ctx) error {
@ -73,13 +104,28 @@ func JokeByID(c *fiber.Ctx) error {
// fetch image url
// send the image as proxied file
var link string
err := db.QueryRow(context.Background(), "SELECT link FROM jokesbapak2 WHERE id = ?", c.Params("id")).Scan(link)
err := db.QueryRow(context.Background(), "SELECT \"link\" FROM \"jokesbapak2\" WHERE \"id\" = $1", c.Params("id")).Scan(&link)
if err != nil {
if err.Error() == "no rows in result set" {
return c.Status(fiber.StatusNotFound).Send([]byte("Requested ID was not found."))
}
return err
}
if link == "" {
return c.Status(fiber.StatusNotFound).Send([]byte("Requested ID was not found."))
}
c.Attachment(link)
return c.SendStatus(fiber.StatusOK)
// Get image data
response, err := client.Get(link, nil)
if err != nil {
return err
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
c.Set("Content-Type", response.Header.Get("content-type"))
return c.Status(fiber.StatusOK).Send(data)
}

View File

@ -3,8 +3,9 @@ package handler
import (
"context"
"jokes-bapak2-api/app/v1/models"
"github.com/Masterminds/squirrel"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/models"
"github.com/gofiber/fiber/v2"
)
@ -29,7 +30,7 @@ func UpdateJoke(c *fiber.Ctx) error {
return err
}
sql, args, err = psql.Update("jokesbapak2").Set("link", body.Link).Set("key", body.Key).ToSql()
sql, args, err = psql.Update("jokesbapak2").Set("link", body.Link).Set("creator", c.Locals("userID")).ToSql()
if err != nil {
return err
}

View File

@ -2,10 +2,13 @@ package middleware
import (
"context"
"log"
"time"
"jokes-bapak2-api/app/v1/models"
"jokes-bapak2-api/app/v1/platform/database"
"github.com/Masterminds/squirrel"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/models"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/database"
phccrypto "github.com/aldy505/phc-crypto"
"github.com/gofiber/fiber/v2"
)
@ -21,30 +24,22 @@ func RequireAuth() fiber.Handler {
return err
}
// Check if token exists
sql, args, err := psql.Select("token").From("authorization").Where("token", auth.Token).ToSql()
// Check if key exists
sql, args, err := psql.Select("token").From("administrators").Where(squirrel.Eq{"key": auth.Key}).ToSql()
if err != nil {
return err
}
log.Println(args)
var token string
err = db.QueryRow(context.Background(), sql, args...).Scan(&token)
if err != nil {
return err
}
if token == "" {
if err.Error() == "no rows in result set" {
return c.Status(fiber.StatusForbidden).JSON(models.ResponseError{
Error: "Invalid token",
Error: "Invalid key",
})
}
sql, args, err = psql.Select("key").From("authorization").Where("token", token).ToSql()
if err != nil {
return err
}
var key string
err = db.QueryRow(context.Background(), sql, args...).Scan(&key)
if err != nil {
log.Println("31 - auth.go")
return err
}
@ -53,13 +48,34 @@ func RequireAuth() fiber.Handler {
return err
}
verify, err := crypto.Verify(key, auth.Key)
verify, err := crypto.Verify(token, auth.Token)
if err != nil {
return err
}
if verify {
c.Next()
sql, args, err = psql.Update("administrator").Set("last_used", time.Now().UTC().Format(time.RFC3339)).ToSql()
if err != nil {
return err
}
_, err = db.Query(context.Background(), sql, args...)
if err != nil {
return err
}
sql, args, err = psql.Select("id").From("administrators").Where(squirrel.Eq{"key": auth.Key}).ToSql()
if err != nil {
return err
}
var id int
err = db.QueryRow(context.Background(), sql, args...).Scan(&id)
if err != nil {
return err
}
c.Locals("userID", id)
return c.Next()
}
return c.Status(fiber.StatusForbidden).JSON(models.ResponseError{

View File

@ -1,11 +1,16 @@
package models
type RequestJokePost struct {
Key string `json:"string"`
Link string `json:"link"`
Link string `json:"link" form:"link"`
}
type RequestAuth struct {
Key string `json:"key"`
Token string `json:"token"`
Key string `json:"key" form:"key"`
Token string `json:"token" form:"token"`
}
type Today struct {
Date string `redis:"today:date"`
Image string `redis:"today:image"`
ContentType string `redis:"today:contentType"`
}

View File

@ -3,7 +3,6 @@ package database
import (
"context"
"log"
"strings"
"github.com/aldy505/bob"
)
@ -12,48 +11,99 @@ import (
func Setup() error {
db := New()
// Jokesbapak2 table & data
sql, _, err := bob.CreateTableIfNotExists("jokesbapak2").
Columns("id", "link", "key").
Types("SERIAL", "TEXT", "VARCHAR(255)").
Primary("id").ToSql()
// Jokesbapak2 table
// Check if table exists
var tableJokesExists bool
err := db.QueryRow(context.Background(), `SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name = 'jokesbapak2'
);`).Scan(&tableJokesExists)
if err != nil {
log.Fatalln("10 - failed on table creation: ", err)
log.Fatalln("10 - failed on checking table: ", err)
return err
}
splitSql := strings.Split(sql, ";")
for i := range splitSql {
_, err = db.Query(context.Background(), splitSql[i])
if !tableJokesExists {
sql, _, err := bob.CreateTable("jokesbapak2").
Columns("id", "link").
Types("SERIAL", "TEXT").
ToSql()
if err != nil {
log.Fatalln("11 - failed on table creation: ", err)
return err
}
_, err = db.Query(context.Background(), sql)
if err != nil {
log.Fatalln("12 - failed on table creation: ", err)
return err
}
_, err = db.Query(context.Background(), "ALTER TABLE \"jokesbapak2\" ADD creator INT NOT NULL DEFAULT 0;")
if err != nil {
log.Fatalln("13 - failed on table creation: ", err)
return err
}
// Authorization
sql, _, err = bob.CreateTableIfNotExists("authorization").
Columns("id", "token", "key").
Types("SERIAL", "TEXT", "VARCHAR(255)").
Primary("id").
Unique("token").
_, err = db.Query(context.Background(), "ALTER TABLE \"jokesbapak2\" ADD PRIMARY KEY (\"id\")")
if err != nil {
log.Fatalln("14 - failed on table alteration: ", err)
return err
}
_, err = db.Query(context.Background(), "ALTER TABLE \"jokesbapak2\" ADD UNIQUE (\"link\")")
if err != nil {
log.Fatalln("15 - failed on table alteration: ", err)
return err
}
}
// administrators table
var tableAuthExists bool
err = db.QueryRow(context.Background(), `SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name = 'administrators'
);`).Scan(&tableAuthExists)
if err != nil {
log.Fatalln("16 - failed on checking table: ", err)
return err
}
if !tableAuthExists {
sql, _, err := bob.CreateTable("administrators").
Columns("id", "key", "token", "last_used").
Types("SERIAL", "VARCHAR(255)", "TEXT", "VARCHAR(255)").
ToSql()
if err != nil {
log.Fatalln("14 - failed on table creation: ", err)
log.Fatalln("17 - failed on table creation: ", err)
return err
}
splitSql = strings.Split(sql, ";")
for i := range splitSql {
_, err = db.Query(context.Background(), splitSql[i])
_, err = db.Query(context.Background(), sql)
if err != nil {
log.Fatalln("15 - failed on table creation: ", err)
log.Fatalln("18 - failed on table creation: ", err)
return err
}
_, err = db.Query(context.Background(), "ALTER TABLE \"administrators\" ADD PRIMARY KEY (\"id\");")
if err != nil {
log.Fatalln("19 - failed on table alteration: ", err)
return err
}
_, err = db.Query(context.Background(), "ALTER TABLE jokesbapak2 ADD CONSTRAINT fk_jokesbapak2_key FOREIGN KEY (key) REFERENCES authorization (id)")
_, err = db.Query(context.Background(), "ALTER TABLE \"administrators\" ADD UNIQUE (\"key\");")
if err != nil {
log.Fatalln("16 - failed on foreign key iteration: ", err)
log.Fatalln("20 - failed on table alteration: ", err)
return err
}
_, err = db.Query(context.Background(), "ALTER TABLE \"jokesbapak2\" ADD CONSTRAINT fk_auth_key FOREIGN KEY (\"creator\") REFERENCES \"administrators\" (\"id\");")
if err != nil {
log.Fatalln("21 - failed on foreign key iteration: ", err)
return err
}
}
return nil
}

View File

@ -1,12 +1,13 @@
package routes
import (
"github.com/aldy505/jokes-bapak2-api/api/app/v1/handler"
"jokes-bapak2-api/app/v1/handler"
"github.com/gofiber/fiber/v2"
)
func Health(app *fiber.App) *fiber.App {
// Health check
app.Get("/", handler.Health)
app.Get("/health", handler.Health)
return app
}

View File

@ -1,17 +1,12 @@
package routes
import (
"github.com/aldy505/jokes-bapak2-api/api/app/v1/handler"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/middleware"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/cache"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/database"
"jokes-bapak2-api/app/v1/handler"
"jokes-bapak2-api/app/v1/middleware"
"github.com/gofiber/fiber/v2"
)
var db = database.New()
var redis = cache.New()
func Joke(app *fiber.App) *fiber.App {
// Single route
app.Get("/", handler.SingleJoke)

View File

@ -4,6 +4,10 @@ import "time"
// IsToday checks if a date is in fact today or not.
func IsToday(date string) (bool, error) {
if date == "" {
return false, nil
}
parse, err := time.Parse(time.RFC3339, date)
if err != nil {
return false, err

View File

@ -4,7 +4,7 @@ import (
"testing"
"time"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/utils"
"jokes-bapak2-api/app/v1/utils"
)
func TestIsToday(t *testing.T) {

View File

@ -3,7 +3,7 @@ package utils_test
import (
"testing"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/utils"
"jokes-bapak2-api/app/v1/utils"
)
func TestParseToJSONBody(t *testing.T) {

View File

@ -4,7 +4,7 @@ import (
"net/http"
"testing"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/utils"
"jokes-bapak2-api/app/v1/utils"
)
func TestRequest(t *testing.T) {

View File

@ -1,4 +1,4 @@
module github.com/aldy505/jokes-bapak2-api/api
module jokes-bapak2-api
go 1.16
@ -9,6 +9,7 @@ require (
github.com/getsentry/sentry-go v0.11.0
github.com/go-redis/redis/v8 v8.11.0
github.com/gofiber/fiber/v2 v2.14.0
github.com/gojek/heimdall/v7 v7.0.2
github.com/jackc/pgx/v4 v4.11.0
github.com/joho/godotenv v1.3.0
)

View File

@ -4,6 +4,7 @@ github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOv
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo=
github.com/DataDog/datadog-go v3.7.1+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
@ -15,8 +16,6 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/aldy505/bob v0.0.0-20210630160113-75547d606a54 h1:U9GFaqa00Ft1kqmUxoNz+CugEmXGdX6bz2L+O/dbB/8=
github.com/aldy505/bob v0.0.0-20210630160113-75547d606a54/go.mod h1:/8HuD17XXgzuaFw5j4oDyB8O+NlW8mKWd0QCCbeoLVE=
github.com/aldy505/bob v0.0.1 h1:L/nvD9+ViLJaWbgbeBes/4xQfz7YtQLJtk8OjSa9L2k=
github.com/aldy505/bob v0.0.1/go.mod h1:/8HuD17XXgzuaFw5j4oDyB8O+NlW8mKWd0QCCbeoLVE=
github.com/aldy505/phc-crypto v1.1.0 h1:BagRKCrB7FOYy5vnuXR6xs6ml2gJD/CvSJkX/Ozo63w=
@ -42,6 +41,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/cactus/go-statsd-client/statsd v0.0.0-20200423205355-cb0885a1018c/go.mod h1:l/bIBLeOl9eX+wxJAzxS4TveKRtAqlyDpHjhkfO0MEI=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@ -122,6 +122,10 @@ github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFG
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gojek/heimdall/v7 v7.0.2 h1:+YutGXZ8oEWbCJIwjRnkKmoTl+Oxt1Urs3hc/FR0sxU=
github.com/gojek/heimdall/v7 v7.0.2/go.mod h1:Z43HtMid7ysSjmsedPTXAki6jcdcNVnjn5pmsTyiMic=
github.com/gojek/valkyrie v0.0.0-20180215180059-6aee720afcdf h1:5xRGbUdOmZKoDXkGx5evVLehuCMpuO1hl701bEQqXOM=
github.com/gojek/valkyrie v0.0.0-20180215180059-6aee720afcdf/go.mod h1:QzhUKaYKJmcbTnCYCAVQrroCOY7vOOI8cSQ4NbuhYf0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@ -270,9 +274,11 @@ github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
@ -362,8 +368,9 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@ -385,6 +392,7 @@ github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
@ -424,6 +432,8 @@ github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5J
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@ -625,6 +635,7 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=

View File

@ -6,8 +6,8 @@ import (
"os/signal"
"time"
v1 "github.com/aldy505/jokes-bapak2-api/api/app/v1"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/database"
v1 "jokes-bapak2-api/app/v1"
"jokes-bapak2-api/app/v1/platform/database"
"github.com/getsentry/sentry-go"
"github.com/gofiber/fiber/v2"
@ -58,6 +58,7 @@ func main() {
}
func errorHandler(c *fiber.Ctx, err error) error {
log.Println(err)
sentry.CaptureException(err)
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Something went wrong on our end",