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

Function ExampleSet_structWithMultipleFields

pkg/set/example_test.go:300–334  ·  view source on GitHub ↗

ExampleSet_structWithMultipleFields demonstrates deduplication with complex structs

()

Source from the content-addressed store, hash-verified

298
299// ExampleSet_structWithMultipleFields demonstrates deduplication with complex structs
300func ExampleSet_structWithMultipleFields() {
301 // Define a struct representing an S3 object key with metadata
302 type S3Object struct {
303 Bucket string
304 Key string
305 Version string
306 ETag string
307 }
308
309 objects := set.New[S3Object]()
310
311 // Add objects
312 objects.Add(S3Object{"my-bucket", "docs/file1.txt", "v1", "abc123"})
313 objects.Add(S3Object{"my-bucket", "docs/file2.txt", "v1", "def456"})
314 objects.Add(S3Object{"my-bucket", "docs/file1.txt", "v2", "ghi789"})
315 objects.Add(S3Object{"my-bucket", "docs/file1.txt", "v1", "abc123"}) // duplicate
316
317 fmt.Println("Unique objects:", len(objects))
318
319 // Check for specific object
320 obj := S3Object{"my-bucket", "docs/file1.txt", "v1", "abc123"}
321 fmt.Println("Contains object:", objects.Contains(obj))
322
323 // Get all objects from a specific bucket
324 bucketObjects := objects.FuncMatch(func(o, filter S3Object) bool {
325 return o.Bucket == filter.Bucket && o.Key == filter.Key
326 }, S3Object{Bucket: "my-bucket", Key: "docs/file1.txt"})
327
328 fmt.Println("Versions of file1.txt:", len(bucketObjects))
329
330 // Output:
331 // Unique objects: 3
332 // Contains object: true
333 // Versions of file1.txt: 2
334}
335
336// ExampleSet_nestedComparable demonstrates using Set with nested comparable structs
337func ExampleSet_nestedComparable() {

Callers

nothing calls this directly

Calls 3

AddMethod · 0.45
ContainsMethod · 0.45
FuncMatchMethod · 0.45

Tested by

no test coverage detected