github.com/demonoid81/containerd@v1.3.4/plugin/plugin_go18.go (about) 1 // +build go1.8,!windows,amd64,!static_build 2 3 /* 4 Copyright The containerd Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package plugin 20 21 import ( 22 "fmt" 23 "path/filepath" 24 "plugin" 25 "runtime" 26 ) 27 28 // loadPlugins loads all plugins for the OS and Arch 29 // that containerd is built for inside the provided path 30 func loadPlugins(path string) error { 31 abs, err := filepath.Abs(path) 32 if err != nil { 33 return err 34 } 35 pattern := filepath.Join(abs, fmt.Sprintf( 36 "*-%s-%s.%s", 37 runtime.GOOS, 38 runtime.GOARCH, 39 getLibExt(), 40 )) 41 libs, err := filepath.Glob(pattern) 42 if err != nil { 43 return err 44 } 45 for _, lib := range libs { 46 if _, err := plugin.Open(lib); err != nil { 47 return err 48 } 49 } 50 return nil 51 } 52 53 // getLibExt returns a platform specific lib extension for 54 // the platform that containerd is running on 55 func getLibExt() string { 56 switch runtime.GOOS { 57 case "windows": 58 return "dll" 59 default: 60 return "so" 61 } 62 }