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 package v1
import ( import (
"github.com/aldy505/jokes-bapak2-api/api/app/v1/routes" "jokes-bapak2-api/app/v1/routes"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )

View File

@ -3,7 +3,8 @@ package handler
import ( import (
"context" "context"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/models" "jokes-bapak2-api/app/v1/models"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
@ -14,7 +15,7 @@ func AddNewJoke(c *fiber.Ctx) error {
return err 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 { if err != nil {
return err return err
} }

View File

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

View File

@ -2,55 +2,74 @@ package handler
import ( import (
"context" "context"
"io/ioutil"
"log"
"time" "time"
"github.com/Masterminds/squirrel" "jokes-bapak2-api/app/v1/models"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/cache" "jokes-bapak2-api/app/v1/platform/cache"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/platform/database" "jokes-bapak2-api/app/v1/platform/database"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/utils" "jokes-bapak2-api/app/v1/utils"
"github.com/gofiber/fiber/v2"
)
type Today struct { "github.com/Masterminds/squirrel"
link string `redis:"link"` "github.com/gofiber/fiber/v2"
date string `redis:"date"` "github.com/gojek/heimdall/v7/httpclient"
} )
var psql = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar) var psql = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
var db = database.New() var db = database.New()
var redis = cache.New() var redis = cache.New()
var client = httpclient.NewClient(httpclient.WithHTTPTimeout(10 * time.Second))
func TodayJoke(c *fiber.Ctx) error { func TodayJoke(c *fiber.Ctx) error {
// check from redis if today's joke already exists // check from redis if today's joke already exists
// send the joke if exists // send the joke if exists
// get a new joke if it's not, then send it. // get a new joke if it's not, then send it.
var joke Today var joke models.Today
err := redis.MGet(context.Background(), "today:link", "today:date").Scan(&joke) err := redis.MGet(context.Background(), "today:link", "today:date", "today:image", "today:contentType").Scan(&joke)
if err != nil { if err != nil {
return err return err
} }
eq, err := utils.IsToday(joke.date) eq, err := utils.IsToday(joke.Date)
if err != nil { if err != nil {
return err return err
} }
if eq { if eq {
c.Attachment(joke.link) log.Println("through cached")
return c.SendStatus(fiber.StatusOK) c.Set("Content-Type", joke.ContentType)
return c.Status(fiber.StatusOK).Send([]byte(joke.Image))
} else { } else {
var link string 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 { if err != nil {
return err 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) 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 { if err != nil {
return err 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 // fetch the image url
// send the image as proxied file // send the image as proxied file
var link string 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 { if err != nil {
return err 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 { func JokeByID(c *fiber.Ctx) error {
@ -73,13 +104,28 @@ func JokeByID(c *fiber.Ctx) error {
// fetch image url // fetch image url
// send the image as proxied file // send the image as proxied file
var link string 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 != nil {
if err.Error() == "no rows in result set" {
return c.Status(fiber.StatusNotFound).Send([]byte("Requested ID was not found."))
}
return err return err
} }
if link == "" { if link == "" {
return c.Status(fiber.StatusNotFound).Send([]byte("Requested ID was not found.")) 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 ( import (
"context" "context"
"jokes-bapak2-api/app/v1/models"
"github.com/Masterminds/squirrel" "github.com/Masterminds/squirrel"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/models"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
@ -29,7 +30,7 @@ func UpdateJoke(c *fiber.Ctx) error {
return err 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 { if err != nil {
return err return err
} }

View File

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

View File

@ -1,11 +1,16 @@
package models package models
type RequestJokePost struct { type RequestJokePost struct {
Key string `json:"string"` Link string `json:"link" form:"link"`
Link string `json:"link"`
} }
type RequestAuth struct { type RequestAuth struct {
Key string `json:"key"` Key string `json:"key" form:"key"`
Token string `json:"token"` 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 ( import (
"context" "context"
"log" "log"
"strings"
"github.com/aldy505/bob" "github.com/aldy505/bob"
) )
@ -12,48 +11,99 @@ import (
func Setup() error { func Setup() error {
db := New() db := New()
// Jokesbapak2 table & data // Jokesbapak2 table
sql, _, err := bob.CreateTableIfNotExists("jokesbapak2").
Columns("id", "link", "key"). // Check if table exists
Types("SERIAL", "TEXT", "VARCHAR(255)"). var tableJokesExists bool
Primary("id").ToSql() 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 { 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, ";") if !tableJokesExists {
for i := range splitSql { sql, _, err := bob.CreateTable("jokesbapak2").
_, err = db.Query(context.Background(), splitSql[i]) Columns("id", "link").
Types("SERIAL", "TEXT").
ToSql()
if err != nil { if err != nil {
log.Fatalln("11 - failed on table creation: ", err) log.Fatalln("11 - failed on table creation: ", err)
return err return err
} }
}
// Authorization _, err = db.Query(context.Background(), sql)
sql, _, err = bob.CreateTableIfNotExists("authorization").
Columns("id", "token", "key").
Types("SERIAL", "TEXT", "VARCHAR(255)").
Primary("id").
Unique("token").
ToSql()
if err != nil {
log.Fatalln("14 - failed on table creation: ", err)
return err
}
splitSql = strings.Split(sql, ";")
for i := range splitSql {
_, err = db.Query(context.Background(), splitSql[i])
if err != nil { if err != nil {
log.Fatalln("15 - failed on table creation: ", err) 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
}
_, 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 return err
} }
} }
_, err = db.Query(context.Background(), "ALTER TABLE jokesbapak2 ADD CONSTRAINT fk_jokesbapak2_key FOREIGN KEY (key) REFERENCES authorization (id)") // 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 { if err != nil {
log.Fatalln("16 - failed on foreign key iteration: ", err) 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("17 - failed on table creation: ", err)
return err
}
_, err = db.Query(context.Background(), sql)
if err != nil {
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 \"administrators\" ADD UNIQUE (\"key\");")
if err != nil {
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 return nil
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/aldy505/jokes-bapak2-api/api/app/v1/utils" "jokes-bapak2-api/app/v1/utils"
) )
func TestRequest(t *testing.T) { 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 go 1.16
@ -9,6 +9,7 @@ require (
github.com/getsentry/sentry-go v0.11.0 github.com/getsentry/sentry-go v0.11.0
github.com/go-redis/redis/v8 v8.11.0 github.com/go-redis/redis/v8 v8.11.0
github.com/gofiber/fiber/v2 v2.14.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/jackc/pgx/v4 v4.11.0
github.com/joho/godotenv v1.3.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/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/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/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/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/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= 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/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/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/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 h1:L/nvD9+ViLJaWbgbeBes/4xQfz7YtQLJtk8OjSa9L2k=
github.com/aldy505/bob v0.0.1/go.mod h1:/8HuD17XXgzuaFw5j4oDyB8O+NlW8mKWd0QCCbeoLVE= github.com/aldy505/bob v0.0.1/go.mod h1:/8HuD17XXgzuaFw5j4oDyB8O+NlW8mKWd0QCCbeoLVE=
github.com/aldy505/phc-crypto v1.1.0 h1:BagRKCrB7FOYy5vnuXR6xs6ml2gJD/CvSJkX/Ozo63w= 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.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 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/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/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/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 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.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.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 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/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-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/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.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/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/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/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.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= 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/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/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= 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 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= 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.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.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/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= 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-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/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/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= 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.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.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= 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.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 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= 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/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 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/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/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= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=

View File

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