httputil

package
v12.41.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package httputil provides methods for working with HTTP request/responses

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDescByCode

func GetDescByCode(code int) string

GetDescByCode returns response code description

Example
fmt.Println("200:", GetDescByCode(200))
fmt.Println("404:", GetDescByCode(404))
Output:

200: OK
404: Not Found

func GetPortByScheme

func GetPortByScheme(s string) string

GetPortByScheme returns port for supported scheme

Example
fmt.Println(GetPortByScheme("https"))
Output:

443

func GetRemoteAddr

func GetRemoteAddr(r *http.Request) (string, string)

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

func GetRemoteHost(r *http.Request) string

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

func GetRemotePort(r *http.Request) string

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

func GetRequestAddr(r *http.Request) (string, string)

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

func GetRequestHost(r *http.Request) string

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

func GetRequestPort(r *http.Request) string

GetRequestPort returns port from request struct

Example
r, _ := http.NewRequest("GET", "https://http.cat/200", nil)

fmt.Println(GetRequestPort(r))
Output:

443

func IsURL

func IsURL(url string) bool

IsURL check if given value is valid URL or not

Example
url1 := "https://domain.com"
url2 := "httpj://domain.com"

fmt.Printf("%s: %t\n", url1, IsURL(url1))
fmt.Printf("%s: %t\n", url2, IsURL(url2))
Output:

https://domain.com: true
httpj://domain.com: false

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL