fork download
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. )
  6.  
  7. // Dataset represents a dataset with a name, size, and archive status.
  8. type Dataset struct {
  9. Name string
  10. Size int64
  11. IsArchived bool
  12. }
  13.  
  14. // DatasetManager handles the list of datasets and archive operations.
  15. type DatasetManager struct {
  16. Datasets []Dataset
  17. }
  18.  
  19. // NewDatasetManager creates a new DatasetManager with sample datasets.
  20. func NewDatasetManager() *DatasetManager {
  21. return &DatasetManager{
  22. Datasets: []Dataset{
  23. {Name: "Dataset 1", Size: 1024 * 1024 * 500, IsArchived: false}, // 500 MB
  24. {Name: "Dataset 2", Size: 1024 * 1024 * 200, IsArchived: true}, // 200 MB
  25. {Name: "Dataset 3", Size: 1024 * 1024 * 750, IsArchived: false}, // 750 MB
  26. },
  27. }
  28. }
  29.  
  30. // ListDatasets displays a list of datasets with their names and archive statuses.
  31. func (dm *DatasetManager) ListDatasets() {
  32. fmt.Println("Available Datasets:")
  33. for _, ds := range dm.Datasets {
  34. status := "Archived"
  35. if !ds.IsArchived {
  36. status = "Not Archived"
  37. }
  38. fmt.Printf("%s: %s\n", ds.Name, status)
  39. }
  40. }
  41.  
  42. // ArchiveDatasetByName archives the specified dataset by name.
  43. func (dm *DatasetManager) ArchiveDatasetByName(name string) {
  44. for i, ds := range dm.Datasets {
  45. if ds.Name == name {
  46. dm.Datasets[i].IsArchived = true
  47. fmt.Printf("%s has been archived.\n", name)
  48. return
  49. }
  50. }
  51. fmt.Printf("Dataset '%s' not found.\n", name)
  52. }
  53.  
  54. func main() {
  55. dm := NewDatasetManager()
  56.  
  57. dm.ListDatasets()
  58.  
  59. datasetToArchive := "Dataset 1"
  60. dm.ArchiveDatasetByName(datasetToArchive)
  61.  
  62. dm.ListDatasets()
  63. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Available Datasets:
Dataset 1: Not Archived
Dataset 2: Archived
Dataset 3: Not Archived
Dataset 1 has been archived.
Available Datasets:
Dataset 1: Archived
Dataset 2: Archived
Dataset 3: Not Archived