学习 Gorilla Toolkit 和 golang 所以请在这里轻松一点。想要在其对应的文件夹中呈现 .css、.js 和 .jpeg 文件。
文件结构为:
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
用 gorilla pat 和 mux 打包 main 如下:
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)
}
}
得到错误:
.\main.go:23: syntax error: unexpected .
不知道如何通过 func main 运行多个 http 服务器来启动应用程序并渲染嵌套在静态文件夹中的所有文件。