version 2.0.0
This commit is contained in:
parent
108583814e
commit
de6a48c088
10 changed files with 84 additions and 108 deletions
35
example/port80fg.go
Normal file
35
example/port80fg.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.giftfish.de/ston1th/godrop/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := godrop.Config{
|
||||
User: "nobody",
|
||||
Group: "nobody",
|
||||
Foreground: true,
|
||||
}
|
||||
err := godrop.Drop(cfg, func() (net.Listener, error) { return net.Listen("tcp", ":80") })
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
l, err := godrop.GetListener()
|
||||
if err != nil {
|
||||
log.Fatal("Failed to listen on FD 3:", err)
|
||||
}
|
||||
_, port, _ := net.SplitHostPort(l.Addr().String())
|
||||
|
||||
fmt.Printf("port %s\npid %d\nuid %d\ngid %d\n", port, os.Getpid(), os.Getuid(), os.Getgid())
|
||||
|
||||
http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "port %s\npid %d\nuid %d\ngid %d", port, os.Getpid(), os.Getuid(), os.Getgid())
|
||||
}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue