|
|
@ -15,18 +15,17 @@ |
|
|
|
package cmd |
|
|
|
package cmd |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
serrors "errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"github.com/gpmgo/gopm/doc" |
|
|
|
"github.com/syndtr/goleveldb/leveldb" |
|
|
|
"github.com/syndtr/goleveldb/leveldb" |
|
|
|
"github.com/syndtr/goleveldb/leveldb/errors" |
|
|
|
"github.com/syndtr/goleveldb/leveldb/errors" |
|
|
|
"github.com/syndtr/goleveldb/leveldb/opt" |
|
|
|
"github.com/syndtr/goleveldb/leveldb/opt" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/user" |
|
|
|
|
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gpmgo/gopm/doc" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
@ -144,6 +143,21 @@ func batchPut(batch *leveldb.Batch, key string, value string) error { |
|
|
|
return nil |
|
|
|
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 { |
|
|
|
func addNode(nod *doc.Node) error { |
|
|
|
batch := new(leveldb.Batch) |
|
|
|
batch := new(leveldb.Batch) |
|
|
|
strLastId, err := dbGet("lastId") |
|
|
|
strLastId, err := dbGet("lastId") |
|
|
@ -316,14 +330,13 @@ func runningStatus() (int, int, int) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func startService(listen string) { |
|
|
|
func startService(listen string) { |
|
|
|
// check the pre serve's type
|
|
|
|
homeDir, err := doc.HomeDir() |
|
|
|
curUser, err := user.Current() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
fmt.Println(err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dbDir = strings.Replace(dbDir, "~", curUser.HomeDir, -1) |
|
|
|
dbDir = strings.Replace(dbDir, "~", homeDir, -1) |
|
|
|
|
|
|
|
|
|
|
|
db, err = leveldb.OpenFile(dbDir, &opt.Options{Flag: opt.OFCreateIfMissing}) |
|
|
|
db, err = leveldb.OpenFile(dbDir, &opt.Options{Flag: opt.OFCreateIfMissing}) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|