Rename http clients/servers to singular language: client/server
This commit is contained in:
38
examples/http-client/http-client.go
Normal file
38
examples/http-client/http-client.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// The Go standard library comes with excellent support
|
||||
// for HTTP clients and servers in the `net/http`
|
||||
// package. In this example we'll use it to issue simple
|
||||
// HTTP requests.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Issue an HTTP GET request to a server. `http.Get` is a
|
||||
// convenient shortcut around creating an `http.Client`
|
||||
// object and calling its `Get` method; it uses the
|
||||
// `http.DefaultClient` object which has useful default
|
||||
// settings.
|
||||
resp, err := http.Get("https://gobyexample.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Print the HTTP response status.
|
||||
fmt.Println("Response status:", resp.Status)
|
||||
|
||||
// Print the first 5 lines of the response body.
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
for i := 0; scanner.Scan() && i < 5; i++ {
|
||||
fmt.Println(scanner.Text())
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
7
examples/http-client/http-client.sh
Normal file
7
examples/http-client/http-client.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
$ go run http-clients.go
|
||||
Response status: 200 OK
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Go by Example</title>
|
||||
2
examples/http-client/http-clients.hash
Normal file
2
examples/http-client/http-clients.hash
Normal file
@@ -0,0 +1,2 @@
|
||||
1497e193431e4740f593039f613773daaf97772e
|
||||
vFW_el7oHMk
|
||||
Reference in New Issue
Block a user