本文整理汇总了Golang中net/http.Dir函数的典型用法代码示例。如果您正苦于以下问题:Golang Dir函数的具体用法?Golang Dir怎么用?Golang Dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
err := LoadConfig()
if err != nil {
log.Fatal("Could not load config file hidemyemail.cfg")
return
}
g_conn_string = g_config.DbConnectionString
http.Handle("/captcha/", captcha.Server(captcha.StdWidth, captcha.StdHeight))
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(g_config.ResourcePath+"/images"))))
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir(g_config.ResourcePath+"/css"))))
http.HandleFunc("/add",
func(w http.ResponseWriter, r *http.Request) {
handleAdd(w, r)
})
http.HandleFunc("/get",
func(w http.ResponseWriter, r *http.Request) {
handleGet(w, r)
})
http.HandleFunc("/",
func(w http.ResponseWriter, r *http.Request) {
handleGetCaptcha(w, r)
})
log.Fatal(http.ListenAndServe(":"+g_config.Port, nil))
}
示例2: main
func main() {
defer db.Close()
http.HandleFunc("/main", handleMain)
http.HandleFunc("/demo", handleDemo)
http.HandleFunc("/logout", auth.HandleLogout)
http.HandleFunc("/authorize", auth.HandleAuthorize)
http.HandleFunc("/oauth2callback", auth.HandleOAuth2Callback)
http.HandleFunc("/categoryList/", handleCategoryList)
http.HandleFunc("/category/", handleCategory)
http.HandleFunc("/feed/list/", handleFeedList)
http.HandleFunc("/feed/new/", handleNewFeed)
http.HandleFunc("/feed/", handleFeed)
http.HandleFunc("/entry/mark/", handleMarkEntry)
http.HandleFunc("/entry/", handleEntry)
http.HandleFunc("/entries/", handleEntries)
http.HandleFunc("/menu/select/", handleSelectMenu)
http.HandleFunc("/menu/", handleMenu)
http.HandleFunc("/stats/", handleStats)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
http.Handle("/favicon.ico", http.StripPrefix("/favicon.ico", http.FileServer(http.Dir("./static/favicon.ico"))))
http.HandleFunc("/", handleRoot)
go feed.CacheAllCats() //create cache for categories at startup
go feed.CacheAllFeeds() //create cache for feeds at startup
print("Listening on 127.0.0.1:" + port + "\n")
http.ListenAndServe("127.0.0.1:"+port, nil)
}
示例3: init
func init() {
initTemplate()
http.HandleFunc("/", rootHandler)
http.HandleFunc("/find/", findHandler)
http.Handle("/css/", http.FileServer(http.Dir(".")))
http.Handle("/js/", http.FileServer(http.Dir(".")))
}
示例4: main
func main() {
var err error
cwd, _ := os.Getwd()
client := flag.String("client", path.Join(cwd, "client"), "Full path to client directory.")
addr := flag.String("listen", "127.0.0.1:8088", "Listen address.")
templates, err = template.ParseGlob(path.Join(*client, "*.html"))
if err != nil {
log.Fatal("Failed to load templates: ", err)
}
flag.Parse()
go h.run()
http.HandleFunc("/", serveClient)
http.HandleFunc("/realtimetraffic", serveWs)
http.Handle("/css/", http.FileServer(http.Dir(*client)))
http.Handle("/scripts/", http.FileServer(http.Dir(*client)))
http.Handle("/img/", http.FileServer(http.Dir(*client)))
http.Handle("/favicon.ico", http.FileServer(http.Dir(*client)))
err = http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
示例5: Serve
func Serve(httpAddress *string, db core.Database, s *search.Searcher, devAssets bool, updater *torrent.StatsUpdater) {
// Add SVG to mime directory
mime.AddExtensionType(".svg", "image/svg+xml")
r := mux.NewRouter()
apirouter := ApiRouter(db, s, updater)
r.PathPrefix("/api/").Handler(apirouter)
if devAssets {
log.Println("Debug mode is on. Serving development assets from angular/app.")
r.PathPrefix("/styles/").Handler(http.FileServer(http.Dir("frontend/angular/.tmp/")))
r.PathPrefix("/bower_components/").Handler(http.FileServer(http.Dir("frontend/angular/")))
r.PathPrefix("/").Handler(NotFoundHook{
http.FileServer(http.Dir("frontend/angular/app/")),
"frontend/angular/app/index.html"})
} else {
r.PathPrefix("/").Handler(NotFoundHook{
http.FileServer(http.Dir("frontend/angular/dist/")),
"frontend/angular/dist/index.html"})
}
http.Handle("/", r)
log.Println("Web server listening on", *httpAddress)
err := http.ListenAndServe(*httpAddress, nil)
if err != nil {
log.Println(err)
}
}
示例6: registerStaticHandlers
func (this *HttpEndpoint) registerStaticHandlers(staticPath string) {
this.mux.Handle("/", http.FileServer(http.Dir(staticPath)))
pathPrefix := "/tutorial/"
pathValue := staticPath + pathPrefix
this.mux.PathPrefix(pathPrefix).Handler(http.StripPrefix(pathPrefix,
http.FileServer(http.Dir(pathValue))))
}
示例7: main
func main() {
flag.Parse()
if *index != "" {
searcher = search.NewSearcher(*index, *prefix)
}
r := mux.NewRouter()
r.PathPrefix("/src").Methods("GET").
Handler(http.StripPrefix("/src", http.FileServer(http.Dir(*src))))
r.PathPrefix("/api/search").Methods("POST").HandlerFunc(searchHandler)
// Single-page app URLs are always served with the index page.
r.PathPrefix("/file/").Methods("GET").
Handler(&SingleFile{path.Join(*app, "index.html")})
r.Path("/search").Methods("GET").
Handler(&SingleFile{path.Join(*app, "index.html")})
r.PathPrefix("/").Methods("GET").
Handler(http.FileServer(http.Dir(*app)))
http.ListenAndServe(":8080", r)
}
示例8: init
func init() {
if templates == nil {
templates = make(map[string]*template.Template)
}
templates["index"] = template.Must(template.ParseFiles("tmpl/base.tmpl", "tmpl/index.tmpl"))
templates["index1"] = template.Must(template.ParseFiles("tmpl/base.tmpl", "tmpl/index1.tmpl"))
templates["edit"] = template.Must(template.ParseFiles("tmpl/base.tmpl", "tmpl/edit.tmpl"))
templates["preview"] = template.Must(template.ParseFiles("tmpl/preview.tmpl"))
//handle image/css and generated html files
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
http.Handle("/_images/", http.StripPrefix("/_images/", http.FileServer(http.Dir("_images"))))
http.Handle("/_html/", http.StripPrefix("/_html/", http.FileServer(http.Dir("_html"))))
http.Handle("/_html/_images/", http.StripPrefix("/_html/_images/", http.FileServer(http.Dir("_html/_images"))))
http.Handle("/_html/css", http.StripPrefix("/_html/css", http.FileServer(http.Dir("_html/css"))))
// set up html options
htmlExt = 0
htmlExt |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
htmlExt |= blackfriday.EXTENSION_TABLES
htmlExt |= blackfriday.EXTENSION_FENCED_CODE
htmlExt |= blackfriday.EXTENSION_AUTOLINK
htmlExt |= blackfriday.EXTENSION_STRIKETHROUGH
htmlExt |= blackfriday.EXTENSION_SPACE_HEADERS
htmlFlags = blackfriday.HTML_USE_XHTML |
blackfriday.HTML_USE_SMARTYPANTS |
blackfriday.HTML_SMARTYPANTS_FRACTIONS |
blackfriday.HTML_SMARTYPANTS_LATEX_DASHES |
blackfriday.HTML_FOOTNOTE_RETURN_LINKS |
blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES
}
示例9: main
func main() {
parseConstants()
PrefixLookup.LoadPrefixes()
file, e := ioutil.ReadFile(qsoFile)
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}
json.Unmarshal(file, &qsls)
listOfContactedCountries = getListOfCountries()
listOfContactsPerCountry = getContactsPerCountry()
http.Handle("/compressedCards/", http.StripPrefix("/compressedCards",
http.FileServer(http.Dir(path.Join(rootdir, convertedFolder)))))
http.Handle("/thumbnails/", http.StripPrefix("/thumbnails",
http.FileServer(http.Dir(path.Join(rootdir, resizedFolder)))))
http.Handle("/cards/", http.StripPrefix("/cards",
http.FileServer(http.Dir(path.Join(rootdir, cardsFolder)))))
http.Handle("/images/", http.StripPrefix("/images",
http.FileServer(http.Dir(path.Join(rootdir, imagesFolder)))))
http.Handle("/html/", http.StripPrefix("/html",
http.FileServer(http.Dir(path.Join(rootdir, "/html")))))
http.HandleFunc("/", index)
http.HandleFunc("/browse/", browse)
http.HandleFunc("/country/", browseCountry)
http.HandleFunc("/view/", displayCard)
http.HandleFunc("/api/", apiGetCall)
fmt.Printf("Web Server started\n")
http.ListenAndServe(":8080", nil)
}
示例10: main
func main() {
flagWork := flag.String("work", "work", "")
flagAddr := flag.String("addr", ":4020", "")
flag.Parse()
root, err := rootPath()
if err != nil {
panic(err)
}
r := pork.NewRouter(
func(status int, r *http.Request) {
log.Printf("%d - %s", status, r.URL.Path)
}, nil, nil)
r.RespondWith("/", pork.Content(pork.NewConfig(pork.None),
http.Dir(filepath.Join(root, "src/pub"))))
r.RespondWith("/data/", pork.Content(pork.NewConfig(pork.None),
http.Dir(*flagWork)))
log.Printf("Server running on address %s\n", *flagAddr)
if err := http.ListenAndServe(*flagAddr, r); err != nil {
panic(err)
}
}
示例11: listen
func (server *WebServer) listen() {
if server.httpServer.FileDescriptor == 0 {
server.LogInfoF("listening on %s", server.httpServer.Addr)
} else {
server.LogInfoF("listening on existing file descriptor %d, %s", server.httpServer.FileDescriptor, server.httpServer.Addr)
}
handleFunc("/", server.logReq, server.index)
//handleFunc("/restart", server.logReq, server.restart)
//handleFunc("/shutdown", server.logReq, server.shutdown)
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("./app/css"))))
http.Handle("/imgs/", http.StripPrefix("/imgs/", http.FileServer(http.Dir("./app/imgs"))))
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("./app/js"))))
items := []string{"apple-touch-icon.png", "crossdomain.xml", "favicon.ico", "humans.txt", "robots.txt", "tile-wide.png", "tile.png", "browserconfig.xml"}
for _, k := range items {
handleFunc("/"+k, server.logReq, func(w http.ResponseWriter, req *http.Request) {
http.ServeFile(w, req, "./"+k)
})
}
err := server.httpServer.ListenAndServe()
if err != nil {
server.LogErr(err)
server.Close()
}
}
示例12: main
func main() {
flag.Parse()
log.SetPrefix(*LogPrefix + " ")
if *DocumentRoot == "" {
log.Fatalln("You must specify a directory to serve, with '-dir=\"...\"'")
}
handler := http.FileServer(http.Dir(*DocumentRoot))
if *Logging {
// Set the logger output.
var output io.Writer
if *LogPath == "" {
output = os.Stdout
} else {
var err error
flags := os.O_CREATE | os.O_APPEND | os.O_WRONLY
output, err = os.OpenFile(*LogPath, flags, 0644)
if err != nil {
log.Fatal(err.Error())
}
}
handler = LoggingHandler(output, http.FileServer(http.Dir(*DocumentRoot)))
log.Printf("Serving %q", *DocumentRoot)
log.Printf("Listening on %q", *ListenAddr)
}
if err := http.ListenAndServe(*ListenAddr, handler); err != nil {
log.Fatalln(err)
}
return
}
示例13: main
func main() {
//Have to add handles for serving static pages, still a bit fuzzy on the FileServer stuff.
http.Handle("/pic/", http.StripPrefix("/pic/", http.FileServer(http.Dir("pic"))))
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
http.HandleFunc("/", handleThis)
http.ListenAndServe(":8000", nil)
}
示例14: main
func main() {
client = redis.NewClient(&redis.Options{
Addr: RedisAddr,
Password: RedisPassword,
DB: RedisDb,
})
pong, err := client.Ping().Result()
http.Handle("/css/", http.FileServer(http.Dir("template")))
http.Handle("/js/", http.FileServer(http.Dir("template")))
http.Handle("/img/", http.FileServer(http.Dir("template")))
http.Handle("/", http.FileServer(http.Dir("template")))
if err != nil {
fmt.Println(pong, err)
http.HandleFunc("/set", showerror)
http.HandleFunc("/get", showerror)
http.HandleFunc("/tag", showerror)
} else {
http.HandleFunc("/set", sethello)
http.HandleFunc("/get", gethello)
http.HandleFunc("/tag", taghello)
}
http.ListenAndServe(":"+Port, nil)
}
示例15: init
func init() {
r := mux.NewRouter()
apiGet := r.PathPrefix("/api").Methods("GET").Subrouter()
apiGet.HandleFunc("/{view}", apiController.ApiGetHandler)
apiGet.HandleFunc("/{view}/{key}", apiController.ApiGetHandler)
apiGet.HandleFunc("/{view}/{parent}/{key}", apiController.ApiGetHandler)
apiPost := r.PathPrefix("/api").Methods("POST").Subrouter()
apiPost.HandleFunc("/{view}", apiController.ApiPostHandler)
apiPost.HandleFunc("/{view}/{key}", apiController.ApiPostHandler)
apiDelete := r.PathPrefix("/api").Methods("DELETE").Subrouter()
apiDelete.HandleFunc("/{view}/{key}", apiController.ApiDeleteHandler)
r.PathPrefix("/admin/").Handler(http.StripPrefix("/admin/", http.FileServer(http.Dir("./static/admin"))))
r.PathPrefix("/admin").Handler(http.RedirectHandler("/admin/", 301))
r.PathPrefix("/blog").Handler(http.StripPrefix("/blog", http.FileServer(http.Dir("./static"))))
r.PathPrefix("/foundation/").Handler(http.StripPrefix("/foundation/", http.FileServer(http.Dir("./static/foundation"))))
r.HandleFunc("/{.path:.*}", cloudAdminHandler).Methods("GET")
r.HandleFunc("/{.path:.*}", cloudAdminPostHandler).Methods("POST")
http.Handle("/", r)
}