MCPcopy Create free account
hub / github.com/codemistic/Web-Development / viewCodeHandler

Function viewCodeHandler

ResumeCreator/main.go:29–81  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

27}
28
29func viewCodeHandler(w http.ResponseWriter, r *http.Request) {
30 dataString := r.FormValue("dataString")
31 Mobi := r.FormValue("Mobi")
32 Email := r.FormValue("mail")
33
34 v := u.NewRequestPdf("")
35
36 //html template path
37 templatePath := "templates/sample.html"
38
39 //path for download pdf
40 outputPath := "storage/example.pdf"
41
42 //html template data
43 templateData := struct {
44 //Title string
45 Name string
46 Mobi string
47 Email string
48 Country string
49 }{
50 //Title: ,
51 Name: dataString,
52 Mobi: Mobi,
53 Email: Email,
54 Country: "Germany",
55 }
56
57 if err := v.ParseTemplate(templatePath, templateData); err == nil {
58 ok, _ := v.GeneratePDF(outputPath)
59 fmt.Println(ok, "pdf generated successfully")
60 } else {
61 fmt.Println(err)
62 }
63
64 f, err := os.Open(outputPath)
65 if err != nil {
66 fmt.Println(err)
67 w.WriteHeader(500)
68 return
69 }
70 defer f.Close()
71
72 //Set header
73 w.Header().Set("Content-type", "application/pdf")
74
75 //Stream to response
76 if _, err := io.Copy(w, f); err != nil {
77 fmt.Println(err)
78 w.WriteHeader(500)
79 }
80
81}

Callers

nothing calls this directly

Calls 2

ParseTemplateMethod · 0.95
GeneratePDFMethod · 0.95

Tested by

no test coverage detected