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) }
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) } }
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) } }
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("Content-Type", data.mime) header.Set("Content-Encoding", data.encoding) return falcore.SimpleResponse(req.HttpRequest, 200, header, string(data.body)) } } return falcore.SimpleResponse(req.HttpRequest, 404, nil, "Not Found") })) pipeline.Downstream.PushBack(NewFilter(nil)) srv = falcore.NewServer(0, pipeline) if err := srv.ListenAndServe(); err != nil { panic("Could not start falcore") } }() }