• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fogfish / dynamo / 11990190580

23 Nov 2024 08:27PM UTC coverage: 83.45% (-0.3%) from 83.747%
11990190580

push

github

web-flow
Use fogfish/opts library to declare options (#105)

60 of 68 new or added lines in 14 files covered. (88.24%)

2 existing lines in 2 files now uncovered.

1311 of 1571 relevant lines covered (83.45%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/service/s3/options.go
1
//
2
// Copyright (C) 2022 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/fogfish/dynamo
7
//
8

9
package s3
10

11
import (
12
        "context"
13

14
        "github.com/aws/aws-sdk-go-v2/aws"
15
        "github.com/aws/aws-sdk-go-v2/config"
16
        "github.com/aws/aws-sdk-go-v2/service/s3"
17
        "github.com/fogfish/curie"
18
        "github.com/fogfish/opts"
19
)
20

21
// S3 declares AWS API used by the library
22
type S3 interface {
23
        GetObject(context.Context, *s3.GetObjectInput, ...func(*s3.Options)) (*s3.GetObjectOutput, error)
24
        PutObject(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error)
25
        DeleteObject(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
26
        ListObjectsV2(context.Context, *s3.ListObjectsV2Input, ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
27
}
28

29
// Option type to configure the S3
30
type Option = opts.Option[Options]
31

32
// Config Options
33
type Options struct {
34
        prefixes curie.Prefixes
35
        bucket   string
36
        service  S3
37
}
38

39
func (c *Options) checkRequired() error {
1✔
40
        return opts.Required(c,
1✔
41
                WithBucket(""),
1✔
42
        )
1✔
43
}
1✔
44

45
var (
46
        // Set S3 bucket  for session, the option is required
47
        WithBucket = opts.ForName[Options, string]("bucket")
48

49
        // Configure CURIE prefixes
50
        WithPrefixes = opts.ForType[Options, curie.Prefixes]()
51

52
        // Set DynamoDB client for the client
53
        WithService = opts.ForType[Options, S3]()
54

55
        // Set DynamoDB client for the client
56
        WithS3 = opts.ForType[Options, S3]()
57

58
        // Configure client's DynamoDB to use provided the aws.Config
59
        WithConfig = opts.FMap(optsFromConfig)
60

61
        // Use default aws.Config for all DynamoDB clients
62
        WithDefaultS3 = opts.From(optsDefaultS3)
63
)
64

65
// NewConfig creates Config with default options
66
func optsDefault() Options {
1✔
67
        return Options{
1✔
68
                prefixes: curie.Namespaces{},
1✔
69
        }
1✔
70
}
1✔
71

72
func optsDefaultS3(c *Options) error {
1✔
73
        cfg, err := config.LoadDefaultConfig(context.Background())
1✔
74
        if err != nil {
1✔
NEW
75
                return err
×
UNCOV
76
        }
×
77
        return optsFromConfig(c, cfg)
1✔
78
}
79

80
func optsFromConfig(c *Options, cfg aws.Config) error {
1✔
81
        if c.service == nil {
2✔
82
                c.service = s3.NewFromConfig(cfg)
1✔
83
        }
1✔
84
        return nil
1✔
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc