go - 使用 gorilla mux 指向域去服务器

标签 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")
}

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

127.0.0.1       sftablet.dev

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

最佳答案

http://sftablet.dev/ 默认查询端口 80

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

关于go - 使用 gorilla mux 指向域去服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32411219/

相关文章:

http - 带有静态文件的 Go Gorilla mux 子路由器

go - 在 Go 中向特定客户端发送 Websocket 消息(使用 Gorilla)

json - Golang 使用类型

concurrency - Go Memory Model文档中给出的这个例子失败的原因是什么?

go - 如何使用 math/big 对 bigInt 求模?

go - 尝试同步 goroutine 时出现死锁错误

pointers - 在循环中重置指针

AngularJS 页面不从服务器刷新

戈朗 : Type Assertion Error issue

json - 如何列出 Gorilla Mux 中的所有变量?