Ejemplo n.º 1
0
// NewPassthruFilter generates a Falcore RequestFilter that proxies all requests
// that reach it back and forth to a given host and port.
//
// As such, this is the core of the proxying system.
func NewPassthruFilter(host string, port int) falcore.RequestFilter {
	log().Debug("registering a new passthru filter")

	return filter.NewUpstream(
		filter.NewUpstreamTransport(host, port, 0, nil),
	)
}
Ejemplo n.º 2
0
func main() {
	// parse command line options
	flag.Parse()

	// create pipeline
	pipeline := falcore.NewPipeline()

	// setup file server for public directory
	if *flagPath != "" {
		// Serve files from public directory
		pipeline.Upstream.PushBack(&filter.FileFilter{
			BasePath:       *flagPath,
			DirectoryIndex: "index.html",
		})
	} else {
		falcore.Warn("Path to public directory is missing")
	}

	// parse upstream list and create the upstream pool
	upStrings := regexp.MustCompile("[0-9]+").FindAllString(*flagUpstream, -1)
	ups := make([]*filter.UpstreamEntry, len(upStrings))
	for i, s := range upStrings {
		port, _ := strconv.Atoi(s)
		ups[i] = &filter.UpstreamEntry{
			Upstream: filter.NewUpstream(filter.NewUpstreamTransport("localhost", port, 0, nil)),
			Weight:   1,
		}
	}

	// create upstream pool and add to pipeline
	if len(ups) > 0 {
		pipeline.Upstream.PushBack(filter.NewUpstreamPool("railsdemo", ups))
	} else {
		falcore.Warn("No upstream ports provided")
	}

	// add any downstream filters you might want such as etag support or compression

	// setup server
	server := falcore.NewServer(*flagPort, pipeline)

	// start the server
	// this is normally blocking forever unless you send lifecycle commands
	if err := server.ListenAndServe(); err != nil {
		fmt.Println("Could not start server:", err)
	}

}