"Resty"의 두 판 사이의 차이

13번째 줄: 13번째 줄:
   fmt.Println(resp)
   fmt.Println(resp)
}
}
</syntaxhighlight>
<syntaxhighlight lang='go' run>
package main
import "fmt"
import "github.com/go-resty/resty/v2"
func main() {
  // Create a Resty Client
  client := resty.New()
  resp, err := client.R().
    EnableTrace().
    Get("https://httpbin.org/get")
  // Explore response object
  fmt.Println("Response Info:")
  fmt.Println("  Error      :", err)
  fmt.Println("  Status Code:", resp.StatusCode())
  fmt.Println("  Status    :", resp.Status())
  fmt.Println("  Proto      :", resp.Proto())
  fmt.Println("  Time      :", resp.Time())
  fmt.Println("  Received At:", resp.ReceivedAt())
  fmt.Println("  Body      :\n", resp)
  fmt.Println()
  // Explore trace info
  fmt.Println("Request Trace Info:")
  ti := resp.Request.TraceInfo()
  fmt.Println("  DNSLookup    :", ti.DNSLookup)
  fmt.Println("  ConnTime      :", ti.ConnTime)
  fmt.Println("  TCPConnTime  :", ti.TCPConnTime)
  fmt.Println("  TLSHandshake  :", ti.TLSHandshake)
  fmt.Println("  ServerTime    :", ti.ServerTime)
  fmt.Println("  ResponseTime  :", ti.ResponseTime)
  fmt.Println("  TotalTime    :", ti.TotalTime)
  fmt.Println("  IsConnReused  :", ti.IsConnReused)
  fmt.Println("  IsConnWasIdle :", ti.IsConnWasIdle)
  fmt.Println("  ConnIdleTime  :", ti.ConnIdleTime)
  fmt.Println("  RequestAttempt:", ti.RequestAttempt)
  fmt.Println("  RemoteAddr    :", ti.RemoteAddr.String())
}
</syntaxhighlight>
</syntaxhighlight>



2021년 4월 6일 (화) 13:28 판

1 개요

Resty
  • 간단한 HTTP 및 REST 클라이언트 Go 라이브러리
  • inspired by Ruby rest-client
package main
import "fmt"
import "github.com/go-resty/resty/v2"
func main() {
  client := resty.New()
  resp, _ := client.R().Get("https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt")
  fmt.Println(resp)
}
package main
import "fmt"
import "github.com/go-resty/resty/v2"
func main() {
  // Create a Resty Client
  client := resty.New()

  resp, err := client.R().
    EnableTrace().
    Get("https://httpbin.org/get")

  // Explore response object
  fmt.Println("Response Info:")
  fmt.Println("  Error      :", err)
  fmt.Println("  Status Code:", resp.StatusCode())
  fmt.Println("  Status     :", resp.Status())
  fmt.Println("  Proto      :", resp.Proto())
  fmt.Println("  Time       :", resp.Time())
  fmt.Println("  Received At:", resp.ReceivedAt())
  fmt.Println("  Body       :\n", resp)
  fmt.Println()

  // Explore trace info
  fmt.Println("Request Trace Info:")
  ti := resp.Request.TraceInfo()
  fmt.Println("  DNSLookup     :", ti.DNSLookup)
  fmt.Println("  ConnTime      :", ti.ConnTime)
  fmt.Println("  TCPConnTime   :", ti.TCPConnTime)
  fmt.Println("  TLSHandshake  :", ti.TLSHandshake)
  fmt.Println("  ServerTime    :", ti.ServerTime)
  fmt.Println("  ResponseTime  :", ti.ResponseTime)
  fmt.Println("  TotalTime     :", ti.TotalTime)
  fmt.Println("  IsConnReused  :", ti.IsConnReused)
  fmt.Println("  IsConnWasIdle :", ti.IsConnWasIdle)
  fmt.Println("  ConnIdleTime  :", ti.ConnIdleTime)
  fmt.Println("  RequestAttempt:", ti.RequestAttempt)
  fmt.Println("  RemoteAddr    :", ti.RemoteAddr.String())
}

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}