diff --git a/cmd/get.go b/cmd/get.go index 6a502cbfc..f347ed601 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -201,7 +201,7 @@ func downloadPackages(nodes []*doc.Node) { doc.ColorLog("[SUCC] Downloaded package( %s => %s:%s )\n", n.ImportPath, n.Type, n.Value) downloadCount++ - //saveNode(nod) + saveNode(nod) } } else { doc.ColorLog("[WARN] Skipped downloaded package( %s => %s:%s )\n", diff --git a/cmd/serve.go b/cmd/serve.go index c45f93db7..2deb473be 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -15,18 +15,17 @@ package cmd import ( + serrors "errors" "fmt" + "github.com/gpmgo/gopm/doc" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/errors" "github.com/syndtr/goleveldb/leveldb/opt" "io/ioutil" "net/http" "os" - "os/user" "strconv" "strings" - - "github.com/gpmgo/gopm/doc" ) var ( @@ -144,6 +143,21 @@ func batchPut(batch *leveldb.Batch, key string, value string) error { return nil } +func saveNode(nod *doc.Node) error { + url := fmt.Sprintf("http://%v:%v/add?%v", "localhost", "8991", nod.ImportPath) + resp, err := http.Get(url) + if err != nil { + doc.ColorLog(err.Error()) + return err + } + defer resp.Body.Close() + + if resp.StatusCode == 200 { + return nil + } + return serrors.New("save node failed with " + resp.Status) +} + func addNode(nod *doc.Node) error { batch := new(leveldb.Batch) strLastId, err := dbGet("lastId") @@ -316,14 +330,13 @@ func runningStatus() (int, int, int) { } func startService(listen string) { - // check the pre serve's type - curUser, err := user.Current() + homeDir, err := doc.HomeDir() if err != nil { fmt.Println(err) return } - dbDir = strings.Replace(dbDir, "~", curUser.HomeDir, -1) + dbDir = strings.Replace(dbDir, "~", homeDir, -1) db, err = leveldb.OpenFile(dbDir, &opt.Options{Flag: opt.OFCreateIfMissing}) if err != nil { diff --git a/doc/utils.go b/doc/utils.go index 271625bba..5c072916a 100644 --- a/doc/utils.go +++ b/doc/utils.go @@ -17,11 +17,12 @@ package doc import ( "fmt" "os" + "os/user" "path" "regexp" "runtime" "strings" - "syscall" + //"syscall" ) // IsExist returns if a file or directory exists @@ -144,14 +145,14 @@ func printColorLevel(level string) { default: cc = WWhite } - - kernel32 := syscall.NewLazyDLL("kernel32.dll") + fmt.Println(cc) + /*kernel32 := syscall.NewLazyDLL("kernel32.dll") proc := kernel32.NewProc("SetConsoleTextAttribute") handle, _, _ := proc.Call(uintptr(syscall.Stdout), uintptr(cc)) fmt.Print(level) handle, _, _ = proc.Call(uintptr(syscall.Stdout), uintptr(WSilver)) CloseHandle := kernel32.NewProc("CloseHandle") - CloseHandle.Call(handle) + CloseHandle.Call(handle)*/ } // GetGOPATH returns all paths in GOPATH variable. @@ -761,3 +762,12 @@ var standardPath = map[string]bool{ func IsGoRepoPath(importPath string) bool { return standardPath[importPath] } + +func HomeDir() (string, error) { + curUser, err := user.Current() + if err != nil { + return "", err + } + + return curUser.HomeDir, nil +} diff --git a/doc/utils_windows.go b/doc/utils_windows.go new file mode 100644 index 000000000..c389f04ac --- /dev/null +++ b/doc/utils_windows.go @@ -0,0 +1,15 @@ +package doc + +import ( + "errors" + "os" +) + +func HomeDir() (string, error) { + dir := os.Getenv("userprofile") + if dir == "" { + return "", errors.New() + } + + return dir, nil +} diff --git a/docs/features_CN.md b/docs/features_CN.md index 5c057e38b..923c91bf3 100644 --- a/docs/features_CN.md +++ b/docs/features_CN.md @@ -2,6 +2,7 @@ gopm ==== * [总体设计目标](#10) +* [程序结构](#11) * [Go包版本说明](#20) * [各命令的目标和作用](#30) * [gopm help](#31) @@ -30,6 +31,16 @@ gopm 5. 支持依赖管理 6. 支持从github, code.google.com, gitLab, 等常见的源码托管服务下载 + +#最终程序只有一个,但是通过配置,可以有三种模式: +1 独立服务器 +2 子服务器 +3 客户端(默认) + +##独立服务器 + +独立服务器就是本身的包都是直接从源服务器中获取的。 + #Go包版本说明 diff --git a/gopm.go b/gopm.go index b45cae609..2131453aa 100644 --- a/gopm.go +++ b/gopm.go @@ -85,9 +85,9 @@ func initialize() bool { func main() { // Initialization. - if !initialize() { + /*if !initialize() { return - } + }*/ // Check length of arguments. args := os.Args[1:]