-
-
Save ismiyati/aedf6cd77fb923b756f908bd61e0ee60 to your computer and use it in GitHub Desktop.
This is a FastCGI example server in Go.
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
| server { | |
| location ~ /app.* { | |
| fastcgi_pass 127.0.0.1:9000; | |
| include fastcgi_params; | |
| } | |
| } |
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 ( | |
| "fmt" | |
| "net/http" | |
| "net/http/fcgi" | |
| "net" | |
| ) | |
| type FastCGIServer struct{} | |
| func (s FastCGIServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { | |
| w.Write([]byte("This is a FastCGI example server.\n")) | |
| } | |
| func main() { | |
| fmt.Println("Starting server...") | |
| l, _ := net.Listen("tcp", "127.0.0.1:9000") | |
| b := new(FastCGIServer) | |
| fcgi.Serve(l, b) | |
| } |
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
| // 아래처럼 HandleFunc를 등록해서도 처리가능 | |
| func main() { | |
| http.HandleFunc("/foo", fooHandler) | |
| l, err := net.Listen("tcp", "127.0.0.1:9000") | |
| if err != nil { | |
| panic(err) | |
| } | |
| fcgi.Serve(l, nil) | |
| } | |
| func fooHandler(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprintf(w, "Hello") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment