本文整理汇总了Golang中http.Dir函数的典型用法代码示例。如果您正苦于以下问题:Golang Dir函数的具体用法?Golang Dir怎么用?Golang Dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StartHtmlHandler
// starts http handlers for HTML content based on the given configuration file
// optional parameters: default.contentDirectory (location of html content to be served at https://example.com/ or https://example.com/html/index.html
func StartHtmlHandler() {
if contentDir, _ := configFile.GetString("default", "contentDirectory"); contentDir != "" {
logger.Printf("StartHtmlHandler(): serving HTML content from [%v]", contentDir)
http.Handle("/html/", http.StripPrefix("/html/", http.FileServer(http.Dir(contentDir))))
http.Handle("/", http.RedirectHandler("/html/", http.StatusTemporaryRedirect))
}
}
示例2: main
func main() {
log.SetFlags(0)
flag.Parse()
cgiHandler := &cgi.Handler{
Path: *cgitPath,
Env: []string{},
InheritEnv: []string{
"CGIT_CONFIG",
},
}
if *config != "" {
cgiHandler.Env = append(cgiHandler.Env,
"CGIT_CONFIG="+*config)
}
fs := http.FileServer(http.Dir(*cgitRes))
http.Handle("/cgit.css", fs)
http.Handle("/cgit.png", fs)
http.Handle("/", cgiHandler)
err := http.ListenAndServe(*addr+":"+strconv.Itoa(*port), nil)
if err != nil {
log.Fatal(err)
}
// Everything seems to work: daemonize (close file handles)
os.Stdin.Close()
os.Stdout.Close()
os.Stderr.Close()
}
示例3: main
func main() {
http.Handle("/echo", websocket.Handler(EchoServer))
http.Handle("/lobby", websocket.Handler(LobbyServer))
http.Handle("/", http.FileServer(http.Dir("/tmp")))
fmt.Println("Listening on:", listenAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil {
panic("ListenAndServe: " + err.String())
}
}
示例4: main
func main() {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
fmt.Printf("%d\n", l.Addr().(*net.TCPAddr).Port)
http.Handle("/", http.FileServer(http.Dir(".")))
http.Serve(l, nil)
}
示例5: main
func main() {
port := "0.0.0.0:8080"
room = NewRoom()
staticDir := http.Dir("/projects/go/chat/static")
staticServer := http.FileServer(staticDir)
http.HandleFunc("/", Home)
http.HandleFunc("/feed", FeedMux)
http.HandleFunc("/login", LoginMux)
http.Handle("/static/", http.StripPrefix("/static", staticServer))
fmt.Printf("Serving at %s ----------------------------------------------------", port)
http.ListenAndServe(port, nil)
}
示例6: main
/**
* Main Function
*/
func main() {
fmt.Printf("Starting http Server ... \n")
http.Handle("/$sys", http.HandlerFunc(handleSys))
http.Handle("/$db", http.HandlerFunc(handleDb))
//internal webserver should be disabled
http.Handle("/", http.FileServer(http.Dir("web/")))
err := http.ListenAndServe("127.0.0.1:8080", nil)
if err != nil {
fmt.Printf("ListenAndServe Error :" + err.String())
}
}
示例7: initHandlers
func initHandlers() {
paths := filepath.SplitList(*pkgPath)
for _, t := range build.Path {
if t.Goroot {
continue
}
paths = append(paths, t.SrcDir())
}
fsMap.Init(paths)
fileServer = http.FileServer(http.Dir(*goroot))
cmdHandler = httpHandler{"/cmd/", filepath.Join(*goroot, "src", "cmd"), false}
pkgHandler = httpHandler{"/pkg/", filepath.Join(*goroot, "src", "pkg"), true}
}
示例8: runServer
//Start the web server
func runServer(port string, s chan int) {
http.HandleFunc("/", viewHandle)
http.HandleFunc("/logview/", logViewHandle)
pwd, _ := os.Getwd()
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(pwd+"/static/"))))
err := http.ListenAndServe(":"+port, nil)
if err != nil {
println(err.String())
}
s <- 1
}
示例9: main
func main() {
flag.Parse()
if *help {
flag.PrintDefaults()
return
}
coord := NewDownloadCoordinator()
http.Handle("/dl", NewDownloadHandler(*basePath, coord))
// http.Handle("/files/", http.StripPrefix("/files/", http.FileServer(http.Dir(*basePath))))
http.Handle("/", http.FileServer(http.Dir("fs/")))
if e := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); e != nil {
fmt.Printf("Cannot listen! Error: %s\n", e.String())
}
}
示例10: main
func main() {
flag.Parse()
// source of unique numbers
go func() {
for i := 0; ; i++ {
uniq <- i
}
}()
// set archChar
var err os.Error
archChar, err = build.ArchChar(runtime.GOARCH)
if err != nil {
log.Fatal(err)
}
// find and serve the go tour files
t, _, err := build.FindTree(basePkg)
if err != nil {
log.Fatalf("Couldn't find tour files: %v", err)
}
root := filepath.Join(t.SrcDir(), basePkg)
root := basePkg
log.Println("Serving content from", root)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/favicon.ico" || r.URL.Path == "/" {
fn := filepath.Join(root, "static", r.URL.Path[1:])
http.ServeFile(w, r, fn)
return
}
http.Error(w, "not found", 404)
})
http.Handle("/static/", http.FileServer(http.Dir(root)))
http.HandleFunc("/kill", kill)
// set include path for ld and gc
pkgDir = t.PkgDir()
if !strings.HasPrefix(*httpListen, "127.0.0.1") &&
!strings.HasPrefix(*httpListen, "localhost") {
log.Print(localhostWarning)
}
log.Printf("Serving at http://%s/", *httpListen)
log.Fatal(http.ListenAndServe(*httpListen, nil))
}
示例11: main
// A very simple chat server
func main() {
buffer := new(vector.Vector)
mutex := new(sync.Mutex)
// create the socket.io server and mux it to /socket.io/
config := socketio.DefaultConfig
config.Origins = []string{"localhost:8080"}
sio := socketio.NewSocketIO(&config)
go func() {
if err := sio.ListenAndServeFlashPolicy(":843"); err != nil {
log.Println(err)
}
}()
// when a client connects - send it the buffer and broadcasta an announcement
sio.OnConnect(func(c *socketio.Conn) {
mutex.Lock()
c.Send(Buffer{buffer.Copy()})
mutex.Unlock()
sio.Broadcast(Announcement{"connected: " + c.String()})
})
// when a client disconnects - send an announcement
sio.OnDisconnect(func(c *socketio.Conn) {
sio.Broadcast(Announcement{"disconnected: " + c.String()})
})
// when a client send a message - broadcast and store it
sio.OnMessage(func(c *socketio.Conn, msg socketio.Message) {
payload := Message{[]string{c.String(), msg.Data()}}
mutex.Lock()
buffer.Push(payload)
mutex.Unlock()
sio.Broadcast(payload)
})
log.Println("Server starting. Tune your browser to http://localhost:8080/")
mux := sio.ServeMux()
mux.Handle("/", http.FileServer(http.Dir("www/")))
if err := http.ListenAndServe(":8080", mux); err != nil {
log.Fatal("ListenAndServe:", err)
}
}
示例12: ListenAndServeHttp
// Initialize HTTP server for frontend
func ListenAndServeHttp(backend appchilada.Backend) os.Error {
http.HandleFunc("/", indexHandler(backend))
http.HandleFunc("/show/", showHandler(backend))
if dir, err := os.Getwd(); err != nil {
return err
} else {
dir = dir + string(os.PathSeparator) + "assets"
log.Printf("Opening webserver in %s", dir)
// Handle static files in /public served on /public (stripped prefix)
http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir(dir))))
}
log.Printf("Opening webserver on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
return err
}
return nil
}
示例13: main
func main() {
flag.Parse()
runtime.GOMAXPROCS(*Procs)
// port := 8082
// host := "130.226.133.44:8082"
host := *(Host) + ":" + fmt.Sprint(*(Port))
mux := dynamichttp.NewServeMux()
dir := http.Dir("./www")
mux.Handle("/", http.FileServer(dir))
wshttp.EnableWsHttp(host, mux)
fmt.Println("Running on " + host)
err := dynamichttp.ListenAndServe(host, mux)
if err != nil {
fmt.Println("error", err)
}
fmt.Println("Bye!")
}
示例14: main
func main() {
runtime.GOMAXPROCS(8)
port := "0.0.0.0:8000"
room = NewRoom()
rolloffs = make([]*RollOff, 0)
staticDir := http.Dir("/projects/go/chat/static")
staticServer := http.FileServer(staticDir)
homeTemplate = template.Must(template.ParseFile("templates/index.html"))
http.HandleFunc("/", LogWrap(Home, "Home"))
http.HandleFunc("/feed", LogWrap(FeedMux, "FeedMux"))
http.HandleFunc("/login", LogWrap(LoginMux, "LoginMux"))
http.HandleFunc("/users", LogWrap(GetUsers, "GetUsers"))
http.HandleFunc("/roll", LogWrap(Roll, "Roll"))
http.HandleFunc("/roll-off", LogWrap(NewRollOff, "NewRollOff"))
http.HandleFunc("/roll-off-entry/", LogWrap(EnterRollOff, "EnterRollOff"))
http.Handle("/static/", http.StripPrefix("/static", staticServer))
fmt.Printf("Serving at %s ----------------------------------------------------\n", port)
http.ListenAndServe(port, nil)
}
示例15: main
func main() {
flag.Parse()
// The counter is published as a variable directly.
ctr := new(Counter)
http.Handle("/counter", ctr)
expvar.Publish("counter", ctr)
http.Handle("/", http.HandlerFunc(Logger))
http.Handle("/go/", http.StripPrefix("/go/", http.FileServer(http.Dir(*webroot))))
http.Handle("/flags", http.HandlerFunc(FlagServer))
http.Handle("/args", http.HandlerFunc(ArgServer))
http.Handle("/go/hello", http.HandlerFunc(HelloServer))
http.Handle("/chan", ChanCreate())
http.Handle("/date", http.HandlerFunc(DateServer))
err := http.ListenAndServe(":12345", nil)
if err != nil {
log.Panicln("ListenAndServe:", err)
}
}