public snapshot · system/tools/nib/bench/xlang/ · system@main · commit a92f56ab098e · shared 2026-11-22T22:43:57Z· frozen: this page does not change when the repository does
1 // The HTTP benchmark: GET /plaintext and GET /json on port 18441, with the
2 // standard library's net/http and encoding/json.
3 package main
4
5 import (
6 "encoding/json"
7 "log"
8 "net/http"
9 )
10
11 type message struct {
12 Message string `json:"message"`
13 }
14
15 func main() {
16 mux := http.NewServeMux()
17 mux.HandleFunc("GET /plaintext", func(w http.ResponseWriter, r *http.Request) {
18 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
19 w.Write([]byte("Hello, World!"))
20 })
21 mux.HandleFunc("GET /json", func(w http.ResponseWriter, r *http.Request) {
22 w.Header().Set("Content-Type", "application/json; charset=utf-8")
23 json.NewEncoder(w).Encode(message{Message: "Hello, World!"})
24 })
25 log.Fatal(http.ListenAndServe("0.0.0.0:18441", mux))
26 }
snapshot of a92f56ab098e · 2858 files · browse