Golang 中国
package main

import (
    "app/config"
    // "app/controllers"
    // _ "app/utils"
    "fmt"
    "github.com/gorilla/mux"
    "log"
    "net/http"
    "strconv"
)

func main() {
    r := mux.NewRouter()

    http.Handle("/js/", http.FileServer(http.Dir("dist")))
    http.Handle("/css/", http.FileServer(http.Dir("dist")))
    http.Handle("/fonts/", http.FileServer(http.Dir("dist")))
    http.Handle("/imgs/", http.FileServer(http.Dir("dist")))
    http.Handle("/vendor/", http.FileServer(http.Dir("dist")))

    r.HandleFunc("/", Sss)

    http.Handle("/", r)

    if err := http.ListenAndServe(config.ConfigObj.Host+":"+strconv.Itoa(config.ConfigObj.Port), nil); err != nil {
        log.Fatalln("ListenAndServe: ", err)
    }
}

func Sss(w http.ResponseWriter, r *http.Request) {
    fmt.Println("dsdsdsdsdsdss")
}

为什么Sss函数没有执行?
1 回复
fanyang
#1 fanyang • 2018-04-04 13:54

换成http.HandleFunc

需要 登录 后方可回复, 如果你还没有账号你可以 注册 一个帐号。