使用Go实现我们的第一个Web服务器程序

 

package main

import "net/http"
import "fmt"

//打印HelloWorld
func handler(writer http.ResponseWriter, request* http.Request) {
    fmt.Fprintf(writer, "HelloWorld,%s", request.URL.Path[1:] )
}


func main() {
    //设置数据路由,当请求/的时候默认把数据送给handler处理
    http.HandleFunc("/", handler)
    
    //监听8080端口
    http.ListenAndServe(":8080", nil)
}

 

相关文章:

  • 2021-06-10
  • 2021-10-17
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2022-02-23
  • 2022-02-01
  • 2021-05-07
猜你喜欢
  • 2021-06-21
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2022-02-09
  • 2021-08-26
相关资源
相似解决方案