diff --git a/main.go b/main.go index 085dca5..115c8c5 100644 --- a/main.go +++ b/main.go @@ -27,17 +27,14 @@ func init() { } 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 { case "GET": if redirect, ok := short.Get(r.URL.Path[1:]); ok{ http.Redirect(w, r, string(redirect), 301) fmt.Printf("Token: %s Redirect to: %s \n", string(r.URL.Path[1:]), redirect) } else { - P := Page{Title: "All: ", Body: short.All ()} t, _ := template.ParseFiles("template/index.gohtml") - t.Execute(w, P) + t.Execute(w, nil) } case "POST": 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() { 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 if err != nil { log.Fatal("ListenAndServe: ", err)