Go HTTP 客戶端庫:go-rest

jopen 10年前發布 | 15K 次閱讀 go-rest 網絡工具包

這是一個簡單的工具用于構建更實用的 HTTP 客戶端。

已經在Go1.0以上的版本測試過。

package main

import "fmt"
import "github.com/danryan/go-rest/rest"

type githubUser struct {
  Login string `json:"login"`
  Name  string `json:"name"`
}

func main() {
  c, _ := rest.New("https://api.github.com", nil)
  c.Header.Set("Content-Type", "application/json")
  c.Header.Set("Accept", "application/json")

  user := &githubUser{}

  _, err := c.Get("users/danryan", user)
  if err != nil {
    panic(err)
  }

  fmt.Printf("%s's name is %s\n", user.Login, user.Name)
}

項目主頁:http://www.baiduhome.net/lib/view/home/1414245829653

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!