From d9f948bcfc9c31bf343b6f961c5d62f3ddbcbb4f Mon Sep 17 00:00:00 2001 From: badkaktus Date: Mon, 7 Oct 2019 15:57:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples.txt | 2 +- examples/methods/methods.go | 21 +++++++++++---------- examples/methods/methods.sh | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/examples.txt b/examples.txt index a671dc6..9207d54 100644 --- a/examples.txt +++ b/examples.txt @@ -16,7 +16,7 @@ Switch Рекурсия (Recursion) Указатели (Pointers) Структуры (Structs) -Methods +Методы (Methods) Interfaces Errors Goroutines diff --git a/examples/methods/methods.go b/examples/methods/methods.go index e56cb6f..c6d2e90 100644 --- a/examples/methods/methods.go +++ b/examples/methods/methods.go @@ -1,4 +1,4 @@ -// Go supports _methods_ defined on struct types. +// Go поддерживает _методы_ для структур package main @@ -8,13 +8,13 @@ type rect struct { width, height int } -// This `area` method has a _receiver type_ of `*rect`. +// Метод `area` принимает _получателя_ `*rect`. func (r *rect) area() int { return r.width * r.height } -// Methods can be defined for either pointer or value -// receiver types. Here's an example of a value receiver. +// Методы могут принимать как указатели, так и значения. +// Вот пример со значением. func (r rect) perim() int { return 2*r.width + 2*r.height } @@ -22,15 +22,16 @@ func (r rect) perim() int { func main() { r := rect{width: 10, height: 5} - // Here we call the 2 methods defined for our struct. + // Вызываем 2 метода, определенные для нашей структуры. fmt.Println("area: ", r.area()) fmt.Println("perim:", r.perim()) - // Go automatically handles conversion between values - // and pointers for method calls. You may want to use - // a pointer receiver type to avoid copying on method - // calls or to allow the method to mutate the - // receiving struct. + // Go автоматически обрабатывает преобразование между + // значениями и указателями при вызове методов. + // Возможно, вы захотите использовать указатель в + // качестве получателя, чтобы избежать копирования при вызове + // метода или позволить методу изменять структуру + // получателя. rp := &r fmt.Println("area: ", rp.area()) fmt.Println("perim:", rp.perim()) diff --git a/examples/methods/methods.sh b/examples/methods/methods.sh index d646ae9..9dfbda5 100644 --- a/examples/methods/methods.sh +++ b/examples/methods/methods.sh @@ -4,5 +4,5 @@ perim: 30 area: 50 perim: 30 -# Next we'll look at Go's mechanism for grouping and -# naming related sets of methods: interfaces. +# Далее мы рассмотрим механизм Go для группировки +# и именования связанных наборов методов: интерфейсов.