mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-02-10 05:35:53 +08:00
Deploying to gh-pages from @ eunomia-bpf/bpf-developer-tutorial@c120bb4912 🚀
This commit is contained in:
BIN
31-goroutine/go-server-http/main
Executable file
BIN
31-goroutine/go-server-http/main
Executable file
Binary file not shown.
34
31-goroutine/go-server-http/main.go
Normal file
34
31-goroutine/go-server-http/main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var http_body []byte
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(http_body)
|
||||
}
|
||||
|
||||
func main() {
|
||||
args := os.Args
|
||||
if len(args) > 1 {
|
||||
body_len, _ := strconv.ParseInt(args[1], 10, 64)
|
||||
http_body = make([]byte, body_len)
|
||||
rand.Read(http_body)
|
||||
fmt.Println("Body set to", body_len, "bytes of random stuff")
|
||||
} else {
|
||||
http_body = []byte("Hello,World!")
|
||||
}
|
||||
http.HandleFunc("/", handler)
|
||||
fmt.Println("Server started!")
|
||||
err := http.ListenAndServe(":447", nil)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start server: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user