Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "html/template"
- "io/ioutil"
- "net/http"
- )
- var tpl *template.Template
- func init() {
- tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
- }
- func main() {
- http.HandleFunc("/", index)
- http.Handle("/favicon.ico", http.NotFoundHandler())
- http.ListenAndServe(":8080", nil)
- }
- func index(res http.ResponseWriter, req *http.Request) {
- var s string
- if req.Method == http.MethodPost {
- f, _, err := req.FormFile("fails")
- if err != nil {
- http.Error(res, err.Error(), http.StatusInternalServerError)
- return
- }
- defer f.Close()
- bs, err := ioutil.ReadAll(f)
- if err != nil {
- http.Error(res, err.Error(), http.StatusInternalServerError)
- return
- }
- s = string(bs)
- }
- tpl.ExecuteTemplate(res, "index.gohtml", s)
- }
- =============================================
- <!DOCTYPE html>
- <html>
- <head>
- <title>GoLang :P</title>
- </head>
- <body>
- <form method="Post" enctype="multipart/form-data">
- <input type="file" name="fails">
- <input type="submit">
- <br><br>
- <h3>{{.}}</h3>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement