From 11c71d2916278fc34adeef8968c3fa6721255e3e Mon Sep 17 00:00:00 2001 From: badkaktus Date: Sat, 12 Oct 2019 21:20:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D1=81=D1=80=D0=B5=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples.txt | 2 +- .../environment-variables.go | 26 ++++++++++--------- .../environment-variables.sh | 13 +++++----- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/examples.txt b/examples.txt index 722a0a3..2885db0 100644 --- a/examples.txt +++ b/examples.txt @@ -65,7 +65,7 @@ Epoch Аргументы командной строки (Command-Line Arguments) Флаги командной строки (Command-Line Flags) Подкоманды командной строки (Command-Line Subcommands) -Environment Variables +Переменные среды (Environment Variables) HTTP Clients HTTP Servers Spawning Processes diff --git a/examples/environment-variables/environment-variables.go b/examples/environment-variables/environment-variables.go index b316b8a..42bd5bc 100644 --- a/examples/environment-variables/environment-variables.go +++ b/examples/environment-variables/environment-variables.go @@ -1,7 +1,8 @@ -// [Environment variables](http://en.wikipedia.org/wiki/Environment_variable) -// are a universal mechanism for [conveying configuration -// information to Unix programs](http://www.12factor.net/config). -// Let's look at how to set, get, and list environment variables. +// [Переменные среды (или переменные окружения)](http://en.wikipedia.org/wiki/Environment_variable) +// - это [универсальный механизм передачи информации о конфигурации +// в программы Unix](http://www.12factor.net/config). Давайте +// посмотрим, как устанавливать, получать и перечислять переменные +// среды. package main @@ -13,18 +14,19 @@ import ( func main() { - // To set a key/value pair, use `os.Setenv`. To get a - // value for a key, use `os.Getenv`. This will return - // an empty string if the key isn't present in the - // environment. + // Чтобы установить пару ключ/значение, используйте + // `os.Setenv`. Чтобы получить значение для ключа, + // используйте `os.Getenv`. Это вернет пустую строку, + // если ключ не присутствует в среде. os.Setenv("FOO", "1") fmt.Println("FOO:", os.Getenv("FOO")) fmt.Println("BAR:", os.Getenv("BAR")) - // Use `os.Environ` to list all key/value pairs in the - // environment. This returns a slice of strings in the - // form `KEY=value`. You can `strings.Split` them to - // get the key and value. Here we print all the keys. + // Используйте `os.Environ` для вывода списка всех пар + // ключ/значение в среде. Это возвращает спез строк в + // формате `KEY=value`. Вы можете использовать `strings.Split`, + // чтобы получить ключ и значение. Здесь мы печатаем + // все ключи. fmt.Println() for _, e := range os.Environ() { pair := strings.Split(e, "=") diff --git a/examples/environment-variables/environment-variables.sh b/examples/environment-variables/environment-variables.sh index 0969313..c5314e2 100644 --- a/examples/environment-variables/environment-variables.sh +++ b/examples/environment-variables/environment-variables.sh @@ -1,19 +1,18 @@ -# Running the program shows that we pick up the value -# for `FOO` that we set in the program, but that -# `BAR` is empty. +# Запуск программы показывает, что мы выбираем значение +# для `FOO`, которое мы установили в программе, но `BAR` +# пуст. $ go run environment-variables.go FOO: 1 BAR: -# The list of keys in the environment will depend on your -# particular machine. +# Список ключей в среде будет зависеть от вашей системы. TERM_PROGRAM PATH SHELL ... -# If we set `BAR` in the environment first, the running -# program picks that value up. +# Если мы сначала установим `BAR` в среде, запущенная +# программа использует это значение. $ BAR=2 go run environment-variables.go FOO: 1 BAR: 2