1 Star 0 Fork 0

ChrainWang / gopm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
search.go 2.54 KB
一键复制 编辑 原始数据 按行查看 历史
Unknown 提交于 2013-12-05 16:21 . Freeze gopm get code for v0.6.0
// Copyright 2013 gopm authors.
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cmd
// import (
// "encoding/json"
// "fmt"
// "io/ioutil"
// "net/http"
// "github.com/Unknwon/com"
// )
// var CmdSearch = &Command{
// UsageLine: "search [keyword]",
// Short: "search for package",
// Long: `
// search packages
// The search flags are:
// -e
// search extactly, you should input an exactly package name as keyword
// `,
// }
// func init() {
// CmdSearch.Run = runSearch
// CmdSearch.Flags = map[string]bool{
// "-e": false,
// }
// }
// func printSearchPrompt(flag string) {
// switch flag {
// case "-e":
// com.ColorLog("[INFO] You enabled exactly search.\n")
// }
// }
// // search packages
// func runSearch(cmd *Command, args []string) {
// // Check length of arguments.
// if len(args) < 1 {
// com.ColorLog("[ERROR] Please input package's keyword.\n")
// return
// }
// var host, port string
// host = "localhost"
// port = "8991"
// if cmd.Flags["-e"] {
// search(host, port, args[0], true)
// } else {
// search(host, port, args[0], false)
// }
// }
// type searchRes struct {
// Pkg string
// Desc string
// }
// /*
// request local or remote search service to find packages according to keyword inputed
// */
// func search(host, port, keyword string, isExactly bool) {
// url := fmt.Sprintf("http://%v:%v/search?%v", host, port, keyword)
// if isExactly {
// url = fmt.Sprintf("http://%v:%v/searche?%v", host, port, keyword)
// }
// resp, err := http.Get(url)
// if err != nil {
// com.ColorLog(err.Error())
// return
// }
// defer resp.Body.Close()
// if resp.StatusCode == 200 {
// contents, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// com.ColorLog(err.Error())
// return
// }
// pkgs := make([]searchRes, 0)
// err = json.Unmarshal(contents, &pkgs)
// if err != nil {
// com.ColorLog(err.Error())
// return
// }
// for i, pkg := range pkgs {
// fmt.Println(i+1, pkg.Pkg, "\t", pkg.Desc)
// }
// } else {
// com.ColorLog(resp.Status)
// }
// }
1
https://gitee.com/chrain/gopm.git
git@gitee.com:chrain/gopm.git
chrain
gopm
gopm
v0.6.5

搜索帮助