1. 程式人生 > 其它 >"LollipopGo/library/lollipop/common" 測試2

"LollipopGo/library/lollipop/common" 測試2

/*
Golang語言社群(www.Golang.Ltd)
作者:cserli
時間:2018年3月2日
*/
package main

import (
        "LollipopGo/library/lollipop/common"     // Assign統一模板的資料
        "LollipopGo/library/lollipop/controller" // 控制器包--其實就是路由包(也就是訪問路徑的包)
        "fmt"
        "net/http"
)

// 資料結構
type Info struct {
        Title string
        Name  string
        Site  string
}

// 控制器定義變數
var ControllerHub *controller.Tcontroller

// 初始化函式
func init() {
        fmt.Println("Entry INIT!!!")
        return
}

// 主函式
func main() {
        fmt.Println("Entry main!!!")
        // 控制器(路由)

        // -- for迴圈去取資料--在lollipopGo控制器層設定的
        http.HandleFunc("/index", index)
        // -- end()

        // 監聽埠
        err := http.ListenAndServe(":8866", nil)
        if err != nil {
                fmt.Println("ListenAndServe:", err)
        }
        return
}

// 路由函式
func index(w http.ResponseWriter, r *http.Request) {
        info := Info{"社群網站", "cserli", "http://www.golang.ltd/"}
        // 模板路徑
        Lcommon.Assign("template/index.html").Execute(w, info)
        return
}

Golang語言社群 開源輕量級web應用框架,可以快速建立部落格及商城等

git地址:https://github.com/Golangltd/lollipopgo