func home(req *request.Request) (statusCode int) { resp, err := req.Get(loginRequiredPageURL) if err != nil { return 500 } return resp.StatusCode }
func diff(req *request.Request) { url := "http://example.com:12345" start := time.Now() req.Get(url) diff := time.Now().Sub(start) fmt.Println(diff.Seconds()) }
func getCSRFToken(req *request.Request) (string, error) { resp, err := req.Get(loginPageURL) if err != nil { return "", err } s, err := resp.Text() if err != nil { return "", err } reInput := regexp.MustCompile( `<input\s+[^>]*?name=['"]csrfmiddlewaretoken['"'][^>]*>`, ) input := reInput.FindString(s) reValue := regexp.MustCompile(`value=['"]([^'"]+)['"]`) csrfToken := reValue.FindStringSubmatch(input) if len(csrfToken) < 2 { return "", err } return csrfToken[1], err }
func login(req *request.Request) error { _, err := req.Post(loginPageURL) return err }