From 7332e5e6f89db175711285a3e4668096838b7043 Mon Sep 17 00:00:00 2001 From: hycka <1051899827@qq.com> Date: Fri, 19 Mar 2021 13:55:36 +0800 Subject: [PATCH] f-dev --- opencc.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/opencc.go b/opencc.go index 78550ec..fa73f5c 100644 --- a/opencc.go +++ b/opencc.go @@ -9,9 +9,9 @@ import ( "os" "path/filepath" "reflect" - "runtime" "strings" + "github.com/hi20160616/gears" "github.com/liuzl/da" ) @@ -23,14 +23,22 @@ var ( ) func defaultDir() string { - if runtime.GOOS == "windows" { - return `C:\gocc\` - } if goPath, ok := os.LookupEnv("GOPATH"); ok { - return goPath + "/src/github.com/liuzl/gocc/" - } else { - return `/usr/local/share/gocc/` + //judge whether the path exists + //goPath + "/src/github.com/liuzl/gocc/" or "/pkg/mod/github.com/liuzl/gocc/" + //if those path do not exist, return current work dir + p := goPath + "/src/github.com/liuzl/gocc/" + if gears.Exists(p) { + return p + } else if p = goPath + "/pkg/mod/github.com/liuzl/gocc?/"; gears.Exists(p) { + return p + } + } + path, err := os.Getwd() + if err != nil { + return "" } + return path + "/internal/gocc/" } // Group holds a sequence of dicts