File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 "github.com/Prateet-Github/worker-go/internal/config"
77 "github.com/Prateet-Github/worker-go/internal/handlers"
88 "github.com/Prateet-Github/worker-go/internal/queue"
9+ "github.com/Prateet-Github/worker-go/internal/s3"
910
1011 "github.com/hibiken/asynq"
1112)
@@ -15,7 +16,10 @@ func main() {
1516
1617 server := queue .NewServer (cfg )
1718
18- videoHandler := handlers .NewVideoHandler ()
19+ s3Client := s3 .NewClient (cfg )
20+ videoHandler := handlers .NewVideoHandler (
21+ s3Client ,
22+ )
1923
2024 mux := asynq .NewServeMux ()
2125
Original file line number Diff line number Diff line change @@ -6,13 +6,20 @@ import (
66 "log"
77
88 "github.com/Prateet-Github/worker-go/internal/queue"
9+ "github.com/aws/aws-sdk-go-v2/service/s3"
910 "github.com/hibiken/asynq"
1011)
1112
12- type VideoHandler struct {}
13+ type VideoHandler struct {
14+ s3Client * s3.Client
15+ }
1316
14- func NewVideoHandler () * VideoHandler {
15- return & VideoHandler {}
17+ func NewVideoHandler (
18+ s3Client * s3.Client ,
19+ ) * VideoHandler {
20+ return & VideoHandler {
21+ s3Client : s3Client ,
22+ }
1623}
1724
1825func (h * VideoHandler ) ProcessVideo (
Original file line number Diff line number Diff line change 1+ package s3
2+
3+ import (
4+ "context"
5+ "log"
6+
7+ "github.com/Prateet-Github/worker-go/internal/config"
8+
9+ awsconfig "github.com/aws/aws-sdk-go-v2/config"
10+ "github.com/aws/aws-sdk-go-v2/credentials"
11+ awss3 "github.com/aws/aws-sdk-go-v2/service/s3"
12+ )
13+
14+ func NewClient (cfg * config.Config ) * awss3.Client {
15+ awsCfg , err := awsconfig .LoadDefaultConfig (
16+ context .Background (),
17+ awsconfig .WithRegion (cfg .AWSRegion ),
18+ awsconfig .WithCredentialsProvider (
19+ credentials .NewStaticCredentialsProvider (
20+ cfg .AWSAccessKeyID ,
21+ cfg .AWSSecretAccessKey ,
22+ "" ,
23+ ),
24+ ),
25+ )
26+
27+ if err != nil {
28+ log .Fatal (err )
29+ }
30+
31+ return awss3 .NewFromConfig (awsCfg )
32+ }
You can’t perform that action at this time.
0 commit comments