【メモ】Go Webサーバー 標準
net/httpを使った場合
- go version go1.6.1 linux/amd64
- CentOS release 6.7 (Final)
package main
import (
"fmt"
"log"
"net/http"
)
func echo(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "ぐう暇")
}
func main() {
http.HandleFunc("/", echo)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
filterに追加
-A INPUT -p tcp --dport 9090 -j ACCEPT
リスタート
service iptables restart
テスト起動
nohup go run main.go &
ポート確認
nmap -p 9090 hostname
// 9090/tcp open zeus-admin