gopkg.in/docker/docker.v20@v20.10.27/api/types/plugin_responses.go (about) 1 package types // import "github.com/docker/docker/api/types" 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "sort" 7 ) 8 9 // PluginsListResponse contains the response for the Engine API 10 type PluginsListResponse []*Plugin 11 12 // UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType 13 func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error { 14 versionIndex := len(p) 15 prefixIndex := 0 16 if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' { 17 return fmt.Errorf("%q is not a plugin interface type", p) 18 } 19 p = p[1 : len(p)-1] 20 loop: 21 for i, b := range p { 22 switch b { 23 case '.': 24 prefixIndex = i 25 case '/': 26 versionIndex = i 27 break loop 28 } 29 } 30 t.Prefix = string(p[:prefixIndex]) 31 t.Capability = string(p[prefixIndex+1 : versionIndex]) 32 if versionIndex < len(p) { 33 t.Version = string(p[versionIndex+1:]) 34 } 35 return nil 36 } 37 38 // MarshalJSON implements json.Marshaler for PluginInterfaceType 39 func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) { 40 return json.Marshal(t.String()) 41 } 42 43 // String implements fmt.Stringer for PluginInterfaceType 44 func (t PluginInterfaceType) String() string { 45 return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version) 46 } 47 48 // PluginPrivilege describes a permission the user has to accept 49 // upon installing a plugin. 50 type PluginPrivilege struct { 51 Name string 52 Description string 53 Value []string 54 } 55 56 // PluginPrivileges is a list of PluginPrivilege 57 type PluginPrivileges []PluginPrivilege 58 59 func (s PluginPrivileges) Len() int { 60 return len(s) 61 } 62 63 func (s PluginPrivileges) Less(i, j int) bool { 64 return s[i].Name < s[j].Name 65 } 66 67 func (s PluginPrivileges) Swap(i, j int) { 68 sort.Strings(s[i].Value) 69 sort.Strings(s[j].Value) 70 s[i], s[j] = s[j], s[i] 71 }