Documentation
¶
Overview ¶
Package http provides a set of types and functions for working with the http protocol.
It includes types for the http protocol, such as client and request.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultClientGet ¶
DefaultClientGet gets the html of a given url.
It uses the http.DefaultClient to make a GET request to the given url and returns the goquery document.
func GetLocalIP ¶
GetLocalIP returns the non loopback local IP of the host. It checks the address type and if it is not a loopback then it returns the IP.
Example:
ip, err := GetLocalIP()
if err != nil {
log.Fatal(err)
}
fmt.Println(ip)
// Output:
// 192.168.1.100
func HomeDir ¶
func HomeDir() string
HomeDir returns the home directory of the user that owns the current process.
Example:
fmt.Println(HomeDir()) // Output: /home/user
func IsTCPPortAvailable ¶
IsTCPPortAvailable returns a flag indicating whether or not a TCP port is available.
It takes a port as an integer as an argument and returns a boolean indicating whether or not the port is available.
Example:
package main
import "fmt"
import "github.com/cseval/cse-ncaa/pkg/ip"
func main() {
mux := http.NewServeMux()
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World"))
})
srv := &http.Server{
Addr: ":8080",
Handler: mux,
}
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)
}
if IsTCPPortAvailable(8080) {
fmt.Println("Port is available")
} else {
fmt.Println("Port is not available")
}
}
func ParseAddress ¶
ParseAddress parses a standard golang network address and returns the protocol and path.
Example:
ip.ParseAddress("ipv4://127.0.0.1:80/hello")
// Output:
// Protocol: ipv4
// Path: 127.0.0.1:80/hello
func RandomTCPPort ¶
func RandomTCPPort() int
RandomTCPPort gets a free, random TCP port between 1025-65535. If no free ports are available -1 is returned.
It returns an integer representing a random TCP port between 1025-65535. If no free ports are available, it returns -1.
Example:
package main
import "fmt"
import "github.com/cseval/cse-ncaa/pkg/ip"
func main() {
port := ip.RandomTCPPort()
fmt.Println(port)
}
Types ¶
This section is empty.