Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84c454b
commit f0996f8
Showing
4 changed files
with
47 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// PagesController 处理静态页面 | ||
type PagesController struct { | ||
} | ||
|
||
// Home 首页 | ||
func (*PagesController) Home(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprint(w, "<h1>Hello, 欢迎来到 goblog!</h1>") | ||
} | ||
|
||
// About 关于我们页面 | ||
func (*PagesController) About(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprint(w, "此博客是用以记录编程笔记,如您有反馈或建议,请联系 "+ | ||
"<a href=\"mailto:summer@example.com\">summer@example.com</a>") | ||
} | ||
|
||
// NotFound 404 页面 | ||
func (*PagesController) NotFound(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusNotFound) | ||
fmt.Fprint(w, "<h1>请求页面未找到 :(</h1><p>如有疑惑,请联系我们。</p>") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package routes | ||
|
||
import ( | ||
"goblog/app/http/controllers" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
// RegisterWebRoutes 注册网页相关路由 | ||
func RegisterWebRoutes(r *mux.Router) { | ||
|
||
// 静态页面 | ||
pc := new(controllers.PagesController) | ||
r.NotFoundHandler = http.HandlerFunc(pc.NotFound) | ||
r.HandleFunc("/", pc.Home).Methods("GET").Name("home") | ||
r.HandleFunc("/about", pc.About).Methods("GET").Name("about") | ||
} |