A container registry that uses the AT Protocol for manifest storage and S3 for blob storage. atcr.io
docker container atproto go
72
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 88 lines 2.0 kB view raw
1package main 2 3import ( 4 "context" 5 "fmt" 6 "sort" 7 8 "github.com/UpCloudLtd/upcloud-go-api/v8/upcloud" 9 "github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/service" 10 "github.com/charmbracelet/huh" 11) 12 13// pickZone fetches available zones from the UpCloud API and presents an 14// interactive selector. Only public zones are shown. 15func pickZone(ctx context.Context, svc *service.Service) (string, error) { 16 resp, err := svc.GetZones(ctx) 17 if err != nil { 18 return "", fmt.Errorf("fetch zones: %w", err) 19 } 20 21 var opts []huh.Option[string] 22 for _, z := range resp.Zones { 23 if z.Public != upcloud.True { 24 continue 25 } 26 label := fmt.Sprintf("%s — %s", z.ID, z.Description) 27 opts = append(opts, huh.NewOption(label, z.ID)) 28 } 29 30 if len(opts) == 0 { 31 return "", fmt.Errorf("no public zones available") 32 } 33 34 sort.Slice(opts, func(i, j int) bool { 35 return opts[i].Value < opts[j].Value 36 }) 37 38 var zone string 39 err = huh.NewSelect[string](). 40 Title("Select a zone"). 41 Options(opts...). 42 Value(&zone). 43 Run() 44 if err != nil { 45 return "", err 46 } 47 48 return zone, nil 49} 50 51// pickPlan fetches available plans from the UpCloud API and presents an 52// interactive selector. GPU plans are filtered out. 53func pickPlan(ctx context.Context, svc *service.Service) (string, error) { 54 resp, err := svc.GetPlans(ctx) 55 if err != nil { 56 return "", fmt.Errorf("fetch plans: %w", err) 57 } 58 59 var opts []huh.Option[string] 60 for _, p := range resp.Plans { 61 if p.GPUAmount > 0 { 62 continue 63 } 64 memGB := p.MemoryAmount / 1024 65 label := fmt.Sprintf("%s — %d CPU, %d GB RAM, %d GB disk", p.Name, p.CoreNumber, memGB, p.StorageSize) 66 opts = append(opts, huh.NewOption(label, p.Name)) 67 } 68 69 if len(opts) == 0 { 70 return "", fmt.Errorf("no plans available") 71 } 72 73 sort.Slice(opts, func(i, j int) bool { 74 return opts[i].Value < opts[j].Value 75 }) 76 77 var plan string 78 err = huh.NewSelect[string](). 79 Title("Select a plan"). 80 Options(opts...). 81 Value(&plan). 82 Run() 83 if err != nil { 84 return "", err 85 } 86 87 return plan, nil 88}