mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:55:28 +08:00
20 lines
337 B
Go
Executable File
20 lines
337 B
Go
Executable File
// hello_server.go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type Hello struct{}
|
|
|
|
func (h Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprint(w, "Hello!")
|
|
}
|
|
|
|
func main() {
|
|
var h Hello
|
|
http.ListenAndServe("localhost:4000",h)
|
|
}
|
|
// Output in browser-window with url http://localhost:4000: Hello!
|