This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "io/ioutil" | |
| "net/http" | |
| "net/http/httptest" | |
| "testing" | |
| "github.com/stretchr/testify/assert" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "log" | |
| "net/http" | |
| ) | |
| // User — основной объект для теста. | |
| type User struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Фрагмент 1. | |
| package main | |
| import ( | |
| "testing" | |
| ) | |
| func TestAbs(t *testing.T) { | |
| tests := []struct { | |
| name string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Фрагмент 1 | |
| // В первом фрагменте нужно покрыть тестами функцию Abs(value float64). Она возвращает абсолютное значение числа типа float64. | |
| package main | |
| import ( | |
| "fmt" | |
| "math" | |
| ) | |
| func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "net/http" | |
| ) | |
| func mainPage(res http.ResponseWriter, req *http.Request) { | |
| body := fmt.Sprintf("Method: %s\r\n", req.Method) | |
| body += "Header ===============\r\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "net/http" | |
| func mainPage(res http.ResponseWriter, req *http.Request) { | |
| res.Write([]byte("Привет!")) | |
| } | |
| func apiPage(res http.ResponseWriter, req *http.Request) { | |
| res.Write([]byte("Это страница /api.")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "net/http" | |
| func mainPage(res http.ResponseWriter, req *http.Request) { | |
| res.Write([]byte("Привет!")) | |
| } | |
| func apiPage(res http.ResponseWriter, req *http.Request) { | |
| res.Write([]byte("Это страница /api.")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "net/http" | |
| type MyHandler struct{} | |
| func (h MyHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { | |
| data := []byte("Привет!") | |
| res.Write(data) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "net/http" | |
| func main() { | |
| err := http.ListenAndServe(`:8080`, nil) | |
| if err != nil { | |
| panic(err) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "net/http" | |
| _ "net/http/pprof" // Импортируем пакет pprof для регистрации обработчиков HTTP. | |
| ) | |
| const ( | |
| addr = ":8080" // Адрес для pprof сервера. | |
| maxSize = 10000000 // Максимальный размер среза для полезной нагрузки. |