Learning Gorilla Toolkit and golang so please go easy here. Would like to render .css, .js, and .jpeg files in their corresponding folders.
File Structure is:
ROOT/
|--main.go, message.go
|
|Templates/
| |--index.html,confirmation.html
|
|Static/
|
|css/
|--ex1.css, ex2.css
|
|js/
|--ex1.js, ex2.js
|
|Images/
|--ex1.jpeg, ex2.jpeg
Package main with gorilla pat and mux as follows:
package main
import (
"github.com/gorilla/mux"
"github.com/gorilla/pat"
"html/template"
"log"
"net/http"
)
func main() {
r := pat.New()
r.Get("/", http.HandlerFunc(index))
r.Post("/", http.HandlerFunc(send))
r.Get("/confirmation", http.HandlerFunc(confirmation))
log.Println("Listening...")
http.ListenAndServe(":8080",r)
router := mux.NewRouter()
router.HandleFunc("/", Home)
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/",http.FileServer(http.Dir(./static/))))
http.Handle("/", router)
err := http.ListenAndServe(":8443", router)
if err != nil {
log.Fatalln(err)
}
}
Getting error:
.\main.go:23: syntax error: unexpected .
Not sure how to run multiple http servers through func main to start app and render all files nested in static folder.
http.Dirtakes a string as an argument. You need to havehttp.Dir("./static"). There's also no space between the assignment operator:=andhttp.ListenAndServe, as well as mixed cases forindexandIndexhandler functions. - elithrar