Skip to content

Instantly share code, notes, and snippets.

View RoGogDBD's full-sized avatar
:shipit:
«The human brain is limited, but the mind is unlimited.»

Makar Kudryavtsev RoGogDBD

:shipit:
«The human brain is limited, but the mind is unlimited.»
View GitHub Profile
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
package main
import (
"encoding/json"
"log"
"net/http"
)
// User — основной объект для теста.
type User struct {
// Фрагмент 1.
package main
import (
"testing"
)
func TestAbs(t *testing.T) {
tests := []struct {
name string
// Фрагмент 1
// В первом фрагменте нужно покрыть тестами функцию Abs(value float64). Она возвращает абсолютное значение числа типа float64.
package main
import (
"fmt"
"math"
)
func main() {
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"
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."))
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."))
package main
import "net/http"
type MyHandler struct{}
func (h MyHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
data := []byte("Привет!")
res.Write(data)
}
package main
import "net/http"
func main() {
err := http.ListenAndServe(`:8080`, nil)
if err != nil {
panic(err)
}
}
package main
import (
"net/http"
_ "net/http/pprof" // Импортируем пакет pprof для регистрации обработчиков HTTP.
)
const (
addr = ":8080" // Адрес для pprof сервера.
maxSize = 10000000 // Максимальный размер среза для полезной нагрузки.