1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package com
- import (
- "errors"
- "os"
- "path/filepath"
- "runtime"
- "strings"
- )
- func GetGOPATHs() []string {
- gopath := os.Getenv("GOPATH")
- var paths []string
- if runtime.GOOS == "windows" {
- gopath = strings.Replace(gopath, "\\", "/", -1)
- paths = strings.Split(gopath, ";")
- } else {
- paths = strings.Split(gopath, ":")
- }
- return paths
- }
- func GetSrcPath(importPath string) (appPath string, err error) {
- paths := GetGOPATHs()
- for _, p := range paths {
- if IsExist(p + "/src/" + importPath + "/") {
- appPath = p + "/src/" + importPath + "/"
- break
- }
- }
- if len(appPath) == 0 {
- return "", errors.New("Unable to locate source folder path")
- }
- appPath = filepath.Dir(appPath) + "/"
- if runtime.GOOS == "windows" {
-
- appPath = strings.Replace(appPath, "\\", "/", -1)
- }
- return appPath, nil
- }
- func HomeDir() (home string, err error) {
- if runtime.GOOS == "windows" {
- home = os.Getenv("USERPROFILE")
- if len(home) == 0 {
- home = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
- }
- } else {
- home = os.Getenv("HOME")
- }
- if len(home) == 0 {
- return "", errors.New("Cannot specify home directory because it's empty")
- }
- return home, nil
- }
|