Add path all

master
kreativmonkey 7 years ago
parent 315dd5e62f
commit 14836d8b8c

@ -27,17 +27,14 @@ func init() {
} }
func index(w http.ResponseWriter, r *http.Request) { func index(w http.ResponseWriter, r *http.Request) {
fmt.Println("method: ", r.Method) //get request method
fmt.Println("Path: ", r.URL.Path[1:])
switch r.Method { switch r.Method {
case "GET": case "GET":
if redirect, ok := short.Get(r.URL.Path[1:]); ok{ if redirect, ok := short.Get(r.URL.Path[1:]); ok{
http.Redirect(w, r, string(redirect), 301) http.Redirect(w, r, string(redirect), 301)
fmt.Printf("Token: %s Redirect to: %s \n", string(r.URL.Path[1:]), redirect) fmt.Printf("Token: %s Redirect to: %s \n", string(r.URL.Path[1:]), redirect)
} else { } else {
P := Page{Title: "All: ", Body: short.All ()}
t, _ := template.ParseFiles("template/index.gohtml") t, _ := template.ParseFiles("template/index.gohtml")
t.Execute(w, P) t.Execute(w, nil)
} }
case "POST": case "POST":
var test string var test string
@ -53,8 +50,15 @@ func index(w http.ResponseWriter, r *http.Request) {
} }
func all(w http.ResponseWriter, r *http.Request) {
t, _ := template.New("all").Parse("{{.}}")
t.Execute(w, short.All())
}
func main() { func main() {
http.HandleFunc("/", index) // setting router rule http.HandleFunc("/", index) // setting router rule
http.HandleFunc("/all", all) // setting router rule
http.HandleFunc("/put", index) // setting router rule
err := http.ListenAndServe(":9090", nil) // setting listening port err := http.ListenAndServe(":9090", nil) // setting listening port
if err != nil { if err != nil {
log.Fatal("ListenAndServe: ", err) log.Fatal("ListenAndServe: ", err)

Loading…
Cancel
Save