예제 #1
0
func main() {

	p, err := poetry.LoadPoem("wordsworth.txt")
	if err != nil {
		fmt.Printf("Error loading poem: %s\n", err)
	}
	fmt.Printf("%s\n", p)
}
예제 #2
0
파일: main.go 프로젝트: mukulrawat1986/code
func poemHandler(w http.ResponseWriter, r *http.Request) {

	// Parse the form
	r.ParseForm()
	poemName := r.Form["name"][0]

	p, err := poetry.LoadPoem(poemName)
	if err != nil {
		http.Error(w, "File not found", http.StatusInternalServerError)
	} else {
		// http.ResponseWriter implements the io writer interface
		fmt.Fprintf(w, "%s\n", p)
	}
}
예제 #3
0
파일: main.go 프로젝트: mukulrawat1986/code
func poemHandler(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	poemName := r.Form["name"][0]

	p, err := poetry.LoadPoem(poemName)
	fmt.Printf("Loading poem done")
	if err != nil {
		http.Error(w, "File not found", http.StatusInternalServerError)
	} else {
		//		fmt.Fprintf(w, "%s\n", p)
		pwt := poemWithTitle{poemName, p}
		enc := json.NewEncoder(w)
		enc.Encode(pwt)
	}
}
예제 #4
0
func poemHandler(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()
	if err != nil {
		log.Println("ParseForm Error", err)
	}

	poemName := r.Form["name"][0]
	p, err := poetry.LoadPoem(poemName)
	if err != nil {
		log.Println("LoadPoem Error", err)
	} else {
		pwt := poemWithTitle{poemName, p}
		enc := json.NewEncoder(w)
		enc.Encode(pwt)
	}
}
예제 #5
0
func poemHandler(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()
	if err != nil {
		log.Println("ParseForm Error", err)
	}
	poemName := r.Form["name"][0]

	p, err := poetry.LoadPoem(poemName)

	if err != nil {
		log.Println("Loading Poem Error", err)
	} else {
		// Since we have defined the Stringer interface on the poem we can just print it out
		fmt.Fprintf(w, "%s", p)
		log.Println("Poem requested and served ", poemName)
	}
}
예제 #6
0
파일: main.go 프로젝트: mukulrawat1986/code
func main() {
	p, _ := poetry.LoadPoem("wordsworth.txt")
	fmt.Printf("%T %T\n", p, p.NumStanzas())

}