当前位置: 首页>>代码示例>>Golang>>正文


Golang http.Dir函数代码示例

本文整理汇总了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))
	}
}
开发者ID:codeforsystemsbiology,项目名称:restjsonmgo.go,代码行数:9,代码来源:main.go

示例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()
}
开发者ID:Luit-IT,项目名称:gitwrap,代码行数:31,代码来源:main.go

示例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())
	}
}
开发者ID:uglybrd,项目名称:GoGameHTML5,代码行数:9,代码来源:server.go

示例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)
}
开发者ID:soundcloud,项目名称:statiker,代码行数:12,代码来源:main.go

示例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)
}
开发者ID:andrewsmedina,项目名称:gochat,代码行数:13,代码来源:main.go

示例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())
	}
}
开发者ID:okard,项目名称:depot,代码行数:17,代码来源:server.go

示例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}
}
开发者ID:ssrl,项目名称:go,代码行数:14,代码来源:godoc.go

示例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
}
开发者ID:janimo,项目名称:ftbfs,代码行数:16,代码来源:server.go

示例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())
	}
}
开发者ID:areusch,项目名称:ytd-server,代码行数:15,代码来源:main.go

示例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))
}
开发者ID:k001,项目名称:Golang-spanish-documentation,代码行数:47,代码来源:local.go

示例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)
	}
}
开发者ID:WaylandGod,项目名称:go-socket.io,代码行数:47,代码来源:example.go

示例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
}
开发者ID:hlubek,项目名称:appchilada,代码行数:19,代码来源:frontend.go

示例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!")
}
开发者ID:cheng81,项目名称:goexp-wshttp,代码行数:19,代码来源:wshttptest.go

示例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)
}
开发者ID:jordanorelli,项目名称:superchat,代码行数:20,代码来源:main.go

示例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)
	}
}
开发者ID:NailClippar,项目名称:GoHTTP,代码行数:20,代码来源:triv.go


注:本文中的http.Dir函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。