这篇文章中我们将会通过简单的实例介绍如何在go语言Web编程中使用BootStrap的方式
BootStrap
Bootstrap源于Twitter的一个机遇HTML/CSS/JS的前端开发框架,它由Twitter的Mark Otto和Jacob Thornton合作开发,简单灵活,使得 Web 开发更加快速便捷。
版本
目前BootStrap虽然推出了4.0.0,但是仍然是Alpha版。这篇文章中仍然使用稳定的BootStrap3.3.7版本。
项目 | 版本 |
---|---|
BootStrap版本 | 3.3.7 |
下载地址 | https://github.com/twbs/bootstrap/releases/download/v3.3.7/bootstrap-3.3.7-dist.zip |
下载
使用如下步骤,下载和准备BootStrap
步骤 | 详细 |
---|---|
Step 1 | wget https://github.com/twbs/bootstrap/releases/download/v3.3.7/bootstrap-3.3.7-dist.zip |
Step 2 | unzip bootstrap-3.3.7-dist.zip |
Step 3 | cd bootstrap-3.3.7-dist/ |
例子代码
[root@liumiaocn bootstrap-3.3.7-dist]# cat basic-web-bootstrap.go
package main
import "fmt"
import "net/http"
import "html/template"
func Hello(response http.ResponseWriter, request *http.Request) {
type person struct {
Id int
Name string
Country string
}
liumiaocn := person{Id: 1001, Name: "liumiaocn", Country: "China"}
tmpl, err := template.ParseFiles("./user.tpl")
if err != nil {
fmt.Println("Error happened..")
}
tmpl.Execute(response, liumiaocn)
}
func main() {
http.HandleFunc("/", Hello)
http.ListenAndServe(":8080", nil)
}
[root@liumiaocn bootstrap-3.3.7-dist]#
BootStrap模板文件
例子中使用的bootstrap.min.css和bootstrap.min.js均使用了cdn进行引用。
[root@liumiaocn bootstrap-3.3.7-dist]# cat user.tpl
<html lang="en"</