Created
May 9, 2022 12:27
-
-
Save todashuta/9de2b300c44307d38fb0ce9adfe0cffd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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