forked from toolshed/abra
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			926 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			926 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package client
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 
 | |
| 	"github.com/docker/docker/api/types"
 | |
| 	"github.com/docker/docker/api/types/filters"
 | |
| )
 | |
| 
 | |
| func GetVolumes(ctx context.Context, server string, fs filters.Args) ([]*types.Volume, error) {
 | |
| 	cl, err := New(server)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 
 | |
| 	volumeListOKBody, err := cl.VolumeList(ctx, fs)
 | |
| 	volumeList := volumeListOKBody.Volumes
 | |
| 	if err != nil {
 | |
| 		return volumeList, err
 | |
| 	}
 | |
| 
 | |
| 	return volumeList, nil
 | |
| }
 | |
| 
 | |
| func GetVolumeNames(volumes []*types.Volume) []string {
 | |
| 	var volumeNames []string
 | |
| 
 | |
| 	for _, vol := range volumes {
 | |
| 		volumeNames = append(volumeNames, vol.Name)
 | |
| 	}
 | |
| 
 | |
| 	return volumeNames
 | |
| }
 | |
| 
 | |
| func RemoveVolumes(ctx context.Context, server string, volumeNames []string, force bool) error {
 | |
| 	cl, err := New(server)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	for _, volName := range volumeNames {
 | |
| 		err := cl.VolumeRemove(ctx, volName, force)
 | |
| 		if err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return nil
 | |
| }
 |