- package main
- import (
- "io"
- "log"
- "net/http"
- )
- func main() {
- //设置路由
- http.HandleFunc("/", sayHello)
- //启动http服务
- err := http.ListenAndServe(":8080", nil)
- if err != nil {
- log.Fatal(err)
- }
- }
- //Handler Func(参数规定)
- func sayHello(w http.ResponseWriter, r *http.Request) {
- io.WriteString(w, "Hello world is version1.")
- }
- //该片段来自于http://www.codesnippet.cn/detail/160920135897.html
来源: http://www.codesnippet.cn/detail/160920135897.html