Documentation ¶
Overview ¶
Package httputil provides methods for working with HTTP request/responses
Index ¶
- func GetDescByCode(code int) string
- func GetPortByScheme(s string) string
- func GetRemoteAddr(r *http.Request) (string, string)
- func GetRemoteHost(r *http.Request) string
- func GetRemotePort(r *http.Request) string
- func GetRequestAddr(r *http.Request) (string, string)
- func GetRequestHost(r *http.Request) string
- func GetRequestPort(r *http.Request) string
- func IsFTP(url string) bool
- func IsHTTP(url string) bool
- func IsHTTPS(url string) bool
- func IsURL(url string) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDescByCode ¶
GetDescByCode returns response code description
Example ¶
fmt.Println("200:", GetDescByCode(200)) fmt.Println("404:", GetDescByCode(404))
Output: 200: OK 404: Not Found
func GetPortByScheme ¶
GetPortByScheme returns port for supported scheme
Example ¶
fmt.Println(GetPortByScheme("https"))
Output: 443
func GetRemoteAddr ¶
GetRemoteAddr returns network address that sent the request
Example ¶
r, _ := http.NewRequest("GET", "https://http.cat/200", nil) r.RemoteAddr = "127.0.0.1:19371" fmt.Println(GetRemoteAddr(r))
Output: 127.0.0.1 19371
func GetRemoteHost ¶
GetRemoteHost returns host that sent the request
Example ¶
r, _ := http.NewRequest("GET", "https://http.cat/200", nil) r.RemoteAddr = "127.0.0.1:19371" fmt.Println(GetRemoteHost(r))
Output: 127.0.0.1
func GetRemotePort ¶
GetRemotePort returns port of the host that sent the request
Example ¶
r, _ := http.NewRequest("GET", "https://http.cat/200", nil) r.RemoteAddr = "127.0.0.1:19371" fmt.Println(GetRemotePort(r))
Output: 19371
func GetRequestAddr ¶
GetRequestAddr returns host and port info from request
Example ¶
r, _ := http.NewRequest("GET", "https://http.cat/200", nil) fmt.Println(GetRequestAddr(r))
Output: http.cat 443
func GetRequestHost ¶
GetRequestHost returns host from request struct
Example ¶
r, _ := http.NewRequest("GET", "https://http.cat/200", nil) fmt.Println(GetRequestHost(r))
Output: http.cat
func GetRequestPort ¶
GetRequestPort returns port from request struct
Example ¶
r, _ := http.NewRequest("GET", "https://http.cat/200", nil) fmt.Println(GetRequestPort(r))
Output: 443
func IsFTP ¶ added in v12.57.0
IsFTP returns true if given URL contains ftp scheme
Example ¶
url1 := "ftp://domain.com" url2 := "http://domain.com" fmt.Printf("%s: %t\n", url1, IsFTP(url1)) fmt.Printf("%s: %t\n", url2, IsFTP(url2))
Output: ftp://domain.com: true http://domain.com: false
func IsHTTP ¶ added in v12.57.0
IsHTTP returns true if given URL contains http scheme
Example ¶
url1 := "https://domain.com" url2 := "http://domain.com" fmt.Printf("%s: %t\n", url1, IsHTTP(url1)) fmt.Printf("%s: %t\n", url2, IsHTTP(url2))
Output: https://domain.com: false http://domain.com: true
func IsHTTPS ¶ added in v12.57.0
IsHTTPS returns true if given URL contains https scheme
Example ¶
url1 := "https://domain.com" url2 := "http://domain.com" fmt.Printf("%s: %t\n", url1, IsHTTPS(url1)) fmt.Printf("%s: %t\n", url2, IsHTTPS(url2))
Output: https://domain.com: true http://domain.com: false
Types ¶
This section is empty.