mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
51 lines
803 B
Go
51 lines
803 B
Go
package replay
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
|
|
type ForwardHost struct {
|
|
Url string
|
|
Limit int
|
|
|
|
Stat *RequestStat
|
|
}
|
|
|
|
type ReplaySettings struct {
|
|
port int
|
|
host string
|
|
|
|
limit int
|
|
|
|
address string
|
|
}
|
|
|
|
func (r *ReplaySettings) ForwardedHosts() (hosts []*ForwardHost) {
|
|
hosts = make([]*ForwardHost, 0, 10)
|
|
|
|
for _, address := range strings.Split(r.address, ",") {
|
|
host_info := strings.Split(address, "|")
|
|
|
|
if strings.Index(host_info[0], "http") == -1 {
|
|
host_info[0] = "http://" + host_info[0]
|
|
}
|
|
|
|
host := &ForwardHost{Url: host_info[0]}
|
|
host.Stat = NewRequestStats(host)
|
|
|
|
if len(host_info) > 1 {
|
|
host.Limit, _ = strconv.Atoi(host_info[1])
|
|
}
|
|
|
|
hosts = append(hosts, host)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (r *ReplaySettings) Address() string {
|
|
return r.host + ":" + strconv.Itoa(r.port)
|
|
}
|