MCPcopy
hub / github.com/minio/minio-go / main

Function main

examples/s3/selectobject.go:33–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31)
32
33func main() {
34 // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and
35 // my-testfile are dummy values, please replace them with original values.
36
37 // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
38 // This boolean value is the last argument for New().
39
40 // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
41 // determined based on the Endpoint value.
42 s3Client, err := minio.New("s3.amazonaws.com", &minio.Options{
43 Creds: credentials.NewStaticV4("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", ""),
44 Secure: true,
45 })
46 if err != nil {
47 log.Fatalln(err)
48 }
49
50 opts := minio.SelectObjectOptions{
51 Expression: "select count(*) from s3object",
52 ExpressionType: minio.QueryExpressionTypeSQL,
53 InputSerialization: minio.SelectObjectInputSerialization{
54 CompressionType: minio.SelectCompressionNONE,
55 CSV: &minio.CSVInputOptions{
56 FileHeaderInfo: minio.CSVFileHeaderInfoNone,
57 RecordDelimiter: "\n",
58 FieldDelimiter: ",",
59 },
60 },
61 OutputSerialization: minio.SelectObjectOutputSerialization{
62 CSV: &minio.CSVOutputOptions{
63 RecordDelimiter: "\n",
64 FieldDelimiter: ",",
65 },
66 },
67 }
68
69 reader, err := s3Client.SelectObjectContent(context.Background(), "mycsvbucket", "mycsv.csv", opts)
70 if err != nil {
71 log.Fatalln(err)
72 }
73 defer reader.Close()
74
75 if _, err := io.Copy(os.Stdout, reader); err != nil {
76 log.Fatalln(err)
77 }
78}

Callers

nothing calls this directly

Calls 3

NewStaticV4Function · 0.92
SelectObjectContentMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected