github.com/openimsdk/tools@v0.0.49/utils/mageutil/path.go (about) 1 package mageutil 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 ) 8 9 var ( 10 OpenIMRoot string 11 OpenIMOutputConfig string 12 OpenIMOutput string 13 OpenIMOutputTools string 14 OpenIMOutputTmp string 15 OpenIMOutputLogs string 16 OpenIMOutputBin string 17 OpenIMOutputBinPath string 18 OpenIMOutputBinToolPath string 19 OpenIMInitErrLogFile string 20 OpenIMInitLogFile string 21 OpenIMOutputHostBin string 22 OpenIMOutputHostBinTools string 23 ) 24 25 func init() { 26 currentDir, err := os.Getwd() 27 if err != nil { 28 panic("Error getting current directory: " + err.Error()) 29 } 30 31 OpenIMRoot = currentDir 32 33 OpenIMOutputConfig = filepath.Join(OpenIMRoot, "config") + string(filepath.Separator) 34 OpenIMOutput = filepath.Join(OpenIMRoot, "_output") + string(filepath.Separator) 35 36 OpenIMOutputTools = filepath.Join(OpenIMOutput, "tools") + string(filepath.Separator) 37 OpenIMOutputTmp = filepath.Join(OpenIMOutput, "tmp") + string(filepath.Separator) 38 OpenIMOutputLogs = filepath.Join(OpenIMOutput, "logs") + string(filepath.Separator) 39 OpenIMOutputBin = filepath.Join(OpenIMOutput, "bin") + string(filepath.Separator) 40 41 OpenIMOutputBinPath = filepath.Join(OpenIMOutputBin, "platforms") + string(filepath.Separator) 42 OpenIMOutputBinToolPath = filepath.Join(OpenIMOutputBin, "tools") + string(filepath.Separator) 43 44 OpenIMInitErrLogFile = filepath.Join(OpenIMOutputLogs, "openim-init-err.log") 45 OpenIMInitLogFile = filepath.Join(OpenIMOutputLogs, "openim-init.log") 46 47 OpenIMOutputHostBin = filepath.Join(OpenIMOutputBinPath, OsArch()) + string(filepath.Separator) 48 OpenIMOutputHostBinTools = filepath.Join(OpenIMOutputBinToolPath, OsArch()) + string(filepath.Separator) 49 50 dirs := []string{ 51 OpenIMOutputConfig, 52 OpenIMOutput, 53 OpenIMOutputTools, 54 OpenIMOutputTmp, 55 OpenIMOutputLogs, 56 OpenIMOutputBin, 57 OpenIMOutputBinPath, 58 OpenIMOutputBinToolPath, 59 OpenIMOutputHostBin, 60 OpenIMOutputHostBinTools, 61 } 62 63 for _, dir := range dirs { 64 createDirIfNotExist(dir) 65 } 66 } 67 68 func createDirIfNotExist(dir string) { 69 if err := os.MkdirAll(dir, 0755); err != nil { 70 fmt.Printf("Failed to create directory %s: %v\n", dir, err) 71 os.Exit(1) 72 } 73 } 74 75 // GetBinFullPath constructs and returns the full path for the given binary name. 76 func GetBinFullPath(binName string) string { 77 binFullPath := filepath.Join(OpenIMOutputHostBin, binName) 78 return binFullPath 79 } 80 81 // GetToolFullPath constructs and returns the full path for the given tool name. 82 func GetToolFullPath(toolName string) string { 83 toolFullPath := filepath.Join(OpenIMOutputHostBinTools, toolName) 84 return toolFullPath 85 }