-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from isd-sgcu/dev
update main
- Loading branch information
Showing
150 changed files
with
10,256 additions
and
5,772 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
root = "." | ||
testdata_dir = "testdata" | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
args_bin = [] | ||
bin = "./tmp/main" | ||
cmd = "go build -o ./tmp/main ./cmd/main.go" | ||
delay = 1000 | ||
exclude_dir = ["assets", "tmp", "vendor", "testdata"] | ||
exclude_file = [] | ||
exclude_regex = ["_test.go"] | ||
exclude_unchanged = false | ||
follow_symlink = false | ||
full_bin = "" | ||
include_dir = [] | ||
include_ext = ["go", "tpl", "tmpl", "html"] | ||
include_file = [] | ||
kill_delay = "0s" | ||
log = "build-errors.log" | ||
poll = false | ||
poll_interval = 0 | ||
post_cmd = [] | ||
pre_cmd = [] | ||
rerun = false | ||
rerun_delay = 500 | ||
send_interrupt = false | ||
stop_on_error = false | ||
|
||
[color] | ||
app = "" | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[log] | ||
main_only = false | ||
time = false | ||
|
||
[misc] | ||
clean_on_exit = false | ||
|
||
[proxy] | ||
app_port = 0 | ||
enabled = false | ||
proxy_port = 0 | ||
|
||
[screen] | ||
clear_on_rebuild = false | ||
keep_scroll = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
APP_PORT=3001 | ||
APP_ENV=development | ||
APP_MAX_FILE_SIZE=10 | ||
|
||
DB_URL=postgres://root:root@localhost:5432/johnjud_db | ||
|
||
JWT_SECRET=secret | ||
JWT_EXPIRES_IN=3600 | ||
JWT_REFRESH_TOKEN_TTL=604800 | ||
JWT_ISSUER=issuer | ||
JWT_RESET_TOKEN_TTL=900 | ||
|
||
REDIS_HOST=localhost | ||
REDIS_PORT=6379 | ||
REDIS_PASSWORD= | ||
|
||
AUTH_CLIENT_URL=http://localhost:3000 | ||
|
||
SENDGRID_API_KEY=api_key | ||
SENDGRID_NAME=johnjud | ||
SENDGRID_ADDRESS=johnjud@gmail.com | ||
|
||
BUCKET_ENDPOINT=BUCKET_ENDPOINT | ||
BUCKET_ACCESS_KEY=BUCKET_ACCESS_KEY | ||
BUCKET_SECRET_KEY=BUCKET_SECRET_KEY | ||
BUCKET_NAME=johnjud-pet-images | ||
BUCKET_USE_SSL=true |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,6 @@ github.com | |
coverage.out | ||
coverage.html | ||
|
||
token.txt | ||
token.txt | ||
tmp | ||
docker-compose.qa.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package bucket | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"time" | ||
|
||
"github.com/isd-sgcu/johnjud-backend/config" | ||
"github.com/minio/minio-go/v7" | ||
"github.com/pkg/errors" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
type Client interface { | ||
Upload([]byte, string) (string, string, error) | ||
Delete(string) error | ||
DeleteMany([]string) error | ||
} | ||
|
||
type clientImpl struct { | ||
conf config.Bucket | ||
minio *minio.Client | ||
} | ||
|
||
func NewClient(conf config.Bucket, minioClient *minio.Client) Client { | ||
return &clientImpl{conf: conf, minio: minioClient} | ||
} | ||
|
||
func (c *clientImpl) Upload(file []byte, objectKey string) (string, string, error) { | ||
ctx := context.Background() | ||
_, cancel := context.WithTimeout(ctx, 50*time.Second) | ||
defer cancel() | ||
|
||
buffer := bytes.NewReader(file) | ||
|
||
uploadOutput, err := c.minio.PutObject(context.Background(), c.conf.BucketName, objectKey, buffer, | ||
buffer.Size(), minio.PutObjectOptions{ContentType: "application/octet-stream"}) | ||
if err != nil { | ||
log.Error(). | ||
Err(err). | ||
Str("service", "file"). | ||
Str("module", "bucket client"). | ||
Msgf("Couldn't upload object to %v:%v.", c.conf.BucketName, objectKey) | ||
|
||
return "", "", errors.Wrap(err, "Error while uploading the object") | ||
} | ||
|
||
return c.getURL(objectKey), uploadOutput.Key, nil | ||
} | ||
|
||
func (c *clientImpl) Delete(objectKey string) error { | ||
ctx := context.Background() | ||
_, cancel := context.WithTimeout(ctx, 50*time.Second) | ||
defer cancel() | ||
|
||
opts := minio.RemoveObjectOptions{ | ||
GovernanceBypass: true, | ||
} | ||
err := c.minio.RemoveObject(context.Background(), c.conf.BucketName, objectKey, opts) | ||
if err != nil { | ||
log.Error(). | ||
Err(err). | ||
Str("service", "file"). | ||
Str("module", "bucket client"). | ||
Msgf("Couldn't delete object from bucket %v:%v.", c.conf.BucketName, objectKey) | ||
|
||
return errors.Wrap(err, "Error while deleting the object") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *clientImpl) DeleteMany(objectKeys []string) error { | ||
ctx := context.Background() | ||
_, cancel := context.WithTimeout(ctx, 50*time.Second) | ||
defer cancel() | ||
|
||
opts := minio.RemoveObjectOptions{ | ||
GovernanceBypass: true, | ||
} | ||
for _, objectKey := range objectKeys { | ||
err := c.minio.RemoveObject(context.Background(), c.conf.BucketName, objectKey, opts) | ||
if err != nil { | ||
log.Error(). | ||
Err(err). | ||
Str("service", "file"). | ||
Str("module", "bucket client"). | ||
Msgf("Couldn't delete object from bucket %v:%v.", c.conf.BucketName, objectKey) | ||
|
||
return errors.Wrap(err, "Error while deleting the object") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *clientImpl) getURL(objectKey string) string { | ||
return "https://" + c.conf.Endpoint + "/" + c.conf.BucketName + "/" + objectKey | ||
} |
Oops, something went wrong.