/
kravalsergey
/
testing
Обзор
Документация
Войти
/
kravalsergey
/
testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
main.go
161 строка
5 KB
Краваль Сергей
success
18 май 2026, 18:17
18 май 2026, 18:17
8b610f8
Код
Авторство
О чём код?
// Testing project main.go package main import ( "fmt" curl "gocurl" "log" ) var options *curl.RequestOptions var timeOut = 20 func init() { method := "GET" fullURL := "http://f5.local/" options = curl.NewOptions(fullURL, method) options.SetTimeout(timeOut) options.FileName = "cucumber.txt" options.DownloadDir = "/home/kraser/tmp" // options.FileName = "testGet.txt" } func main() { receive := true send := true if options.Method == "GET" && !receive { testGet() } else if options.Method == "GET" && receive { testReceivingGet() } else if options.Method == "POST" && !send { json := true if json { testJSONPost() } else { testPost() } } else if options.Method == "POST" && send { testSendingPost() } } func testGet() { fmt.Println("=== GET-запрос ===") fmt.Println(options.Url) options.AddGetParam("times", "много и всяко") options.AddGetParam("home", "RedAvenue") options.AddHeader("Authorization", "Bearer Sometoken") options.AddHeader("User-Agent", "curl/8.9.1") options.AddHeader("Accept", "text/html, application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8") client := curl.NewHTTPClient() getResponse, getStatus, getErr := client.DoRequest( options, ) if getErr != nil { log.Fatalf("GET-запрос завершился ошибкой: %v", getErr) } fmt.Printf("Статус: %d\nОтвет: %s\n\n", getStatus, getResponse) } func testReceivingGet() { fmt.Println("=== Получение файла GET-запрос ===") options.AddGetParam("times", "много и всяко") // options.AddGetParam("fuck", "Nata") options.AddGetParam("home", "RedAvenue") fmt.Println(len(options.GetParams)) options.AddHeader("Authorization", "Bearer Sometoken") options.AddHeader("User-Agent", "curl/8.9.1") options.AddHeader("Accept", "text/html, application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8") options.AddHeader("Content-Type", "text/plain; charset=utf-8") client := curl.NewHTTPClient() getResponse, getStatus, getErr := client.DoRequest( options, ) if getErr != nil { log.Fatalf("GET-запрос завершился ошибкой: %v", getErr) } fmt.Printf("Статус: %d\nОтвет: %s\n\n", getStatus, getResponse) } func testPost() { fmt.Println("=== POST-запрос ===") options.AddGetParam("times", "много и всяко") options.AddGetParam("home", "RedAvenue") options.AddHeader("User-Agent", "curl/8.9.1") options.AddHeader("Accept", "text/html, application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8") options.AddHeader("Content-Type", "application/x-www-form-urlencoded") options.PostFields.Set("post", "Yes Post") options.PostFields.Set("login", "robot") options.PostFields.Set("email", "mangusta@example.com") client := curl.NewHTTPClient() getResponse, getStatus, getErr := client.DoRequest(options) if getErr != nil { log.Fatalf("POST-запрос завершился ошибкой: %v", getErr) } fmt.Printf("Статус: %d\nОтвет: %s\n\n", getStatus, getResponse) } func testSendingPost() { fmt.Println("=== POST-запрос SEND FILES ===") options.AddGetParam("home", "RedAvenue") options.AddGetParam("names", "KatyNaty") options.AddHeader("User-Agent", "curl/8.9.1") options.AddHeader("Accept", "text/html, application/xhtml+xml, application/xml;q=0.9,*/*;q=0.8") options.AddHeader("Content-Type", "application/x-www-form-urlencoded") options.PostFields.Set("post", "Yes Post") options.PostFields.Set("login", "robot") options.PostFields.Set("email", "mangusta@example.com") options.PostFields.SetFilename("/home/kraser/hidden.csv") options.PostFields.SetFilename("/home/kraser/outsource.csv") client := curl.NewHTTPClient() getResponse, getStatus, getErr := client.DoRequest(options) if getErr != nil { log.Fatalf("POST-запрос завершился ошибкой: %v", getErr) } fmt.Printf("Статус: %d\nОтвет: %s\n\n", getStatus, getResponse) } func testJSONPost() { // Пример POST‑запроса fmt.Println("=== POST-запрос JSON ===") options.AddGetParam("times", "много и всяко") options.AddGetParam("screwed", "Kate") options.AddGetParam("home", "RedAvenue") options.AddHeader("Authorization", "Bearer Sometoken") options.AddHeader("User-Agent", "curl/8.9.1") options.AddHeader("Accept", "text/plain") options.AddHeader("Content-Type", "application/x-www-form-urlencoded") options.PostFields.Set("post", "Yes Post") options.PostFields.Set("login", "robot") options.PostFields.TestSttruct() options.PostFields.InitJSONFromString(`{"name": "MED","fucked": true, "age": 25, "email": "mangusta@example.com"}`) options.PostFields.AddJsonField("doggyStyle", "yes") options.PostFields.AddJsonField("name", "Kate.Mat") options.PostFields.TestSttruct() /* //jsonString := `{"name": "MED","fucked": true, "age": 25, "email": "mangusta@example.com"}` jsonFerr, _ := curl.NewJSONPostParams() jsonFerr.InitFromString("") jsonFerr.Add("doggyStyle", "yes") jsonFerr.Add("name", "Kate.Mat") fmt.Println("JSON:", jsonFerr.ToString()) */ // options.ReqBody = jsonFerr.Build(options) client := curl.NewHTTPClient() getResponse, getStatus, getErr := client.DoRequest(options) if getErr != nil { log.Fatalf("POST-запрос завершился ошибкой: %v", getErr) } fmt.Printf("Статус: %d\nОтвет: %s\n\n", getStatus, getResponse) }