go語言原生web框架 golang項目-書城商店

go語言原生web框架 golang項目-書城商店

golang書城商店功能介紹

書城主頁 分頁展示 價格搜索 登錄注冊 加入購物車 購買 我的訂單 查看詳情

后臺管理 圖書管理 添加修改刪除圖書 訂單管理 發(fā)貨

go語言原生web框架開發(fā)的一個 "書城商店" 網(wǎng)站 數(shù)據(jù)庫使用mysql

使用技術(shù)

  • golang原生web框架

  • Mysql數(shù)據(jù)庫

  • html前端

  • js框架jquery

功能展示

主頁.jpg
登錄.jpg
注冊.jpg
購物車.jpg
價格搜索.jpg
我的訂單.jpg
訂單詳情.jpg
圖書管理.jpg
訂單管理.jpg

主方法

main.go

package main

import (
    "book-store/controller"
    "net/http"
    "os"
)

func main() {
    parseStatic()
    userHandler()
    bookHandler()
    cartHandler()
    orderHandler()
    //8080端口監(jiān)聽 多路復(fù)用器為nil表示使用默認(rèn)值
    http.ListenAndServe(":8080", nil)
}

func parseStatic() {
    //設(shè)置處理靜態(tài)資源(css和js文件)
    //http.StripPrefix(prefix string , h Handler) Handler
    //http.StripPrefix返回一個處理器,該處理器會將請求的URL.Path字段中給定前綴prefix去除后,再交給h處理。如果prefix為空會回復(fù)404。
    //此時html中的所有URL地址以static開頭的資源都能被加載出來(pages同理)
    //邏輯:如果訪問"/static/"開頭的資源,就去"書城項目/views/static"里找(pages同理)
    path, _ := os.Getwd()
    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(path+"/views/static"))))
    http.Handle("/pages/", http.StripPrefix("/pages/", http.FileServer(http.Dir(path+"/views/pages"))))
}

func userHandler() {
    //去首頁
    http.HandleFunc("/", controller.GetPageBooksByPrice)
    //去登錄
    http.HandleFunc("/login", controller.LoginHandler)
    //去注冊
    http.HandleFunc("/regist", controller.RegistHandler)
    //去注銷
    http.HandleFunc("/logout", controller.LogoutHandler)
    //Ajax請求驗證用戶名是否可用
    http.HandleFunc("/checkUserName", controller.CheckUserName)
}

func bookHandler() {
    ////去圖書管理(所有的)
    //http.HandleFunc("/getPageBooks",controller.GetBooks)
    //去圖書管理(帶分頁的)
    http.HandleFunc("/getPageBooks", controller.GetPageBooks)
    //去刪除圖書
    http.HandleFunc("/deleteBooks", controller.DeleteBooks)
    //去更新或添加圖書信息輸入頁
    http.HandleFunc("/toUpdateOrAddBooks", controller.ToUpdateOrAddBooks)
    //去更新或添加圖書
    http.HandleFunc("/updateOrAddBooks", controller.UpdateOrAddBooks)
    //去獲取圖書價格范圍分頁
    http.HandleFunc("/getPageBooksByPrice", controller.GetPageBooksByPrice)
}

func cartHandler() {
    //去添加圖書到購物車
    http.HandleFunc("/addBookCart", controller.AddBookCart)
    //去獲取購物車信息
    http.HandleFunc("/getCartInfo", controller.GetCartInfo)
    //去清空購物車
    http.HandleFunc("/deleteCart", controller.DeleteCart)
    //去刪除購物項
    http.HandleFunc("/deleteCartItem", controller.DeleteCartItem)
    //更新購物項
    http.HandleFunc("/updateCartItem", controller.UpdateCart)
}

func orderHandler() {
    //去結(jié)賬
    http.HandleFunc("/checkout", controller.Checkout)
    //去訂單管理
    http.HandleFunc("/getOrder", controller.GetOrder)
    //去獲取訂單詳情
    http.HandleFunc("/getOrderInfo", controller.GetOrderInfo)
    //去我的訂單
    http.HandleFunc("/getMyOrder", controller.GetMyOrder)
    //去發(fā)貨
    http.HandleFunc("/sendOrder", controller.SendOrder)
    //去確認(rèn)收貨
    http.HandleFunc("/takeOrder", controller.TakeOrder)
}

運行

創(chuàng)建數(shù)據(jù)庫, 然后修改數(shù)據(jù)庫連接相關(guān)信息。

go run main.go

訪問: http://127.0.0.1:8080/
賬號/密碼: abc/123456

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容