package main
import (
"fmt"
)
// Dataset represents a dataset with a name, size, and archive status.
type Dataset struct {
Name string
Size int64
IsArchived bool
}
// DatasetManager handles the list of datasets and archive operations.
type DatasetManager struct {
Datasets [ ] Dataset
}
// NewDatasetManager creates a new DatasetManager with sample datasets.
func NewDatasetManager( ) * DatasetManager {
return & DatasetManager{
Datasets: [ ] Dataset{
{ Name: "Dataset 1" , Size: 1024 * 1024 * 500 , IsArchived: false } , // 500 MB
{ Name: "Dataset 2" , Size: 1024 * 1024 * 200 , IsArchived: true } , // 200 MB
{ Name: "Dataset 3" , Size: 1024 * 1024 * 750 , IsArchived: false } , // 750 MB
} ,
}
}
// ListDatasets displays a list of datasets with their names and archive statuses.
func ( dm * DatasetManager) ListDatasets( ) {
fmt.Println ( "Available Datasets:" )
for _, ds := range dm.Datasets {
status := "Archived"
if ! ds.IsArchived {
status = "Not Archived"
}
fmt.Printf ( "%s: %s\n " , ds.Name , status)
}
}
// ArchiveDatasetByName archives the specified dataset by name.
func ( dm * DatasetManager) ArchiveDatasetByName( name string) {
for i, ds := range dm.Datasets {
if ds.Name == name {
dm.Datasets [ i] .IsArchived = true
fmt.Printf ( "%s has been archived.\n " , name)
return
}
}
fmt.Printf ( "Dataset '%s' not found.\n " , name)
}
func main( ) {
dm := NewDatasetManager( )
dm.ListDatasets ( )
datasetToArchive := "Dataset 1"
dm.ArchiveDatasetByName ( datasetToArchive)
dm.ListDatasets ( )
}
cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKKQoKLy8gRGF0YXNldCByZXByZXNlbnRzIGEgZGF0YXNldCB3aXRoIGEgbmFtZSwgc2l6ZSwgYW5kIGFyY2hpdmUgc3RhdHVzLgp0eXBlIERhdGFzZXQgc3RydWN0IHsKCU5hbWUgc3RyaW5nCglTaXplIGludDY0CglJc0FyY2hpdmVkIGJvb2wKfQoKLy8gRGF0YXNldE1hbmFnZXIgaGFuZGxlcyB0aGUgbGlzdCBvZiBkYXRhc2V0cyBhbmQgYXJjaGl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