代码拉取完成,页面将自动刷新
package mego
import (
"errors"
"log"
"net/http"
"path"
)
type HandlerFunc func(http.ResponseWriter, *http.Request) interface{}
// UseStarter attach an starter to the server
func (s *Server) UseStarter(starter Starter) {
if starter == nil {
panic(errors.New("starter is nil"))
}
s.starters = append(s.starters, starter)
}
// MapRootPath Returns the physical file path that corresponds to the specified virtual path.
// @param virtualPath: the virtual path starts with
// @return the absolute file path
func (s *Server) MapRootPath(virtualPath string) string {
if len(virtualPath) == 0 {
return s.webRoot
}
return ClearFilePath(path.Join(s.webRoot, virtualPath))
}
// MapContentPath Returns the physical file path that corresponds to the specified virtual path.
// @param virtualPath: the virtual path starts with
// @return the absolute file path
func (s *Server) MapContentPath(virtualPath string) string {
if len(virtualPath) == 0 {
return s.contentRoot
}
return ClearFilePath(path.Join(s.contentRoot, virtualPath))
}
// Run run the application as http
func (s *Server) Run() {
s.init()
log.Printf("INFO: the server is listening on address %s\r\n", s.addr)
err := http.ListenAndServe(s.addr, s)
panicErr(err)
}
// RunTLS run the application as https
func (s *Server) RunTLS(certFile, keyFile string) {
s.init()
log.Printf("INFO: the server is listening on address %s, TLS\r\n", s.addr)
err := http.ListenAndServeTLS(s.addr, certFile, keyFile, s)
panicErr(err)
}
// NewServer create a new server
//
// webRoot: the root of this web server. and the content root is '${webRoot}/www'
//
// addr: the address the server is listen on
func NewServer(webRoot, addr string) *Server {
if len(webRoot) == 0 {
webRoot = GetExeDir()
}
webRoot = path.Clean(ClearFilePath(webRoot))
if len(addr) == 0 {
addr = ":8888"
}
var s = &Server{
webRoot: webRoot,
contentRoot: webRoot + "/www",
addr: addr,
routing: newRouteTree(),
}
return s
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。