go语言快速入门:BootStrap应用(16)

本文介绍了在Go语言Web编程中使用BootStrap的方法,包括BootStrap的简介、版本选择(3.3.7)、下载步骤、示例代码、模板文件的应用、执行确认及结果展示。强调了在实际开发中使用cdn简化操作,同时也指出自行设计Go Web框架时可能面临的挑战。
摘要由CSDN通过智能技术生成

这篇文章中我们将会通过简单的实例介绍如何在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"</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值