OSDN Git Service

update
[bytom/shuttle.git] / swap / request.go
index 615860a..28c1294 100644 (file)
@@ -8,40 +8,10 @@ import (
        "net/http"
 )
 
-var (
-       localURL = "http://127.0.0.1:9888/"
-
-       buildTransactionURL   = localURL + "build-transaction"
-       getTransactionURL     = localURL + "get-transaction"
-       signTransactionURL    = localURL + "sign-transaction"
-       submitTransactionURL  = localURL + "submit-transaction"
-       compileURL            = localURL + "compile"
-       decodeProgramURL      = localURL + "decode-program"
-       listAccountsURL       = localURL + "list-accounts"
-       listAddressesURL      = localURL + "list-addresses"
-       listBalancesURL       = localURL + "list-balances"
-       listPubkeysURL        = localURL + "list-pubkeys"
-       listUnspentOutputsURL = localURL + "list-unspent-outputs"
-)
-
-// func request(URL string, data []byte) []byte {
-//     req, err := http.NewRequest("POST", URL, bytes.NewBuffer(data))
-//     req.Header.Set("Content-Type", "application/json")
-
-//     client := &http.Client{}
-//     resp, err := client.Do(req)
-//     if err != nil {
-//             panic(err)
-//     }
-//     defer resp.Body.Close()
-
-//     body, err := ioutil.ReadAll(resp.Body)
-//     if err != nil {
-//             fmt.Println(err)
-//     }
-//     // fmt.Println("response Body:", string(body))
-//     return body
-// }
+type Server struct {
+       IP   string
+       Port string
+}
 
 type response struct {
        Status    string          `json:"status"`
@@ -49,8 +19,9 @@ type response struct {
        ErrDetail string          `json:"error_detail"`
 }
 
-func request(url string, payload []byte, respData interface{}) error {
-       resp := &response{}
+func (s *Server) request(apiURL string, payload []byte, respData interface{}) error {
+       url := "http://" + s.IP + ":" + s.Port + "/" + apiURL
+       resp := new(response)
        if err := post(url, payload, resp); err != nil {
                return err
        }