NewManager creates a new S3 manager
(accessKey, accessSecret, endpoint, region, bucket string, opts ...ManagerOptionFunc)
| 92 | |
| 93 | // NewManager creates a new S3 manager |
| 94 | func 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. |