Adds v46 command
This commit is contained in:
parent
b87e722658
commit
4b26877517
41
main.go
Normal file
41
main.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// command v46 serves http on various network types
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const resp = `{"ok": true}
|
||||||
|
`
|
||||||
|
|
||||||
|
var port = flag.Int("port", 8400, "listening port")
|
||||||
|
var both = flag.Bool("both", false, "listen on ipv4 and ipv6")
|
||||||
|
var dur = flag.Duration("dur", 10*time.Second, "how long to sleep before giving a request")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
time.Sleep(*dur)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
fmt.Fprintf(w, resp)
|
||||||
|
})
|
||||||
|
|
||||||
|
a := fmt.Sprintf(":%d", *port)
|
||||||
|
log.Printf("listening on: %+v", a)
|
||||||
|
proto := "tcp4"
|
||||||
|
if *both {
|
||||||
|
proto = "tcp"
|
||||||
|
}
|
||||||
|
l, err := net.Listen(proto, a)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
if err := http.Serve(l, nil); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user