Skip to content

Commit

Permalink
fix: config
Browse files Browse the repository at this point in the history
  • Loading branch information
macgeargear committed Jun 26, 2024
1 parent be4ad51 commit 763f02b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 41 deletions.
9 changes: 5 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func main() {
if err != nil {
panic(fmt.Sprintf("Failed to load config: %v", err))
}
fmt.Println("conf: ", conf)

logger := logger.New(conf)

minioClient, err := minio.New(conf.Store.Endpoint, &minio.Options{
Creds: credentials.NewStaticV4(conf.Store.AccessKey, conf.Store.SecretKey, ""),
Expand All @@ -42,10 +45,8 @@ func main() {
storeClient := store.NewClient(minioClient)
httpClient := &http.Client{}

objectRepo := object.NewRepository(&conf.Store, storeClient, *httpClient)
objectSvc := object.NewService(objectRepo, logger.New(conf))

logger := logger.New(conf)
objectRepo := object.NewRepository(&conf.Store, storeClient, httpClient)
objectSvc := object.NewService(objectRepo, &conf.Store, logger.Named("objectSvc"))

listener, err := net.Listen("tcp", fmt.Sprintf(":%v", conf.App.Port))
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type DB struct {
}

type Store struct {
Endpoint string `mapstructure:"endpoint"`
AccessKey string `mapstructure:"access_key"`
SecretKey string `mapstructure:"secret_key"`
UseSSL bool `mapstructure:"use_ssl"`
BucketName string `mapstructure:"bucket_name"`
Region string `mapstructure:"region"`
Token string `mapstructure:"token"`
Endpoint string
AccessKey string
SecretKey string
UseSSL bool
BucketName string
Region string
Token string
}

type Config struct {
Expand Down
21 changes: 0 additions & 21 deletions docker-compose.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
)

require (
github.com/isd-sgcu/rpkm67-go-proto v0.1.4
github.com/isd-sgcu/rpkm67-go-proto v0.1.5
github.com/minio/minio-go/v7 v7.0.72
github.com/pkg/errors v0.9.1
go.uber.org/multierr v1.10.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/isd-sgcu/rpkm67-go-proto v0.1.4 h1:2nZRoBrHZUMN6QogR46yzqi7RoydmqRyF496udEknGg=
github.com/isd-sgcu/rpkm67-go-proto v0.1.4/go.mod h1:Z5SYz5kEe4W+MdqPouF0zEOiaqvg+s9I1S5d0q6e+Jw=
github.com/isd-sgcu/rpkm67-go-proto v0.1.5 h1:WShrm8DeVqIY1ZelgM88vW8LMnLxF6dTt650A0YkC8U=
github.com/isd-sgcu/rpkm67-go-proto v0.1.5/go.mod h1:Z5SYz5kEe4W+MdqPouF0zEOiaqvg+s9I1S5d0q6e+Jw=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
Expand Down
19 changes: 12 additions & 7 deletions internal/object/object.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"time"

"github.com/isd-sgcu/rpkm67-store/config"
"github.com/isd-sgcu/rpkm67-store/internal/client/store"
httpClient "github.com/isd-sgcu/rpkm67-store/internal/client/http"
storeClient "github.com/isd-sgcu/rpkm67-store/internal/client/store"
"github.com/minio/minio-go/v7"
"github.com/pkg/errors"
)
Expand All @@ -22,11 +23,11 @@ type Repository interface {

type repositoryImpl struct {
conf *config.Store
storeClient store.Client
httpClient http.Client
storeClient storeClient.Client
httpClient httpClient.Client
}

func NewRepository(conf *config.Store, storeClient store.Client, httpClient http.Client) Repository {
func NewRepository(conf *config.Store, storeClient storeClient.Client, httpClient httpClient.Client) Repository {
return &repositoryImpl{
conf: conf,
storeClient: storeClient,
Expand All @@ -41,8 +42,12 @@ func (r *repositoryImpl) Upload(file []byte, bucketName string, objectKey string

buffer := bytes.NewReader(file)

uploadOutput, err := r.storeClient.PutObject(context.Background(), bucketName, objectKey, buffer,
buffer.Size(), minio.PutObjectOptions{ContentType: "application/octet-stream"})
fmt.Println("bucketName: ", bucketName)
fmt.Println("objectKey: ", objectKey)
fmt.Println("buffer: ", buffer)

uploadOutput, err := r.storeClient.PutObject(ctx, bucketName, objectKey, buffer,
buffer.Size(), minio.PutObjectOptions{})
if err != nil {
return "", "", errors.Wrap(err, fmt.Sprintf("Couldn't upload object to %v/%v.", bucketName, objectKey))
}
Expand All @@ -58,7 +63,7 @@ func (r *repositoryImpl) Delete(bucketName string, objectKey string) (err error)
opts := minio.RemoveObjectOptions{
GovernanceBypass: true,
}
err = r.storeClient.RemoveObject(context.Background(), bucketName, objectKey, opts)
err = r.storeClient.RemoveObject(ctx, bucketName, objectKey, opts)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Couldn't delete object %v/%v.", bucketName, objectKey))
}
Expand Down
4 changes: 3 additions & 1 deletion internal/object/object.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type serviceImpl struct {
log *zap.Logger
}

func NewService(repo Repository, log *zap.Logger) Service {
func NewService(repo Repository, conf *config.Store, log *zap.Logger) Service {
return &serviceImpl{
repo: repo,
conf: conf,
log: log,
}
}
Expand All @@ -37,6 +38,7 @@ func (s *serviceImpl) Upload(_ context.Context, req *proto.UploadObjectRequest)
return nil, status.Error(codes.Internal, constant.InternalServerErrorMessage)
}
objectKey := req.Filename + "_" + randomString
fmt.Println("objectKey: ", objectKey)

url, key, err := s.repo.Upload(req.Data, s.conf.BucketName, objectKey)
if err != nil {
Expand Down

0 comments on commit 763f02b

Please sign in to comment.