点域服务器与大猩猩多路复用器

时间:2015-09-05 08:54:04

标签: go gorilla

我有一个小型服务器,我希望该服务器使用gorilla / mux包来监听我的自定义域sftablet.dev。

以下是代码:

package main

import (
    "fmt"
    "net/http"

    "github.com/gorilla/mux"
)

func main() {
    r := mux.NewRouter()
    r.Host("sftablet.dev")
    r.HandleFunc("/", HomeHandler)
    r.HandleFunc("/products", ProductsHandler)
    http.ListenAndServe(":8080", r)
}

func HomeHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hey, this is homepage")
}

func ProductsHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hey, this is products")
}

我还在hosts文件中添加了这个:

127.0.0.1       sftablet.dev

但由于某种原因,它不起作用。如果我转到127.0.0.1:8080,它会工作,但是当我访问http://sftablet.dev/时却不行。还清除了DNS缓存。

1 个答案:

答案 0 :(得分:2)

http://sftablet.dev/默认情况下会查询端口80

您的服务器只侦听端口8080. http://sftablet.dev:8080/应该可以正常工作。

相关问题