Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@karahiyo
Last active November 25, 2015 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karahiyo/a5daa5e90d7d3cbf856b to your computer and use it in GitHub Desktop.
Save karahiyo/a5daa5e90d7d3cbf856b to your computer and use it in GitHub Desktop.
gor試してみたメモ

gor test

install

$ wget https://github.com/buger/gor/releases/download/v0.10.1/gor_0.10.1_x64.tar.gz
$ tar zxvf gor_0.10.1_x64.tar.gz
$ mv ./gor /usr/local/bin/

準備

$ sudo setcap CAP_NET_RAW=ep gor

run

$ make start-server
$ make start-gor-case1
$ http localhost:8081
$ sudo ngrep -d lo -W byline port 8081
interface: lo (127.0.0.0/255.0.0.0)
filter: ( port 8081 ) and (ip or ip6)
######
T 127.0.0.1:45925 -> 127.0.0.1:8081 [AP]
GET / HTTP/1.1.
Host: localhost:8081.
Connection: keep-alive.
Accept-Encoding: gzip, deflate.
Accept: */*.
User-Agent: HTTPie/0.9.2.
.

##
T 127.0.0.1:8081 -> 127.0.0.1:45925 [AP]
HTTP/1.1 200 OK.
Date: Wed, 25 Nov 2015 13:37:42 GMT.
Content-Length: 7.
Content-Type: text/plain; charset=utf-8.
.
server1
####
$ sudo ngrep -d lo -W byline port 8082
interface: lo (127.0.0.0/255.0.0.0)
filter: ( port 8082 ) and (ip or ip6)
#
T 127.0.0.1:51706 -> 127.0.0.1:8082 [AP]
GET / HTTP/1.1.
Host: :8082.
Connection: keep-alive.
Accept-Encoding: gzip, deflate.
Accept: */*.
User-Agent: HTTPie/0.9.2.
.

#
T 127.0.0.1:8082 -> 127.0.0.1:51706 [AP]
HTTP/1.1 200 OK.
Date: Wed, 25 Nov 2015 13:40:49 GMT.
Content-Length: 7.
Content-Type: text/plain; charset=utf-8.
.
server2
#

!

  • macは対応していない
  • gom使って落としてこようとしたら、あとソースからダウンロードしようとしたらこれにはまった
  • urlの指定に注意
    • server1-bad.goみたいにlocalhostを省略するとreplayができない
gom "github.com/buger/gor"
GO:=$(shell which go)
GOR:=$(shell which gor)
CWD:=$(shell pwd)
start-server: server1 server2
server1:
$(GO) run server1.go &
server2:
$(GO) run server2.go &
kill-server:
pkill server1
pkill server2
start-gor-case1:
gor --input-raw :8081 --output-http :8082
start-gor-case2:
gor --input-raw :8081 --output-http :8082 --verbose
package main
import (
"fmt"
"net/http"
)
type String string
func (s String) ServeHTTP (w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, s)
}
func main() {
http.Handle("/", String("server1"))
http.ListenAndServe(":8081", nil)
}
package main
import (
"fmt"
"net/http"
)
type String string
func (s String) ServeHTTP (w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, s)
}
func main() {
http.Handle("/", String("server1"))
http.ListenAndServe("localhost:8081", nil)
}
package main
import (
"fmt"
"net/http"
)
type String string
func (s String) ServeHTTP (w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, s)
}
func main() {
http.Handle("/", String("server2"))
http.ListenAndServe("localhost:8082", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment