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

fogfish / stream / 11748698612

08 Nov 2024 07:56PM UTC coverage: 92.564% (-1.9%) from 94.437%
11748698612

push

github

web-flow
Update optional params of the library (#38)

32 of 45 new or added lines in 2 files covered. (71.11%)

5 existing lines in 2 files now uncovered.

722 of 780 relevant lines covered (92.56%)

1.03 hits per line

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

68.29
/options.go
1
//
2
// Copyright (C) 2024 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/stream
7
//
8

9
package stream
10

11
import (
12
        "context"
13
        "time"
14

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

22
type Option = opts.Option[Opts]
23

24
// File System Configuration Options
25
type Opts struct {
26
        api          S3
27
        upload       S3Upload
28
        signer       S3Signer
29
        timeout      time.Duration
30
        ttlSignedUrl time.Duration
31
        lslimit      int32
32
}
33

34
func (c *Opts) checkRequired() error {
1✔
35
        return opts.Required(c,
1✔
36
                WithS3(nil),
1✔
37
                WithIOTimeout(0),
1✔
38
        )
1✔
39
}
1✔
40

41
var (
42
        // Set S3 client for the file system
43
        WithS3 = opts.ForType[Opts, S3]()
44

45
        // Set S3 upload client for the file system
46
        WithS3Upload = opts.ForType[Opts, S3Upload]()
47

48
        // Set S3 url signer client for the file system
49
        WithS3Signer = opts.ForType[Opts, S3Signer]()
50

51
        // Use aws.Config as base config for S3, S3 upload and S3 url signer clients
52
        WithConfig = opts.FMap(optsFromConfig)
53

54
        // Use region for configuring the service
55
        WithRegion = opts.FMap(optsFromRegion)
56

57
        // Use default aws.Config for all S3 clients
58
        WithDefaultS3 = opts.From(optsDefaultS3)
59

60
        // Sets the I/O timeout for the file stream.
61
        // This timeout defines how long the stream remains open.
62
        // After timeout expiration any stream I/O would fail.
63
        WithIOTimeout = opts.ForName[Opts, time.Duration]("timeout")
64

65
        // Sets the time-to-live for the pre-signed urls
66
        WithPreSignUrlTTL = opts.ForName[Opts, time.Duration]("ttlSignedUrl")
67

68
        // Set the number of keys to be read from S3 while walking through "dir"
69
        WithListingLimit = opts.ForName[Opts, int32]("lslimit")
70
)
71

72
func optsDefault() Opts {
1✔
73
        return Opts{
1✔
74
                timeout:      120 * time.Second,
1✔
75
                ttlSignedUrl: 5 * time.Minute,
1✔
76
                lslimit:      1000,
1✔
77
        }
1✔
78
}
1✔
79

80
func optsDefaultS3(c *Opts) error {
1✔
81
        cfg, err := config.LoadDefaultConfig(context.Background())
1✔
82
        if err != nil {
1✔
NEW
83
                return err
×
UNCOV
84
        }
×
85
        return optsFromConfig(c, cfg)
1✔
86
}
87

NEW
88
func optsFromRegion(c *Opts, region string) error {
×
NEW
89
        cfg, err := config.LoadDefaultConfig(
×
NEW
90
                context.Background(),
×
NEW
91
                config.WithRegion(region),
×
NEW
92
        )
×
NEW
93
        if err != nil {
×
NEW
94
                return err
×
UNCOV
95
        }
×
96

NEW
97
        return optsFromConfig(c, cfg)
×
98
}
99

100
func optsFromConfig(c *Opts, cfg aws.Config) error {
1✔
101
        api := s3.NewFromConfig(cfg)
1✔
102

1✔
103
        if c.api == nil {
2✔
104
                c.api = api
1✔
105
        }
1✔
106

107
        if c.upload == nil {
2✔
108
                c.upload = manager.NewUploader(api)
1✔
109
        }
1✔
110

111
        if c.signer == nil {
1✔
NEW
112
                c.signer = s3.NewPresignClient(api)
×
UNCOV
113
        }
×
114
        return nil
1✔
115
}
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