1. 程式人生 > >golang搭建web服務器

golang搭建web服務器

req http imp quest fun wro div write bsp

一個最簡單的golang web服務器

package main

import (
    "net/http"
    "fmt"
)

func sayHelloWorld(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello Wrold!") //這個寫入到w的是輸出到客戶端的
}

func main() {
    http.HandleFunc("/",sayHelloWorld)
    http.ListenAndServe(":8899",nil)
}

golang搭建web服務器