Documentation ¶
Overview ¶
Package golisten allows a user to user http.ListenAndServe with any port as root and effectively accept the incomming connection as an other un-privileged user.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe wraps `http.ListenAndServe`. Listen as root and accept as `targetUser`.
Example ¶
package main import ( "fmt" "log" "net/http" "os/user" ) func handler(w http.ResponseWriter, req *http.Request) { u, err := user.Current() if err != nil { log.Printf("Error getting user: %s", err) return } fmt.Fprintf(w, "%s\n", u.Uid) } func main() { ln, err := Listen("guillaume", "tcp", ":80") if err != nil { log.Fatal(err) } http.HandleFunc("/", handler) log.Fatal(http.Serve(ln, nil)) }
Output:
Example ¶
package main import ( "fmt" "log" "net/http" "os/user" ) func handler(w http.ResponseWriter, req *http.Request) { u, err := user.Current() if err != nil { log.Printf("Error getting user: %s", err) return } fmt.Fprintf(w, "%s\n", u.Uid) } func main() { http.HandleFunc("/", handler) log.Fatal(ListenAndServe("guillaume", ":80", nil)) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.