forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
34 lines (28 loc) · 1.18 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// https://play.golang.org/p/vB_ZytmqC1
// Sample program to show how to implement a handler function
// with the http package.
package main
import (
"fmt"
"net/http"
)
// HelloHandler shows how the http Handlers are the universal interface for
// handling http stuff, you will see that many Go developers rally around the
// http.Handler interface.
func HelloHandler(w http.ResponseWriter, r *http.Request) {
// Fprintln is a nice way to write formatted text out to a io.Writer
fmt.Fprintln(w, "Hello world")
}
func main() {
// Like many packages in the standard library, the http package has
// convenience methods that are declared on the package level. These methods
// actually delegate to an underlying structure that you can initialize
// yourself. In this example, we are adding a handler to the http.DefaultServeMux
http.HandleFunc("/", HelloHandler)
// ListenAndServe will listen on the specified host:port combo. Passing nil
// as the second argument means we will be using the http.DefaultServeMux as
// our http handler
http.ListenAndServe(":4000", nil)
}