httputil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: CC0-1.0 Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClientIPAddress

func GetClientIPAddress(r *http.Request) string

func GetListenPort

func GetListenPort(hport string) string

applications need some way to access the port TODO: this method will work only after grace.Serve is called.

func GetUserAgent

func GetUserAgent(r *http.Request) string

func Listen

func Listen(hport string) (net.Listener, error)

This method can be used for any TCP Listener, e.g. non HTTP

func Serve

func Serve(hport string, handler http.Handler, gracefulTimeout, readTimeout, writeTimeout time.Duration) error

start serving on hport. If running via socketmaster, the hport argument is ignored. Also, if a port was specified via -p, it takes precedence on hport

Example
package main

import (
	"log"
	"net/http"
	"time"
)

func main() {
	timeout := 1 * time.Second
	http.HandleFunc("/foo/bar", foobarHandler)
	log.Fatal(Serve(":9000", nil, timeout, timeout, timeout))
}

func foobarHandler(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("foobar"))
}
Output:

func ServerFastHTTP

func ServerFastHTTP(hport string, handler fasthttp.RequestHandler) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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