initial commit
This commit is contained in:
commit
8666e4461c
6 changed files with 242 additions and 0 deletions
31
example/main.go
Normal file
31
example/main.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.giftfish.de/ston1th/godrop"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := godrop.Config{
|
||||
User: "nobody",
|
||||
Group: "nobody",
|
||||
}
|
||||
err := godrop.Drop(cfg, func() (net.Listener, error) { return net.Listen("tcp", ":80") })
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
l, err := godrop.GetListener()
|
||||
if err != nil {
|
||||
fmt.Println("Failed to listen on FD 3:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "pid %d\nuid %d\ngid %d", os.Getpid(), os.Getuid(), os.Getgid())
|
||||
}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue