Skip to content

Instantly share code, notes, and snippets.

@todashuta
Created May 9, 2022 12:27
Show Gist options
  • Select an option

  • Save todashuta/9de2b300c44307d38fb0ce9adfe0cffd to your computer and use it in GitHub Desktop.

Select an option

Save todashuta/9de2b300c44307d38fb0ce9adfe0cffd to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"net"
"net/http"
"net/http/fcgi"
"os"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
var (
sockPath = flag.String("sockpath", "/tmp/gofcgitest.sock", "socket path")
)
func main() {
flag.Parse()
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
if _, err := os.Stat(*sockPath); err == nil {
_ = os.Remove(*sockPath)
e.Logger.Printf("previous sock file removed: %s", *sockPath)
}
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello fcgi with echo!")
})
ln, err := net.Listen("unix", *sockPath)
if err != nil {
e.Logger.Fatalf("can't listen on %s: %v", *sockPath, err)
}
defer ln.Close()
e.Logger.Printf("listening on %s", *sockPath)
e.Logger.Fatal(fcgi.Serve(ln, e))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment