github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/common/path.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package common 13 14 import ( 15 "fmt" 16 "os" 17 "path/filepath" 18 "runtime" 19 ) 20 21 // MakeName creates a node name that follows the sberex convention 22 // for such names. It adds the operation system name and Go runtime version 23 // the name. 24 func MakeName(name, version string) string { 25 return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version()) 26 } 27 28 func FileExist(filePath string) bool { 29 _, err := os.Stat(filePath) 30 if err != nil && os.IsNotExist(err) { 31 return false 32 } 33 34 return true 35 } 36 37 func AbsolutePath(Datadir string, filename string) string { 38 if filepath.IsAbs(filename) { 39 return filename 40 } 41 return filepath.Join(Datadir, filename) 42 }