Пример #1
0
func main() {
	pid := syscall.Getpid()
	flag.Parse()

	// create the pipeline
	pipeline := falcore.NewPipeline()
	pipeline.Upstream.PushBack(falcore.NewRequestFilter(Filter))

	// create the server with the pipeline
	srv := falcore.NewServer(8090, pipeline)

	// if passed the socket file descriptor, setup the listener that way
	// if you don't have it, the default is to create the socket listener
	// with the data passed to falcore.NewServer above (happens in ListenAndServer())
	if *socketFd != -1 {
		// I know I'm a child process if I get here so I can signal the parent when I'm ready to take over
		go childReady(srv)
		fmt.Printf("%v Got socket FD: %v\n", pid, *socketFd)
		srv.FdListen(*socketFd)
	}

	// using signals to manage the restart lifecycle
	go handleSignals(srv)

	// start the server
	// this is normally blocking forever unless you send lifecycle commands
	if err := srv.ListenAndServe(); err != nil {
		fmt.Printf("%v Could not start server: %v", pid, err)
	}
	fmt.Printf("%v Exiting now\n", pid)
}
Пример #2
0
func main() {
	// parse command line options
	flag.Parse()

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

	// upstream filters

	// Serve index.html for root requests
	pipeline.Upstream.PushBack(falcore.NewRequestFilter(func(req *falcore.Request) *http.Response {
		if req.HttpRequest.URL.Path == "/" {
			req.HttpRequest.URL.Path = "/index.html"
		}
		return nil
	}))
	// Serve files
	pipeline.Upstream.PushBack(&static_file.Filter{
		BasePath: *path,
	})

	// downstream
	pipeline.Downstream.PushBack(compression.NewFilter(nil))

	// setup server
	server := falcore.NewServer(*port, 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)
	}
}
Пример #3
0
func main() {
	// parse command line options
	flag.Parse()

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

	// upstream
	pipeline.Upstream.PushBack(helloFilter)

	// setup server
	server := falcore.NewServer(*port, 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)
	}
}
Пример #4
0
func init() {
	// Silence log output
	log.SetOutput(nil)

	// setup mime
	mime.AddExtensionType(".foo", "foo/bar")
	mime.AddExtensionType(".json", "application/json")

	go func() {

		// falcore setup
		pipeline := falcore.NewPipeline()
		pipeline.Upstream.PushBack(&Filter{
			PathPrefix: "/",
			BasePath:   "../test/",
		})
		srv = falcore.NewServer(0, pipeline)
		if err := srv.ListenAndServe(); err != nil {
			panic(fmt.Sprintf("Could not start falcore: %v", err))
		}
	}()
}
Пример #5
0
func main() {
	// create pipeline
	pipeline := falcore.NewPipeline()

	// add upstream pipeline stages
	var filter1 delayFilter
	pipeline.Upstream.PushBack(filter1)
	var filter2 helloFilter
	pipeline.Upstream.PushBack(filter2)

	// add request done callback stage
	pipeline.RequestDoneCallback = reqCB

	// create server on port 8000
	server := falcore.NewServer(8000, 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)
	}
}
Пример #6
0
func main() {

	port := 8080

	pipeline := falcore.NewPipeline()

	pipeline.Upstream.PushBack(
		falcore.NewRequestFilter(
			func(req *falcore.Request) *http.Response {
				return falcore.SimpleResponse(
					req.HttpRequest,
					200,
					nil,
					"Hello, World!")
			}))

	server := falcore.NewServer(port, pipeline)

	if err := server.ListenAndServe(); err != nil {
		fmt.Println("Could not start server:" + err.Error())
	}

}
Пример #7
0
func init() {
	go func() {
		// falcore setup
		pipeline := falcore.NewPipeline()
		pipeline.Upstream.PushBack(falcore.NewRequestFilter(func(req *falcore.Request) *http.Response {
			for _, data := range serverData {
				if data.path == req.HttpRequest.URL.Path {
					header := make(http.Header)
					header.Set("Etag", data.etag)
					return falcore.SimpleResponse(req.HttpRequest, data.status, header, string(data.body))
				}
			}
			return falcore.SimpleResponse(req.HttpRequest, 404, nil, "Not Found")
		}))

		pipeline.Downstream.PushBack(new(Filter))

		srv = falcore.NewServer(0, pipeline)
		if err := srv.ListenAndServe(); err != nil {
			panic("Could not start falcore")
		}
	}()
}