-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
main.go
67 lines (55 loc) · 1.95 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Our web app will be a micro-blogging site. It will only allow people to
share 140 characters of their thoughts per post. GL2U.
An example of a tweet could be:
GOLANG WEB APP TRAININGS from Silicon Valley Code @sv_code_camp 1 of 2:
https://youtu.be/qeREX9r20YQ 2 of 2: https://youtu.be/cIatklLmr5I
Learn more about documenting your code:
https://golang.org/doc/effective_go.html#commentary
http://blog.golang.org/godoc-documenting-go-code
Use the godoc command to see your documentation:
https://godoc.org/golang.org/x/tools/cmd/godoc
Try these godoc commands:
godoc .
godoc -http=:6060
*/
package main
import (
"html/template"
"log"
"net/http"
)
// tpl holds all of our templates.
var tpl *template.Template
// main is the entry point for our web app. main parses our templates.
// main handles our routing and defines our end-points. Doc comments work
// best as complete sentences, which allow a wide variety of automated
// presentations. The first sentence should be a one-sentence summary
// that starts with the name being declared.
func main() {
GodocExperiment()
godocUnexported()
tpl = template.Must(template.ParseGlob("templates/html/*.html"))
http.HandleFunc("/", home)
http.Handle("/favicon.ico", http.NotFoundHandler())
http.Handle("/public/", http.StripPrefix("/public", http.FileServer(http.Dir("public/"))))
log.Fatal(http.ListenAndServe(":8080", nil))
}
// home handles everything coming into the root of our web app.
func home(res http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/" {
http.NotFound(res, req)
return
}
tpl.ExecuteTemplate(res, "home.html", nil)
}
// GodocExperiment tests whether or not exported functions appear in
// documentation when godoc is run.
func GodocExperiment() {
log.Println("This is a godoc EXPORTED experiment")
}
// godocUnexported tests whether or not exported functions appear in
// documentation when godoc is run.
func godocUnexported() {
log.Println("This is a godoc UNEXPORTED experiment")
}