MCPcopy Create free account
hub / github.com/DoNewsCode/core / NewManager

Function NewManager

ots3/uploader.go:94–132  ·  view source on GitHub ↗

NewManager creates a new S3 manager

(accessKey, accessSecret, endpoint, region, bucket string, opts ...ManagerOptionFunc)

Source from the content-addressed store, hash-verified

92
93// NewManager creates a new S3 manager
94func NewManager(accessKey, accessSecret, endpoint, region, bucket string, opts ...ManagerOptionFunc) *Manager {
95 c := &ManagerConfig{
96 doer: http.DefaultClient,
97 keyer: key.New(),
98 locationFunc: func(location string) (url string) {
99 return location
100 },
101 autoExtension: true,
102 }
103 for _, f := range opts {
104 f(c)
105 }
106
107 s3Config := &aws.Config{
108 Credentials: credentials.NewStaticCredentials(accessKey, accessSecret, ""),
109 Endpoint: aws.String(endpoint),
110 Region: aws.String(region),
111 DisableSSL: aws.Bool(true),
112 S3ForcePathStyle: aws.Bool(true),
113 }
114 sess := session.Must(session.NewSession(s3Config))
115 c.keyer.Key("/")
116 m := &Manager{
117 bucket: bucket,
118 sess: sess,
119 tracer: c.tracer,
120 doer: c.doer,
121 pathPrefix: c.pathPrefix,
122 keyer: c.keyer,
123 locationFunc: c.locationFunc,
124 autoExtension: c.autoExtension,
125 }
126
127 // add opentracing capabilities if opt factoryIn
128 if c.tracer != nil {
129 sess.Handlers.Build.PushFront(m.otHandler())
130 }
131 return m
132}
133
134// Upload uploads an io.reader to the S3 server, and returns the url on S3. The extension of the uploaded file
135// is auto detected.

Callers 4

newManagerFunction · 0.85
TestNewManagerFunction · 0.85
setupManagerWithTracerFunction · 0.85
ExampleFunction · 0.85

Calls 5

otHandlerMethod · 0.95
NewFunction · 0.92
StringMethod · 0.65
BoolMethod · 0.65
KeyMethod · 0.65

Tested by 3

TestNewManagerFunction · 0.68
setupManagerWithTracerFunction · 0.68
ExampleFunction · 0.68