http server
Node.js
const http = require('http')
function handler(request, response) {
response.writeHead(200, { 'Content-type':'text/plain' })
response.write('hello world')
response.end()
}
const server = http.createServer(handler)
server.listen(8080)
Output
$ curl http://localhost:8080
hello world
Go
package main
import (
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("hello world"))
}
func main() {
http.HandleFunc("/", handler)
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
Output
$ curl http://localhost:8080
hello world
当前内容版权归 miguelmota 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 miguelmota .