结构

└── main.go

└── static

└──── css

└── ── ── main.css

└── ── js

└── ── ── main.js

└── view

└── ── index.html

若有如上目录结构

代码

func main() {
    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) // 启动静态文件服务
    // ...
}
<!-- index.html -->
<link rel="stylesheet" href="/static/css/main.css" type="text/css">
<script type="text/javascript" src="/static/js/main.js"></script>
⤧  Next page golang中的模板template ⤧  Previous page struct匿名字段,interface和断言