PracticeDev/study_go/wiki/simple.go

28 lines
537 B
Go

// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, this is %s!\n", r.URL.Path[1:])
fmt.Printf("Hi %s\n", r.URL)
}
func main() {
http.HandleFunc("/", handler)
fmt.Println("server in http://127.0.0.1:9999")
log.Fatal(http.ListenAndServe("127.0.0.1:9999", nil))
}