Lu Stadler лет назад: 7
Родитель
Сommit
9356299434
2 измененных файлов с 10 добавлено и 1 удалено
  1. 0 1
      go/fake-http/README.md
  2. 10 0
      go/fake-http/fake-http.go

+ 0 - 1
go/fake-http/README.md

5
- support matching query strings
5
- support matching query strings
6
- refactoring
6
- refactoring
7
- /_clear endpoint
7
- /_clear endpoint
8
- (randomized) delays
9
- some kind of templating (request info + random functions?)
8
- some kind of templating (request info + random functions?)
10
- lua integration? ;)
9
- lua integration? ;)
11
10

+ 10 - 0
go/fake-http/fake-http.go

9
	"io"
9
	"io"
10
	"io/ioutil"
10
	"io/ioutil"
11
	"log"
11
	"log"
12
	"math/rand"
12
	"net/http"
13
	"net/http"
13
	"net/url"
14
	"net/url"
14
	"os"
15
	"os"
15
	"os/exec"
16
	"os/exec"
16
	"path"
17
	"path"
17
	"strings"
18
	"strings"
19
	"time"
18
20
19
	"gopkg.in/yaml.v2"
21
	"gopkg.in/yaml.v2"
20
)
22
)
136
		resp = &Response{Status: 404, Body: "Not found"}
138
		resp = &Response{Status: 404, Body: "Not found"}
137
	}
139
	}
138
140
141
	time.Sleep(resp.Delay)
142
	if resp.RandomDelay > 0 {
143
		time.Sleep(time.Duration(rand.Intn(int(resp.RandomDelay))))
144
	}
145
139
	for _, header := range resp.Headers {
146
	for _, header := range resp.Headers {
140
		w.Header().Set(header.Name, header.Value)
147
		w.Header().Set(header.Name, header.Value)
141
	}
148
	}
291
	Status  int      `yaml:"status"`
298
	Status  int      `yaml:"status"`
292
	Headers []Header `yaml:"headers"`
299
	Headers []Header `yaml:"headers"`
293
	Body    string   `yaml:"body"`
300
	Body    string   `yaml:"body"`
301
302
	Delay       time.Duration `yaml:"delay"`
303
	RandomDelay time.Duration `yaml:"randomDelay"`
294
}
304
}
295
305
296
func (resp Response) String() string {
306
func (resp Response) String() string {