Golang:02-Web 开发的本质

一个请求对应一个响应。

一个简单的服务器

package main

import (
   "fmt"
   "io/ioutil"
   "net/http"
)

func sayHello(w http.ResponseWriter, r *http.Request) {
   b, _ := ioutil.ReadFile("./hello.txt")
   _, _ = fmt.Fprintln(w, string(b))
}

func main() {
   http.HandleFunc("/hello", sayHello)
   err := http.ListenAndServe(":9090", nil)
   if err != nil {
      fmt.Printf("http serve faild, err = %v", err)
      return
   }
}


你可能感兴趣的:(golang)