go简易http服务器,测试用

http

package main

import (
	"fmt"
	"net/http"
	"os"
)

func hello(w http.ResponseWriter, r *http.Request) {
	hostName, _ := os.Hostname()
	fmt.Fprintf(w, "hello i am %s", hostName)
}

func main() {
	http.HandleFunc("/", hello)
	err := http.ListenAndServe("0.0.0.0:9000", nil)
	if err != nil {
		fmt.Println("http listen failed")
	}
}
原文地址:https://www.cnblogs.com/HachikoT/p/14269942.html