update req package

master
wangyj 6 years ago
parent b38cbcb4af
commit b0df876166

@ -14,8 +14,9 @@ import (
"strings" "strings"
"time" "time"
"github.com/franela/goreq" // "github.com/franela/goreq"
"github.com/goji/httpauth" "github.com/goji/httpauth"
"github.com/imroc/req"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -91,9 +92,10 @@ func actionStartServer(c *cli.Context) error {
} }
func actionStatus(c *cli.Context) error { func actionStatus(c *cli.Context) error {
res, err := goreq.Request{ // res, err := goreq.Request{
Uri: cfg.Client.ServerURL + "/api/programs", // Uri: cfg.Client.ServerURL + "/api/programs",
}.Do() // }.Do()
res, err := req.Get(cfg.Client.ServerURL + "/api/programs")
if err != nil { if err != nil {
return err return err
} }
@ -114,10 +116,12 @@ func actionStatus(c *cli.Context) error {
// cmd: <start|stop> // cmd: <start|stop>
func programOperate(cmd, name string) (err error, success bool) { func programOperate(cmd, name string) (err error, success bool) {
res, err := goreq.Request{ // res, err := goreq.Request{
Method: "POST", // Method: "POST",
Uri: cfg.Client.ServerURL + "/api/programs/" + name + "/" + cmd, // Uri: cfg.Client.ServerURL + "/api/programs/" + name + "/" + cmd,
}.Do() // }.Do()
res, err := req.Post(cfg.Client.ServerURL + "/api/programs/" + name + "/" + cmd)
if err != nil { if err != nil {
return return
} }

@ -2,7 +2,7 @@ package: github.com/soopsio/gosuv
import: import:
- package: github.com/soopsio/kexec - package: github.com/soopsio/kexec
- package: github.com/equinox-io/equinox - package: github.com/equinox-io/equinox
- package: github.com/franela/goreq - package: github.com/imroc/req
- package: github.com/glycerine/rbuf - package: github.com/glycerine/rbuf
- package: github.com/go-yaml/yaml - package: github.com/go-yaml/yaml
- package: github.com/goji/httpauth - package: github.com/goji/httpauth

@ -11,7 +11,8 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/franela/goreq" // "github.com/franela/goreq"
"github.com/imroc/req"
"github.com/qiniu/log" "github.com/qiniu/log"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -31,16 +32,21 @@ type TagInfo struct {
func githubLatestVersion(repo, name string) (tag TagInfo, err error) { func githubLatestVersion(repo, name string) (tag TagInfo, err error) {
githubURL := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", repo, name) githubURL := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", repo, name)
req := goreq.Request{Uri: githubURL} // req := goreq.Request{Uri: githubURL}
r := req.New()
h := req.Header{}
ghToken := os.Getenv("GITHUB_TOKEN") ghToken := os.Getenv("GITHUB_TOKEN")
if ghToken != "" { if ghToken != "" {
req.AddHeader("Authorization", "token "+ghToken) // req.AddHeader("Authorization", "token "+ghToken)
h["Authorization"] = "token " + ghToken
} }
res, err := req.Do() // res, err := req.Do()
res, err := r.Get(githubURL, h)
if err != nil { if err != nil {
return return
} }
err = res.Body.FromJsonTo(&tag) // err = res.Body.FromJsonTo(&tag)
err := res.ToJSON(&tag)
return return
} }

Loading…
Cancel
Save