1. 程式人生 > >golang實現相容Linux和Windows的路徑處理

golang實現相容Linux和Windows的路徑處理

//==========================================
//建立時間:2017-4-20 首次建立
//功能描述:windows和Linux下路徑相容處理
//==========================================

package env
import (
    "os"
    "runtime"
)

var ostype = runtime.GOOS

func GetProjectPath() string{
    var projectPath string
    projectPath, _ = os.Getwd()
    return projectPath
}

func GetConfigPath() string{
    path := GetProjectPath()
    if ostype == "windows"{
        path = path + "\\" + "config\\"
    }else if ostype == "linux"{
        path = path +"/" + "config/"
    }
    return  path
}

func GetConLogPath() string{
    path := GetProjectPath()
    if ostype == "windows"{
        path = path + "\\log\\"
    }else if ostype == "linux"{
        path = path + "/log/"
    }
    return  path
}