fix links
This commit is contained in:
parent
2634a9ca4b
commit
02a7051563
148
examples.txt
148
examples.txt
@ -1,74 +1,74 @@
|
|||||||
Hello World
|
Hello World|Hello World
|
||||||
Типы данных (Values)
|
Типы данных (Values)|Values
|
||||||
Переменные (Variables)
|
Переменные (Variables)|Variables
|
||||||
Константы (Constants)
|
Константы (Constants)|Constants
|
||||||
Цикл For
|
Цикл For|For
|
||||||
If/Else
|
If/Else|If/Else
|
||||||
Switch
|
Switch|Switch
|
||||||
Массивы (Arrays)
|
Массивы (Arrays)|Arrays
|
||||||
Срезы (Slices)
|
Срезы (Slices)|Slices
|
||||||
Карты (Maps)
|
Карты (Maps)|Maps
|
||||||
Ряд (Range)
|
Ряд (Range)|Range
|
||||||
Функции (Functions)
|
Функции (Functions)|Functions
|
||||||
Функции с множественным возвратом (Multiple Return Values)
|
Функции с множественным возвратом (Multiple Return Values)|Multiple Return Values
|
||||||
Функции с переменным числом аргументов (Variadic Functions)
|
Функции с переменным числом аргументов (Variadic Functions)|Variadic Functions
|
||||||
Замыкания (Closures)
|
Замыкания (Closures)|Closures
|
||||||
Рекурсия (Recursion)
|
Рекурсия (Recursion)|Recursion
|
||||||
Указатели (Pointers)
|
Указатели (Pointers)|Pointers
|
||||||
Структуры (Structs)
|
Структуры (Structs)|Structs
|
||||||
Методы (Methods)
|
Методы (Methods)|Methods
|
||||||
Интерфейсы (Interfaces)
|
Интерфейсы (Interfaces)|Interfaces
|
||||||
Ошибки (Errors)
|
Ошибки (Errors)|Errors
|
||||||
Горутины (Goroutines)
|
Горутины (Goroutines)|Goroutines
|
||||||
Каналы (Channels)
|
Каналы (Channels)|Channels
|
||||||
Буферизированный канал (Channel Buffering)
|
Буферизированный канал (Channel Buffering)|Channel Buffering
|
||||||
Синхронизация канала (Channel Synchronization)
|
Синхронизация канала (Channel Synchronization)|Channel Synchronization
|
||||||
Направления канала (Channel Directions)
|
Направления канала (Channel Directions)|Channel Directions
|
||||||
Select
|
Select|Select
|
||||||
Тайм-ауты (Timeouts)
|
Тайм-ауты (Timeouts)|Timeouts
|
||||||
Неблокируемые операции в каналах (Non-Blocking Channel Operations)
|
Неблокируемые операции в каналах (Non-Blocking Channel Operations)|Non-Blocking Channel Operations
|
||||||
Закрытие каналов (Closing Channels)
|
Закрытие каналов (Closing Channels)|Closing Channels
|
||||||
Перебор значений из каналов (Range over Channels)
|
Перебор значений из каналов (Range over Channels)|Range over Channels
|
||||||
Таймеры (Timers)
|
Таймеры (Timers)|Timers
|
||||||
Тикеры (повторения) (Tickers)
|
Тикеры (повторения) (Tickers)|Tickers
|
||||||
Пулы воркеров (Worker Pools)
|
Пулы воркеров (Worker Pools)|Worker Pools
|
||||||
WaitGroups
|
WaitGroups|WaitGroups
|
||||||
Ограничение скорости (Rate Limiting)
|
Ограничение скорости (Rate Limiting)|Rate Limiting
|
||||||
Атомарные счетчики (Atomic Counters)
|
Атомарные счетчики (Atomic Counters)|Atomic Counters
|
||||||
Мьютексы (Mutexes)
|
Мьютексы (Mutexes)|Mutexes
|
||||||
Управление состоянием горутин (Stateful Goroutines)
|
Управление состоянием горутин (Stateful Goroutines)|Stateful Goroutines
|
||||||
Сортировка (Sorting)
|
Сортировка (Sorting)|Sorting
|
||||||
Сортировка через функции (Sorting by Functions)
|
Сортировка через функции (Sorting by Functions)|Sorting by Functions
|
||||||
Panic
|
Panic|Panic
|
||||||
Defer
|
Defer|Defer
|
||||||
Функции коллекции (Collection Functions)
|
Функции коллекции (Collection Functions)|Collection Functions
|
||||||
Строковые функции (String Functions)
|
Строковые функции (String Functions)|String Functions
|
||||||
Форматирование строк (String Formatting)
|
Форматирование строк (String Formatting)|String Formatting
|
||||||
Регулярные выражения (Regular Expressions)
|
Регулярные выражения (Regular Expressions)|Regular Expressions
|
||||||
JSON
|
JSON|JSON
|
||||||
XML
|
XML|XML
|
||||||
Время (Time)
|
Время (Time)|Time
|
||||||
Epoch
|
Epoch|Epoch
|
||||||
Форматирование времени (Time Formatting / Parsing)
|
Форматирование времени (Time Formatting / Parsing)|Time Formatting / Parsing
|
||||||
Случайные числа (Random Numbers)
|
Случайные числа (Random Numbers)|Random Numbers
|
||||||
Парсинг чисел (Number Parsing)
|
Парсинг чисел (Number Parsing)|Number Parsing
|
||||||
Парсинг URL (URL Parsing)
|
Парсинг URL (URL Parsing)|URL Parsing
|
||||||
Хеш SHA1 (SHA1 Hashes)
|
Хеш SHA1 (SHA1 Hashes)|SHA1 Hashes
|
||||||
Кодирование Base64 (Base64 Encoding)
|
Кодирование Base64 (Base64 Encoding)|Base64 Encoding
|
||||||
Чтение файлов (Reading Files)
|
Чтение файлов (Reading Files)|Reading Files
|
||||||
Запись файлов (Writing Files)
|
Запись файлов (Writing Files)|Writing Files
|
||||||
Строковые фильтры (Line Filters)
|
Строковые фильтры (Line Filters)|Line Filters
|
||||||
Пути к файлам (File Paths)
|
Пути к файлам (File Paths)|File Paths
|
||||||
Директории (Directories)
|
Директории (Directories)|Directories
|
||||||
Временные файлы и директории (Temporary Files and Directories)
|
Временные файлы и директории (Temporary Files and Directories)|Temporary Files and Directories
|
||||||
Тестирование (Testing)
|
Тестирование (Testing)|Testing
|
||||||
Аргументы командной строки (Command-Line Arguments)
|
Аргументы командной строки (Command-Line Arguments)|Command-Line Arguments
|
||||||
Флаги командной строки (Command-Line Flags)
|
Флаги командной строки (Command-Line Flags)|Command-Line Flags
|
||||||
Подкоманды командной строки (Command-Line Subcommands)
|
Подкоманды командной строки (Command-Line Subcommands)|Command-Line Subcommands
|
||||||
Переменные среды (Environment Variables)
|
Переменные среды (Environment Variables)|Environment Variables
|
||||||
HTTP клиенты (HTTP Clients)
|
HTTP клиенты (HTTP Clients)|HTTP Clients
|
||||||
HTTP серверы (HTTP Servers)
|
HTTP серверы (HTTP Servers)|HTTP Servers
|
||||||
Порождающие процессы (Spawning Processes)
|
Порождающие процессы (Spawning Processes)|Spawning Processes
|
||||||
Исполняющие процессы (Exec'ing Processes)
|
Исполняющие процессы (Exec'ing Processes)|Exec'ing Processes
|
||||||
Сигналы (Signals)
|
Сигналы (Signals)|Signals
|
||||||
Выход (Exit)
|
Выход (Exit)|Exit
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
cbd7ae7158cdb62fbd0f5a21c1f89a9a43369900
|
||||||
UCPdVNrl0-P
|
CiZ6oDF6A_l
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
e1b3a73458ef10d4cfe093766d05503ed7706544
|
||||||
UCPdVNrl0-P
|
aEOYD0chCYy
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
e0148b9b4acb01e849b8f678cba03f549d250c44
|
0a1abdfdd647b24082d46fd54645bc597fb86b83
|
||||||
V3oV1bvh94k
|
3E068RAuW3p
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
4d4cf7b115f26c12d7e188a2d25c66e64f34edfe
|
||||||
UCPdVNrl0-P
|
HNVSsVpnHXN
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
a0904bf943d61e4d220f29ef3a0e6f1368657e78
|
||||||
UCPdVNrl0-P
|
uEeOmen99CF
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
29e4099160217bd2817aef8546927056b9ea4b12
|
||||||
UCPdVNrl0-P
|
3NHqwE7Bwjz
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
92a2a89118f08e7ac1fcf82567c14a31e6a2fabe
|
||||||
UCPdVNrl0-P
|
jHsjIHrpHXV
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
67493a491669c559ceac851a959828a00ceb89eb
|
||||||
UCPdVNrl0-P
|
V8RCD4w9KY-
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
5a274ea5c01af8573ce5c6382f41189446a8be09
|
||||||
UCPdVNrl0-P
|
J2PladF_bU9
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
5e8a32a022ffb4f746bbdf101face52ca008aeba
|
||||||
UCPdVNrl0-P
|
urAoHQtRHro
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
375f50de2467743174f0d60d0635a3198e031094
|
||||||
UCPdVNrl0-P
|
wSDrVn9TIK5
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
e316c57acf4cc993f182f2d341a608a1eac4a551
|
||||||
UCPdVNrl0-P
|
_r_-ZzDzQUH
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
7320b5803ad9875733c4ca9644600ae8a55009d8
|
||||||
UCPdVNrl0-P
|
sr1FH0P_2Te
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
31b56e63896203b29fd3a08a1f5036ca62d6d0c2
|
||||||
UCPdVNrl0-P
|
e1Vlh7LNMFJ
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
7df99bb0443cbe61600e6466782a66e76cf7d927
|
||||||
UCPdVNrl0-P
|
6lC_YCFEXVl
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
61c3cd2ec3ab8fcd4528452e88fe25c0eafbb2de
|
||||||
UCPdVNrl0-P
|
--fC2aTdXEz
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
91979262128065a70899eb9ee32da1549864b609
|
||||||
UCPdVNrl0-P
|
9-iENtmoI5k
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
878cb29aa644aef60217a2d97a586080cd783daa
|
||||||
UCPdVNrl0-P
|
dojmebwCvC4
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
450a55230493ea17b3b7aeef666f55f796c050a8
|
||||||
UCPdVNrl0-P
|
BgQ_ag62q4k
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
7bbdffb4411e01e9962593d1de16a5654fb780d4
|
||||||
UCPdVNrl0-P
|
6VDVplbM_Sk
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
c478d7d6259b800c42307c0d520fb669109cb2f7
|
||||||
UCPdVNrl0-P
|
Fv7uI0y_EWr
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
fe343c61ebf68660290e3717592e7904c47abad5
|
||||||
UCPdVNrl0-P
|
4sH5Tv_SBoU
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
9de125c9da86967491563075071ccd110b95b8ef
|
||||||
UCPdVNrl0-P
|
79i2V9dLU15
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
ec8fd69aa19e54a7ea05d2a911f09d3a98f0396c
|
4efc6eb143a0e04132f16fcf929f7eed232b897d
|
||||||
VxYIifr_UuH
|
8Z80D4rlbaE
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
a4e8d30b7a6f3a6abd96b916d81ce5930bad94f9
|
0282a23b343fbbbf9e3cb32d1efd934c9d707d26
|
||||||
lNuS9ysZmxH
|
xndCIK5Wo-Y
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
e09278982d7d148dd22c45730d0820659a7ecae8
|
||||||
UCPdVNrl0-P
|
bS2bkTzP8cG
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
92a88a19fb7453935093e2ae893fcef18432f596
|
||||||
UCPdVNrl0-P
|
dLiHA3PDCFp
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
df6205e7069d3914f2a40940696755f4b6343a9b
|
||||||
UCPdVNrl0-P
|
HjBZNUEcF_e
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
b3128d2e4d2238e56d99bfc7138389257076871f
|
||||||
UCPdVNrl0-P
|
qfALObNYETK
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
9cfe1eb1a10a8977bee1581389953af18afc9bc0
|
||||||
UCPdVNrl0-P
|
6Khmls9Dsin
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
8c7db363d911ef04d1340ff195da03a5373b79ab
|
||||||
UCPdVNrl0-P
|
USO1aTX_xMe
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
3b01f109970c31ffb1c67cfea86a8eaa2959f7e0
|
||||||
UCPdVNrl0-P
|
FokCtF5TvgL
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
9b4a9b30f02201adf86ab6c6abc60e23088026be
|
||||||
UCPdVNrl0-P
|
4PKUrIjNyTE
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
909a2f7a79ef942a544292b283a964ae530fd612
|
||||||
UCPdVNrl0-P
|
VHnMkOQfQea
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
03975452ff4c127a4a78897643ce3eca0b90b239
|
||||||
UCPdVNrl0-P
|
CKeOTktHnJe
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
a2f106b835828ac784feffb869604e059d788680
|
||||||
UCPdVNrl0-P
|
zbl7ytLnFCK
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
f8c6ffeaa1f52aeff136779442bbd160313a6b32
|
||||||
UCPdVNrl0-P
|
4GBukIe-7ie
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
a93813bfc920c685c55bf09a3425f63fcc4a542b
|
||||||
UCPdVNrl0-P
|
rC0qLhImKAo
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
176b57caf5a053e3707da299ca9fbb78314d283f
|
||||||
UCPdVNrl0-P
|
m6mvXlZtHTX
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
b75f7597af0526d0fefb481ef7987b5e186c0c04
|
||||||
UCPdVNrl0-P
|
oPbHEHLaRrN
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
984c5939e46284833637df8aa8dd38f51b571425
|
||||||
UCPdVNrl0-P
|
GB_bgVcRKg2
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
4cda643ba233014fe6b30966c37d4d0fcd4edbe8
|
f64d96d9e998d1c8821689af70580b3929a464cf
|
||||||
oqcrTfY4Ykd
|
zhhfA6LqgFI
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
8e3867a11504ce30880c75e3d5ed74907a8ef1b5
|
||||||
UCPdVNrl0-P
|
Xs9zJ53YIAa
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
97236c6deebee661d0bd1e696b12e4ea671d06ff
|
||||||
UCPdVNrl0-P
|
32lRsL-MYrP
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
0252f365e73e310a8f4dc4431f598ffcea3efc72
|
||||||
UCPdVNrl0-P
|
VQrgvKKcvRg
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
a059f86c91ed4084fb37f321a7def4ef88b62e67
|
||||||
UCPdVNrl0-P
|
X9bT-mDzj4o
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
4984e90d62323e378c35e5c52d0c5646fd150d82
|
||||||
UCPdVNrl0-P
|
2QNUQPuiFlR
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
e7e07404454809cbacb719ad94e70726d22dacc1
|
||||||
UCPdVNrl0-P
|
n_gVZus4DBP
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
8ffedfce40621f09c42f07459127279d66425d08
|
||||||
UCPdVNrl0-P
|
TKe8eifne_2
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
818faf1a5caccb1628010427eff861edd8379de8
|
||||||
UCPdVNrl0-P
|
UeDwSoYepQt
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
995a3c5dec1de68fe79d5d3172531fb5d2b99870
|
||||||
UCPdVNrl0-P
|
sJZCI3Gm3Ht
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
99866fef55916b593bf73df9591ca9d7d2c86d7e
|
||||||
UCPdVNrl0-P
|
PMJP7pf-n5h
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
1a41d8c725f8bfe62838744d6327404ec1ddc319
|
||||||
UCPdVNrl0-P
|
gZXCCqO7ezT
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
64772226ab38092e29f23802c8138a723e23cc83
|
||||||
UCPdVNrl0-P
|
2bpsxisGGLj
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
7a8299db21f9554a2b43ecece2d8abf7a370189c
|
||||||
UCPdVNrl0-P
|
G61ruGfMQZA
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
e532cf20c51b0106aba8c041ec44480f7690da5e
|
||||||
UCPdVNrl0-P
|
ZE4n1Jt55m0
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
441dc07d57c03df070488f85dbe24e5ef6591bf7
|
||||||
UCPdVNrl0-P
|
SCMyPsGlXtX
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
d1689f059a29e7e0d3f9ccd52632220d487d6ca0
|
||||||
UCPdVNrl0-P
|
7RnBhz_kuki
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
babc12f5066652f4cb0151231c06f1037298ff28
|
f0b0a50b3471f972b26e6fefb481730661aac6e1
|
||||||
M218D9Tldlr
|
Zt1KHMGZESo
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
1c4cf252844f42861e8fbc59a604833d0dbd24c0
|
||||||
UCPdVNrl0-P
|
SYLIv-rApFj
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
e5f981f078207ac4f67b26be87a73c2989006685
|
||||||
UCPdVNrl0-P
|
BUbDhWP8PV_k
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
e32d27f8b78c3e3f24c5dd98f864ffdb9567d628
|
||||||
UCPdVNrl0-P
|
dz6tVXvffuH
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
a719d863a0b07434beade5c6582eff76df8bd2ef
|
||||||
UCPdVNrl0-P
|
79qTVPHnwGQ
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
da39a3ee5e6b4b0d3255bfef95601890afd80709
|
f6c74f9903720805417ffe5765cef04e3f58d966
|
||||||
UCPdVNrl0-P
|
LscGbwmQZns
|
||||||
|
17
public/404.html
generated
17
public/404.html
generated
@ -1,17 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-eqiv="content-type" content="text/html;charset=utf-8">
|
|
||||||
<title>Go by Example: Not Found</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="intro">
|
|
||||||
<h2><a href="./">Go by Example</a></h2>
|
|
||||||
<p>Sorry, we couldn't find that! Check out the <a href="./">home page</a>?</p>
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://twitter.com/mmcgrana">@mmcgrana</a> | <a href="mailto:mmcgrana@gmail.com">feedback</a> | <a href="https://github.com/mmcgrana/gobyexample">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/arrays
generated
41
public/arrays
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Массивы (Arrays)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'switch';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'slices';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="arrays">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Массивы (Arrays)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="slices">Срезы (Slices)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/arrays">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/atomic-counters
generated
41
public/atomic-counters
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Атомарные счетчики (Atomic Counters)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'rate-limiting';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'mutexes';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="atomic-counters">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Атомарные счетчики (Atomic Counters)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="mutexes">Мьютексы (Mutexes)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/atomic-counters">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/base64
generated
41
public/base64
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Кодирование Base64 (Base64 Encoding)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'sha1';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'reading-files';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="base64">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Кодирование Base64 (Base64 Encoding)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="reading-files">Чтение файлов (Reading Files)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/base64">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/channel-buffering
generated
41
public/channel-buffering
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Буферизированный канал (Channel Buffering)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'channels';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'channel-synchronization';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="channel-buffering">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Буферизированный канал (Channel Buffering)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="channel-synchronization">Синхронизация канала (Channel Synchronization)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/channel-buffering">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/channel-directions
generated
41
public/channel-directions
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Направления канала (Channel Directions)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'channel-synchronization';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'select';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="channel-directions">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Направления канала (Channel Directions)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="select">Select</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/channel-directions">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/channel-synchronization
generated
41
public/channel-synchronization
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Синхронизация канала (Channel Synchronization)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'channel-buffering';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'channel-directions';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="channel-synchronization">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Синхронизация канала (Channel Synchronization)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="channel-directions">Направления канала (Channel Directions)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/channel-synchronization">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/channels
generated
41
public/channels
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Каналы (Channels)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'goroutines';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'channel-buffering';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="channels">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Каналы (Channels)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="channel-buffering">Буферизированный канал (Channel Buffering)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/channels">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
BIN
public/clipboard.png
generated
BIN
public/clipboard.png
generated
Binary file not shown.
Before Width: | Height: | Size: 488 B |
41
public/closing-channels
generated
41
public/closing-channels
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Закрытие каналов (Closing Channels)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'non-blocking-channel-operations';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'range-over-channels';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="closing-channels">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Закрытие каналов (Closing Channels)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="range-over-channels">Перебор значений из каналов (Range over Channels)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/closing-channels">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/closures
generated
41
public/closures
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Замыкания (Closures)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'variadic-functions';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'recursion';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="closures">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Замыкания (Closures)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="recursion">Рекурсия (Recursion)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/closures">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/collection-functions
generated
41
public/collection-functions
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Функции коллекции (Collection Functions)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'defer';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'string-functions';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="collection-functions">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Функции коллекции (Collection Functions)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="string-functions">Строковые функции (String Functions)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/collection-functions">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/command-line-arguments
generated
41
public/command-line-arguments
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Аргументы командной строки (Command-Line Arguments)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'testing';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'command-line-flags';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="command-line-arguments">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Аргументы командной строки (Command-Line Arguments)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="command-line-flags">Флаги командной строки (Command-Line Flags)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/command-line-arguments">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/command-line-flags
generated
41
public/command-line-flags
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Флаги командной строки (Command-Line Flags)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'command-line-arguments';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'command-line-subcommands';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="command-line-flags">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Флаги командной строки (Command-Line Flags)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="command-line-subcommands">Подкоманды командной строки (Command-Line Subcommands)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/command-line-flags">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/command-line-subcommands
generated
41
public/command-line-subcommands
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Подкоманды командной строки (Command-Line Subcommands)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'command-line-flags';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'environment-variables';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="command-line-subcommands">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Подкоманды командной строки (Command-Line Subcommands)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="environment-variables">Переменные среды (Environment Variables)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/command-line-subcommands">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/constants
generated
41
public/constants
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Константы (Constants)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'variables';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'for';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="constants">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Константы (Constants)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="for">Цикл For</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/constants">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
220
public/defer
generated
220
public/defer
generated
@ -1,220 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Defer</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'panic';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'collection-functions';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="defer">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Defer</h2>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p><em>Defer</em> используется, чтобы гарантировать, что
|
|
||||||
вызов функции будет выполнен позже при выполнении
|
|
||||||
программы, обычно для целей очистки. <code>defer</code> часто
|
|
||||||
используется там, где в других языках используются
|
|
||||||
<code>ensure</code> и <code>finally</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty leading">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
<a href="http://play.golang.org/p/lVhFAPGaGby" target="_blank"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
|
||||||
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kn">import</span> <span class="p">(</span>
|
|
||||||
<span class="s">"fmt"</span>
|
|
||||||
<span class="s">"os"</span>
|
|
||||||
<span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Предположим, мы хотим создать файл, записать в него,
|
|
||||||
а затем закрыть, когда закончим. Вот как нам поможет
|
|
||||||
<code>defer</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Сразу же после получения объекта файла с помощью
|
|
||||||
<code>createFile</code> мы откладываем закрытие этого файла
|
|
||||||
с помощью <code>closeFile</code>. Она будет выполнена в
|
|
||||||
конце включающей функции (<code>main</code>) после завершения
|
|
||||||
<code>writeFile</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">f</span> <span class="o">:=</span> <span class="nx">createFile</span><span class="p">(</span><span class="s">"/tmp/defer.txt"</span><span class="p">)</span>
|
|
||||||
<span class="k">defer</span> <span class="nx">closeFile</span><span class="p">(</span><span class="nx">f</span><span class="p">)</span>
|
|
||||||
<span class="nx">writeFile</span><span class="p">(</span><span class="nx">f</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">func</span> <span class="nx">createFile</span><span class="p">(</span><span class="nx">p</span> <span class="kt">string</span><span class="p">)</span> <span class="o">*</span><span class="nx">os</span><span class="p">.</span><span class="nx">File</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">"creating"</span><span class="p">)</span>
|
|
||||||
<span class="nx">f</span><span class="p">,</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">os</span><span class="p">.</span><span class="nx">Create</span><span class="p">(</span><span class="nx">p</span><span class="p">)</span>
|
|
||||||
<span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
|
|
||||||
<span class="nb">panic</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
<span class="k">return</span> <span class="nx">f</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">func</span> <span class="nx">writeFile</span><span class="p">(</span><span class="nx">f</span> <span class="o">*</span><span class="nx">os</span><span class="p">.</span><span class="nx">File</span><span class="p">)</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">"writing"</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Fprintln</span><span class="p">(</span><span class="nx">f</span><span class="p">,</span> <span class="s">"data"</span><span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Важно проверять наличие ошибок при закрытии файла,
|
|
||||||
даже в отложенной функции.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">func</span> <span class="nx">closeFile</span><span class="p">(</span><span class="nx">f</span> <span class="o">*</span><span class="nx">os</span><span class="p">.</span><span class="nx">File</span><span class="p">)</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">"closing"</span><span class="p">)</span>
|
|
||||||
<span class="nx">err</span> <span class="o">:=</span> <span class="nx">f</span><span class="p">.</span><span class="nx">Close</span><span class="p">()</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="k">if</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Fprintf</span><span class="p">(</span><span class="nx">os</span><span class="p">.</span><span class="nx">Stderr</span><span class="p">,</span> <span class="s">"error: %v\n"</span><span class="p">,</span> <span class="nx">err</span><span class="p">)</span>
|
|
||||||
<span class="nx">os</span><span class="p">.</span><span class="nx">Exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Запуск программы подтверждает, что файл закрыт
|
|
||||||
после записи.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="gp">$</span> go run defer.go
|
|
||||||
<span class="go">creating</span>
|
|
||||||
<span class="go">writing</span>
|
|
||||||
<span class="go">closing</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="collection-functions">Функции коллекции (Collection Functions)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/defer">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import (\u000A \"fmt\"\u000A \"os\"\u000A)\u000A');codeLines.push('func main() {\u000A');codeLines.push(' f := createFile(\"/tmp/defer.txt\")\u000A defer closeFile(f)\u000A writeFile(f)\u000A}\u000A');codeLines.push('func createFile(p string) *os.File {\u000A fmt.Println(\"creating\")\u000A f, err := os.Create(p)\u000A if err != nil {\u000A panic(err)\u000A }\u000A return f\u000A}\u000A');codeLines.push('func writeFile(f *os.File) {\u000A fmt.Println(\"writing\")\u000A fmt.Fprintln(f, \"data\")\u000A');codeLines.push('}\u000A');codeLines.push('func closeFile(f *os.File) {\u000A fmt.Println(\"closing\")\u000A err := f.Close()\u000A');codeLines.push(' if err != nil {\u000A fmt.Fprintf(os.Stderr, \"error: %v\\n\", err)\u000A os.Exit(1)\u000A }\u000A}\u000A');codeLines.push('');
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/directories
generated
41
public/directories
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Директории (Directories)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'file-paths';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'temporary-files-and-directories';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="directories">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Директории (Directories)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="temporary-files-and-directories">Временные файлы и директории (Temporary Files and Directories)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/directories">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/environment-variables
generated
41
public/environment-variables
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Переменные среды (Environment Variables)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'command-line-subcommands';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'http';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="environment-variables">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Переменные среды (Environment Variables)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="http">HTTP клиенты (HTTP Clients)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/environment-variables">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
183
public/epoch
generated
183
public/epoch
generated
@ -1,183 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Epoch</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'time';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'time-formatting-parsing';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="epoch">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Epoch</h2>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Общим требованием в программах является получение
|
|
||||||
количества секунд, миллисекунд или наносекунд в <a href="http://en.wikipedia.org/wiki/Unix_time">Unixtime</a>.
|
|
||||||
Вот как это сделать в Go.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty leading">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
<a href="http://play.golang.org/p/MdrFxlv7Ds8" target="_blank"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
|
||||||
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kn">import</span> <span class="p">(</span>
|
|
||||||
<span class="s">"fmt"</span>
|
|
||||||
<span class="s">"time"</span>
|
|
||||||
<span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Используйте <code>time.Now</code> с <code>Unix</code> или <code>UnixNano</code>,
|
|
||||||
чтобы получить время, прошедшее с начала эпохи Unix в
|
|
||||||
секундах или наносекундах соответственно.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">now</span> <span class="o">:=</span> <span class="nx">time</span><span class="p">.</span><span class="nx">Now</span><span class="p">()</span>
|
|
||||||
<span class="nx">secs</span> <span class="o">:=</span> <span class="nx">now</span><span class="p">.</span><span class="nx">Unix</span><span class="p">()</span>
|
|
||||||
<span class="nx">nanos</span> <span class="o">:=</span> <span class="nx">now</span><span class="p">.</span><span class="nx">UnixNano</span><span class="p">()</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">now</span><span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Обратите внимание, что <code>UnixMillis</code> не существует,
|
|
||||||
поэтому, чтобы получить миллисекунды с начала эпохи Unix,
|
|
||||||
вам нужно будет вручную делить наносекунды.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">millis</span> <span class="o">:=</span> <span class="nx">nanos</span> <span class="o">/</span> <span class="mi">1000000</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">secs</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">millis</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">nanos</span><span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Вы также можете конвертировать целые секунды или наносекунды
|
|
||||||
Unixtime в соответствующее <code>время</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">time</span><span class="p">.</span><span class="nx">Unix</span><span class="p">(</span><span class="nx">secs</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">time</span><span class="p">.</span><span class="nx">Unix</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">nanos</span><span class="p">))</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="gp">$</span> go run epoch.go
|
|
||||||
<span class="go">2012-10-31 16:13:58.292387 +0000 UTC</span>
|
|
||||||
<span class="go">1351700038</span>
|
|
||||||
<span class="go">1351700038292</span>
|
|
||||||
<span class="go">1351700038292387000</span>
|
|
||||||
<span class="go">2012-10-31 16:13:58 +0000 UTC</span>
|
|
||||||
<span class="go">2012-10-31 16:13:58.292387 +0000 UTC</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Далее мы рассмотрим еще одну задачу, связанную со
|
|
||||||
временем: разбор и форматирование времени.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="time-formatting-parsing">Форматирование времени (Time Formatting / Parsing)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/epoch">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import (\u000A \"fmt\"\u000A \"time\"\u000A)\u000A');codeLines.push('func main() {\u000A');codeLines.push(' now := time.Now()\u000A secs := now.Unix()\u000A nanos := now.UnixNano()\u000A fmt.Println(now)\u000A');codeLines.push(' millis := nanos / 1000000\u000A fmt.Println(secs)\u000A fmt.Println(millis)\u000A fmt.Println(nanos)\u000A');codeLines.push(' fmt.Println(time.Unix(secs, 0))\u000A fmt.Println(time.Unix(0, nanos))\u000A}\u000A');codeLines.push('');codeLines.push('');
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/errors
generated
41
public/errors
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Ошибки (Errors)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'interfaces';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'goroutines';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="errors">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Ошибки (Errors)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="goroutines">Горутины (Goroutines)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/errors">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/execing-processes
generated
41
public/execing-processes
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Исполняющие процессы (Exec'ing Processes)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'spawning-processes';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'signals';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="execing-processes">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Исполняющие процессы (Exec'ing Processes)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="signals">Сигналы (Signals)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/execing-processes">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
33
public/exit
generated
33
public/exit
generated
@ -1,33 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Выход (Exit)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'signals';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="exit">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Выход (Exit)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/exit">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
BIN
public/favicon.ico
generated
BIN
public/favicon.ico
generated
Binary file not shown.
Before Width: | Height: | Size: 70 KiB |
41
public/file-paths
generated
41
public/file-paths
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Пути к файлам (File Paths)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'line-filters';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'directories';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="file-paths">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Пути к файлам (File Paths)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="directories">Директории (Directories)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/file-paths">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/for
generated
41
public/for
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Цикл For</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'constants';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'if-else';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="for">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Цикл For</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="if-else">If/Else</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/for">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/functions
generated
41
public/functions
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Функции (Functions)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'range';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'multiple-return-values';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="functions">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Функции (Functions)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="multiple-return-values">Функции с множественным возвратом (Multiple Return Values)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/functions">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/goroutines
generated
41
public/goroutines
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Горутины (Goroutines)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'errors';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'channels';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="goroutines">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Горутины (Goroutines)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="channels">Каналы (Channels)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/goroutines">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
142
public/hello-world
generated
142
public/hello-world
generated
@ -1,142 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Hello World</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'values';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="hello-world">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Hello World</h2>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Наша первая программа напечатает классическое сообщение “hello world”
|
|
||||||
Полный код.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
<a href="http://play.golang.org/p/r-UD-XLVae8" target="_blank"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
|
||||||
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kn">import</span> <span class="s">"fmt"</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">"hello world"</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>To run the program, put the code in <code>hello-world.go</code> and
|
|
||||||
use <code>go run</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="gp">$</span> go run hello-world.go
|
|
||||||
<span class="go">hello world</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Sometimes we’ll want to build our programs into
|
|
||||||
binaries. We can do this using <code>go build</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="gp">$</span> go build hello-world.go
|
|
||||||
<span class="gp">$</span> ls
|
|
||||||
<span class="go">hello-world hello-world.go</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>We can then execute the built binary directly.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="gp">$</span> ./hello-world
|
|
||||||
<span class="go">hello world</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Now that we can run and build basic Go programs, let’s
|
|
||||||
learn more about the language.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="values">Типы данных (Values)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/hello-world">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
codeLines.push('package main\u000A');codeLines.push('import \"fmt\"\u000A');codeLines.push('func main() {\u000A fmt.Println(\"hello world\")\u000A}\u000A');codeLines.push('');codeLines.push('');codeLines.push('');codeLines.push('');
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/http
generated
41
public/http
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: HTTP серверы (HTTP Servers)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'http';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'spawning-processes';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="http">
|
|
||||||
<h2><a href="./">Go в примерах</a>: HTTP серверы (HTTP Servers)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="spawning-processes">Порождающие процессы (Spawning Processes)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/http">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
191
public/if-else
generated
191
public/if-else
generated
@ -1,191 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: If/Else</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'for';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'switch';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="if-else">
|
|
||||||
<h2><a href="./">Go в примерах</a>: If/Else</h2>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Условные операторы <code>if</code> и<code>else</code> в Go
|
|
||||||
выглядят достаточно стандартно</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty leading">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
<a href="http://play.golang.org/p/DprUWlg26IL" target="_blank"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
|
||||||
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kn">import</span> <span class="s">"fmt"</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Стандартное использование</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="k">if</span> <span class="mi">7</span><span class="o">%</span><span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">"7 is even"</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">"7 is odd"</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Вы можете использовать блоке <code>if</code> без блока <code>else</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="k">if</span> <span class="mi">8</span><span class="o">%</span><span class="mi">4</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">"8 is divisible by 4"</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Присваивание переменной может происходить до условия.
|
|
||||||
Любые определенные значения будут доступны в
|
|
||||||
последующих ветках</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="k">if</span> <span class="nx">num</span> <span class="o">:=</span> <span class="mi">9</span><span class="p">;</span> <span class="nx">num</span> <span class="p"><</span> <span class="mi">0</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">num</span><span class="p">,</span> <span class="s">"is negative"</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="nx">num</span> <span class="p"><</span> <span class="mi">10</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">num</span><span class="p">,</span> <span class="s">"has 1 digit"</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">num</span><span class="p">,</span> <span class="s">"has multiple digits"</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Имейте ввиду, что в Go не надо использовать скобки в условии,
|
|
||||||
но блок необходимо заключать в фигурные скобки</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="gp">$</span> go run <span class="k">if</span>-else.go
|
|
||||||
<span class="go">7 is odd</span>
|
|
||||||
<span class="go">8 is divisible by 4</span>
|
|
||||||
<span class="go">9 has 1 digit</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>There is no <a href="http://en.wikipedia.org/wiki/%3F:">ternary if</a>
|
|
||||||
in Go, so you’ll need to use a full <code>if</code> statement even
|
|
||||||
for basic conditions.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="switch">Switch</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/if-else">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"fmt\"\u000A');codeLines.push('func main() {\u000A');codeLines.push(' if 7%2 == 0 {\u000A fmt.Println(\"7 is even\")\u000A } else {\u000A fmt.Println(\"7 is odd\")\u000A }\u000A');codeLines.push(' if 8%4 == 0 {\u000A fmt.Println(\"8 is divisible by 4\")\u000A }\u000A');codeLines.push(' if num := 9; num \x3C 0 {\u000A fmt.Println(num, \"is negative\")\u000A } else if num \x3C 10 {\u000A fmt.Println(num, \"has 1 digit\")\u000A } else {\u000A fmt.Println(num, \"has multiple digits\")\u000A }\u000A}\u000A');codeLines.push('');codeLines.push('');codeLines.push('');
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
182
public/index.html
generated
182
public/index.html
generated
@ -1,182 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="intro">
|
|
||||||
<h2><a href="./">Go в примерах</a></h2>
|
|
||||||
<p>
|
|
||||||
<a href="http://golang.org">Go</a> - это язык программирования с
|
|
||||||
открытым исходным кодом, предназначенный для создания простого,
|
|
||||||
быстрого и надежного программного обеспечения.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<em>Go в примерах</em> Go by Example - это практическое введение
|
|
||||||
в Go с использованием примеров реальных программ. Проверьте
|
|
||||||
<a href="hello-world">первый пример</a> или просмотрите полный
|
|
||||||
список ниже.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
|
|
||||||
<li><a href="hello-world">Hello World</a></li>
|
|
||||||
|
|
||||||
<li><a href="values">Типы данных (Values)</a></li>
|
|
||||||
|
|
||||||
<li><a href="variables">Переменные (Variables)</a></li>
|
|
||||||
|
|
||||||
<li><a href="constants">Константы (Constants)</a></li>
|
|
||||||
|
|
||||||
<li><a href="for">Цикл For</a></li>
|
|
||||||
|
|
||||||
<li><a href="if-else">If/Else</a></li>
|
|
||||||
|
|
||||||
<li><a href="switch">Switch</a></li>
|
|
||||||
|
|
||||||
<li><a href="arrays">Массивы (Arrays)</a></li>
|
|
||||||
|
|
||||||
<li><a href="slices">Срезы (Slices)</a></li>
|
|
||||||
|
|
||||||
<li><a href="maps">Карты (Maps)</a></li>
|
|
||||||
|
|
||||||
<li><a href="range">Ряд (Range)</a></li>
|
|
||||||
|
|
||||||
<li><a href="functions">Функции (Functions)</a></li>
|
|
||||||
|
|
||||||
<li><a href="multiple-return-values">Функции с множественным возвратом (Multiple Return Values)</a></li>
|
|
||||||
|
|
||||||
<li><a href="variadic-functions">Функции с переменным числом аргументов (Variadic Functions)</a></li>
|
|
||||||
|
|
||||||
<li><a href="closures">Замыкания (Closures)</a></li>
|
|
||||||
|
|
||||||
<li><a href="recursion">Рекурсия (Recursion)</a></li>
|
|
||||||
|
|
||||||
<li><a href="pointers">Указатели (Pointers)</a></li>
|
|
||||||
|
|
||||||
<li><a href="structs">Структуры (Structs)</a></li>
|
|
||||||
|
|
||||||
<li><a href="methods">Методы (Methods)</a></li>
|
|
||||||
|
|
||||||
<li><a href="interfaces">Интерфейсы (Interfaces)</a></li>
|
|
||||||
|
|
||||||
<li><a href="errors">Ошибки (Errors)</a></li>
|
|
||||||
|
|
||||||
<li><a href="goroutines">Горутины (Goroutines)</a></li>
|
|
||||||
|
|
||||||
<li><a href="channels">Каналы (Channels)</a></li>
|
|
||||||
|
|
||||||
<li><a href="channel-buffering">Буферизированный канал (Channel Buffering)</a></li>
|
|
||||||
|
|
||||||
<li><a href="channel-synchronization">Синхронизация канала (Channel Synchronization)</a></li>
|
|
||||||
|
|
||||||
<li><a href="channel-directions">Направления канала (Channel Directions)</a></li>
|
|
||||||
|
|
||||||
<li><a href="select">Select</a></li>
|
|
||||||
|
|
||||||
<li><a href="timeouts">Тайм-ауты (Timeouts)</a></li>
|
|
||||||
|
|
||||||
<li><a href="non-blocking-channel-operations">Неблокируемые операции в каналах (Non-Blocking Channel Operations)</a></li>
|
|
||||||
|
|
||||||
<li><a href="closing-channels">Закрытие каналов (Closing Channels)</a></li>
|
|
||||||
|
|
||||||
<li><a href="range-over-channels">Перебор значений из каналов (Range over Channels)</a></li>
|
|
||||||
|
|
||||||
<li><a href="timers">Таймеры (Timers)</a></li>
|
|
||||||
|
|
||||||
<li><a href="tickers">Тикеры (повторения) (Tickers)</a></li>
|
|
||||||
|
|
||||||
<li><a href="worker-pools">Пулы воркеров (Worker Pools)</a></li>
|
|
||||||
|
|
||||||
<li><a href="waitgroups">WaitGroups</a></li>
|
|
||||||
|
|
||||||
<li><a href="rate-limiting">Ограничение скорости (Rate Limiting)</a></li>
|
|
||||||
|
|
||||||
<li><a href="atomic-counters">Атомарные счетчики (Atomic Counters)</a></li>
|
|
||||||
|
|
||||||
<li><a href="mutexes">Мьютексы (Mutexes)</a></li>
|
|
||||||
|
|
||||||
<li><a href="stateful-goroutines">Управление состоянием горутин (Stateful Goroutines)</a></li>
|
|
||||||
|
|
||||||
<li><a href="sorting">Сортировка (Sorting)</a></li>
|
|
||||||
|
|
||||||
<li><a href="sorting-by-functions">Сортировка через функции (Sorting by Functions)</a></li>
|
|
||||||
|
|
||||||
<li><a href="panic">Panic</a></li>
|
|
||||||
|
|
||||||
<li><a href="defer">Defer</a></li>
|
|
||||||
|
|
||||||
<li><a href="collection-functions">Функции коллекции (Collection Functions)</a></li>
|
|
||||||
|
|
||||||
<li><a href="string-functions">Строковые функции (String Functions)</a></li>
|
|
||||||
|
|
||||||
<li><a href="string-formatting">Форматирование строк (String Formatting)</a></li>
|
|
||||||
|
|
||||||
<li><a href="regular-expressions">Регулярные выражения (Regular Expressions)</a></li>
|
|
||||||
|
|
||||||
<li><a href="json">JSON</a></li>
|
|
||||||
|
|
||||||
<li><a href="xml">XML</a></li>
|
|
||||||
|
|
||||||
<li><a href="time">Время (Time)</a></li>
|
|
||||||
|
|
||||||
<li><a href="epoch">Epoch</a></li>
|
|
||||||
|
|
||||||
<li><a href="time-formatting-parsing">Форматирование времени (Time Formatting / Parsing)</a></li>
|
|
||||||
|
|
||||||
<li><a href="random-numbers">Случайные числа (Random Numbers)</a></li>
|
|
||||||
|
|
||||||
<li><a href="number-parsing">Парсинг чисел (Number Parsing)</a></li>
|
|
||||||
|
|
||||||
<li><a href="url">Парсинг URL (URL Parsing)</a></li>
|
|
||||||
|
|
||||||
<li><a href="sha1">Хеш SHA1 (SHA1 Hashes)</a></li>
|
|
||||||
|
|
||||||
<li><a href="base64">Кодирование Base64 (Base64 Encoding)</a></li>
|
|
||||||
|
|
||||||
<li><a href="reading-files">Чтение файлов (Reading Files)</a></li>
|
|
||||||
|
|
||||||
<li><a href="writing-files">Запись файлов (Writing Files)</a></li>
|
|
||||||
|
|
||||||
<li><a href="line-filters">Строковые фильтры (Line Filters)</a></li>
|
|
||||||
|
|
||||||
<li><a href="file-paths">Пути к файлам (File Paths)</a></li>
|
|
||||||
|
|
||||||
<li><a href="directories">Директории (Directories)</a></li>
|
|
||||||
|
|
||||||
<li><a href="temporary-files-and-directories">Временные файлы и директории (Temporary Files and Directories)</a></li>
|
|
||||||
|
|
||||||
<li><a href="testing">Тестирование (Testing)</a></li>
|
|
||||||
|
|
||||||
<li><a href="command-line-arguments">Аргументы командной строки (Command-Line Arguments)</a></li>
|
|
||||||
|
|
||||||
<li><a href="command-line-flags">Флаги командной строки (Command-Line Flags)</a></li>
|
|
||||||
|
|
||||||
<li><a href="command-line-subcommands">Подкоманды командной строки (Command-Line Subcommands)</a></li>
|
|
||||||
|
|
||||||
<li><a href="environment-variables">Переменные среды (Environment Variables)</a></li>
|
|
||||||
|
|
||||||
<li><a href="http">HTTP клиенты (HTTP Clients)</a></li>
|
|
||||||
|
|
||||||
<li><a href="http">HTTP серверы (HTTP Servers)</a></li>
|
|
||||||
|
|
||||||
<li><a href="spawning-processes">Порождающие процессы (Spawning Processes)</a></li>
|
|
||||||
|
|
||||||
<li><a href="execing-processes">Исполняющие процессы (Exec'ing Processes)</a></li>
|
|
||||||
|
|
||||||
<li><a href="signals">Сигналы (Signals)</a></li>
|
|
||||||
|
|
||||||
<li><a href="exit">Выход (Exit)</a></li>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
<br/>
|
|
||||||
переведено Nick S. | <a href="https://github.com/badkaktus/gobyexample">исходники</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/interfaces
generated
41
public/interfaces
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Интерфейсы (Interfaces)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'methods';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'errors';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="interfaces">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Интерфейсы (Interfaces)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="errors">Ошибки (Errors)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/interfaces">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
424
public/json
generated
424
public/json
generated
@ -1,424 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: JSON</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'regular-expressions';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'xml';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="json">
|
|
||||||
<h2><a href="./">Go в примерах</a>: JSON</h2>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Go предлагает встроенную поддержку кодирования и
|
|
||||||
декодирования JSON, в том числе встроенных и
|
|
||||||
пользовательских типов данных.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty leading">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
<a href="http://play.golang.org/p/Lky4Hyyl2-t" target="_blank"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
|
|
||||||
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kn">import</span> <span class="p">(</span>
|
|
||||||
<span class="s">"encoding/json"</span>
|
|
||||||
<span class="s">"fmt"</span>
|
|
||||||
<span class="s">"os"</span>
|
|
||||||
<span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Мы будем использовать эти две структуры, для демонстрации
|
|
||||||
кодирования и декодирования.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">type</span> <span class="nx">response1</span> <span class="kd">struct</span> <span class="p">{</span>
|
|
||||||
<span class="nx">Page</span> <span class="kt">int</span>
|
|
||||||
<span class="nx">Fruits</span> <span class="p">[]</span><span class="kt">string</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Только экспортируемые поля могут быть кодированы и
|
|
||||||
декодированы в JSON. Поля должны начинаться с
|
|
||||||
заглавной буквы.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">type</span> <span class="nx">response2</span> <span class="kd">struct</span> <span class="p">{</span>
|
|
||||||
<span class="nx">Page</span> <span class="kt">int</span> <span class="s">`json:"page"`</span>
|
|
||||||
<span class="nx">Fruits</span> <span class="p">[]</span><span class="kt">string</span> <span class="s">`json:"fruits"`</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Для начала мы рассмотрим кодирование данных в
|
|
||||||
JSON строку. Вот несколько примеров для простых
|
|
||||||
типов данных.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">bolB</span><span class="p">,</span> <span class="nx">_</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Marshal</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nb">string</span><span class="p">(</span><span class="nx">bolB</span><span class="p">))</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">intB</span><span class="p">,</span> <span class="nx">_</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Marshal</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nb">string</span><span class="p">(</span><span class="nx">intB</span><span class="p">))</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">fltB</span><span class="p">,</span> <span class="nx">_</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Marshal</span><span class="p">(</span><span class="mf">2.34</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nb">string</span><span class="p">(</span><span class="nx">fltB</span><span class="p">))</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">strB</span><span class="p">,</span> <span class="nx">_</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Marshal</span><span class="p">(</span><span class="s">"gopher"</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nb">string</span><span class="p">(</span><span class="nx">strB</span><span class="p">))</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>А вот примеры для срезов и карт, которые кодируются
|
|
||||||
в JSON массивы и объекты, как мы и ожидаем.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">slcD</span> <span class="o">:=</span> <span class="p">[]</span><span class="kt">string</span><span class="p">{</span><span class="s">"apple"</span><span class="p">,</span> <span class="s">"peach"</span><span class="p">,</span> <span class="s">"pear"</span><span class="p">}</span>
|
|
||||||
<span class="nx">slcB</span><span class="p">,</span> <span class="nx">_</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Marshal</span><span class="p">(</span><span class="nx">slcD</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nb">string</span><span class="p">(</span><span class="nx">slcB</span><span class="p">))</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">mapD</span> <span class="o">:=</span> <span class="kd">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="kt">int</span><span class="p">{</span><span class="s">"apple"</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="s">"lettuce"</span><span class="p">:</span> <span class="mi">7</span><span class="p">}</span>
|
|
||||||
<span class="nx">mapB</span><span class="p">,</span> <span class="nx">_</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Marshal</span><span class="p">(</span><span class="nx">mapD</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nb">string</span><span class="p">(</span><span class="nx">mapB</span><span class="p">))</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Пакет JSON может автоматически кодировать ваши
|
|
||||||
пользовательские типы данных. Он будет включать
|
|
||||||
только экспортируемые поля в закодированный
|
|
||||||
вывод и по умолчанию будет использовать эти
|
|
||||||
имена в качестве ключей JSON.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">res1D</span> <span class="o">:=</span> <span class="o">&</span><span class="nx">response1</span><span class="p">{</span>
|
|
||||||
<span class="nx">Page</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
|
|
||||||
<span class="nx">Fruits</span><span class="p">:</span> <span class="p">[]</span><span class="kt">string</span><span class="p">{</span><span class="s">"apple"</span><span class="p">,</span> <span class="s">"peach"</span><span class="p">,</span> <span class="s">"pear"</span><span class="p">}}</span>
|
|
||||||
<span class="nx">res1B</span><span class="p">,</span> <span class="nx">_</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Marshal</span><span class="p">(</span><span class="nx">res1D</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nb">string</span><span class="p">(</span><span class="nx">res1B</span><span class="p">))</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Вы можете использовать теги в объявлениях
|
|
||||||
структурных полей для настройки кодированных имен
|
|
||||||
ключей JSON. Проверьте определение <code>response2</code>
|
|
||||||
выше, чтобы увидеть пример таких тегов.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">res2D</span> <span class="o">:=</span> <span class="o">&</span><span class="nx">response2</span><span class="p">{</span>
|
|
||||||
<span class="nx">Page</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
|
|
||||||
<span class="nx">Fruits</span><span class="p">:</span> <span class="p">[]</span><span class="kt">string</span><span class="p">{</span><span class="s">"apple"</span><span class="p">,</span> <span class="s">"peach"</span><span class="p">,</span> <span class="s">"pear"</span><span class="p">}}</span>
|
|
||||||
<span class="nx">res2B</span><span class="p">,</span> <span class="nx">_</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Marshal</span><span class="p">(</span><span class="nx">res2D</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nb">string</span><span class="p">(</span><span class="nx">res2B</span><span class="p">))</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Теперь давайте рассмотрим декодирование данных
|
|
||||||
JSON в значения Go. Вот пример для общей
|
|
||||||
структуры данных.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">byt</span> <span class="o">:=</span> <span class="p">[]</span><span class="nb">byte</span><span class="p">(</span><span class="s">`{"num":6.13,"strs":["a","b"]}`</span><span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Нам нужно предоставить переменную, в которую пакет
|
|
||||||
JSON может поместить декодированные данные.
|
|
||||||
`map[string]interface{} будет содержать карту
|
|
||||||
строк для произвольных типов данных.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="kd">var</span> <span class="nx">dat</span> <span class="kd">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="kd">interface</span><span class="p">{}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Вот фактическое декодирование и проверка на наличие
|
|
||||||
ошибок.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="k">if</span> <span class="nx">err</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">Unmarshal</span><span class="p">(</span><span class="nx">byt</span><span class="p">,</span> <span class="o">&</span><span class="nx">dat</span><span class="p">);</span> <span class="nx">err</span> <span class="o">!=</span> <span class="kc">nil</span> <span class="p">{</span>
|
|
||||||
<span class="nb">panic</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">dat</span><span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Чтобы использовать значения в декодированной карте,
|
|
||||||
нам нужно преобразовать их в соответствующий тип.
|
|
||||||
Например, здесь мы конвертируем значение из <code>num</code>
|
|
||||||
в ожидаемый тип <code>float64</code>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">num</span> <span class="o">:=</span> <span class="nx">dat</span><span class="p">[</span><span class="s">"num"</span><span class="p">].(</span><span class="kt">float64</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">num</span><span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Доступ к вложенным данным требует ряда преобразований.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">strs</span> <span class="o">:=</span> <span class="nx">dat</span><span class="p">[</span><span class="s">"strs"</span><span class="p">].([]</span><span class="kd">interface</span><span class="p">{})</span>
|
|
||||||
<span class="nx">str1</span> <span class="o">:=</span> <span class="nx">strs</span><span class="p">[</span><span class="mi">0</span><span class="p">].(</span><span class="kt">string</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">str1</span><span class="p">)</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Мы также можем декодировать JSON в пользовательские
|
|
||||||
типы данных. Это дает преимущество добавления
|
|
||||||
дополнительной безопасности типов в наши программы
|
|
||||||
и устранения необходимости в определении типрв
|
|
||||||
при доступе к декодированным данным.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">str</span> <span class="o">:=</span> <span class="s">`{"page": 1, "fruits": ["apple", "peach"]}`</span>
|
|
||||||
<span class="nx">res</span> <span class="o">:=</span> <span class="nx">response2</span><span class="p">{}</span>
|
|
||||||
<span class="nx">json</span><span class="p">.</span><span class="nx">Unmarshal</span><span class="p">([]</span><span class="nb">byte</span><span class="p">(</span><span class="nx">str</span><span class="p">),</span> <span class="o">&</span><span class="nx">res</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">res</span><span class="p">)</span>
|
|
||||||
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="nx">res</span><span class="p">.</span><span class="nx">Fruits</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>В приведенных выше примерах мы всегда использовали
|
|
||||||
байты и строки в качестве промежуточных звеньев между
|
|
||||||
данными и представлением JSON на стандартном выходе.
|
|
||||||
Мы также можем транслировать JSON-кодировки напрямую
|
|
||||||
в <code>os.Writer</code>, такие как <code>os.Stdout</code> или даже HTTP-тела
|
|
||||||
ответа.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code">
|
|
||||||
|
|
||||||
<div class="highlight"><pre> <span class="nx">enc</span> <span class="o">:=</span> <span class="nx">json</span><span class="p">.</span><span class="nx">NewEncoder</span><span class="p">(</span><span class="nx">os</span><span class="p">.</span><span class="nx">Stdout</span><span class="p">)</span>
|
|
||||||
<span class="nx">d</span> <span class="o">:=</span> <span class="kd">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="kt">int</span><span class="p">{</span><span class="s">"apple"</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="s">"lettuce"</span><span class="p">:</span> <span class="mi">7</span><span class="p">}</span>
|
|
||||||
<span class="nx">enc</span><span class="p">.</span><span class="nx">Encode</span><span class="p">(</span><span class="nx">d</span><span class="p">)</span>
|
|
||||||
<span class="p">}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code leading">
|
|
||||||
|
|
||||||
<div class="highlight"><pre><span class="gp">$</span> go run json.go
|
|
||||||
<span class="go">true</span>
|
|
||||||
<span class="go">1</span>
|
|
||||||
<span class="go">2.34</span>
|
|
||||||
<span class="go">"gopher"</span>
|
|
||||||
<span class="go">["apple","peach","pear"]</span>
|
|
||||||
<span class="go">{"apple":5,"lettuce":7}</span>
|
|
||||||
<span class="go">{"Page":1,"Fruits":["apple","peach","pear"]}</span>
|
|
||||||
<span class="go">{"page":1,"fruits":["apple","peach","pear"]}</span>
|
|
||||||
<span class="go">map[num:6.13 strs:[a b]]</span>
|
|
||||||
<span class="go">6.13</span>
|
|
||||||
<span class="go">a</span>
|
|
||||||
<span class="go">{1 [apple peach]}</span>
|
|
||||||
<span class="go">apple</span>
|
|
||||||
<span class="go">{"apple":5,"lettuce":7}</span>
|
|
||||||
</pre></div>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>Мы рассмотрели основы JSON в Go, но ознакомьтесь с
|
|
||||||
публикацией в блоге <a href="http://blog.golang.org/2011/01/json-and-go.html">JSON and Go</a>
|
|
||||||
и документацией по <a href="http://golang.org/pkg/encoding/json/">пакету JSON</a>.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="xml">XML</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/json">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import (\u000A \"encoding/json\"\u000A \"fmt\"\u000A \"os\"\u000A)\u000A');codeLines.push('type response1 struct {\u000A Page int\u000A Fruits []string\u000A}\u000A');codeLines.push('type response2 struct {\u000A Page int `json:\"page\"`\u000A Fruits []string `json:\"fruits\"`\u000A}\u000A');codeLines.push('func main() {\u000A');codeLines.push(' bolB, _ := json.Marshal(true)\u000A fmt.Println(string(bolB))\u000A');codeLines.push(' intB, _ := json.Marshal(1)\u000A fmt.Println(string(intB))\u000A');codeLines.push(' fltB, _ := json.Marshal(2.34)\u000A fmt.Println(string(fltB))\u000A');codeLines.push(' strB, _ := json.Marshal(\"gopher\")\u000A fmt.Println(string(strB))\u000A');codeLines.push(' slcD := []string{\"apple\", \"peach\", \"pear\"}\u000A slcB, _ := json.Marshal(slcD)\u000A fmt.Println(string(slcB))\u000A');codeLines.push(' mapD := map[string]int{\"apple\": 5, \"lettuce\": 7}\u000A mapB, _ := json.Marshal(mapD)\u000A fmt.Println(string(mapB))\u000A');codeLines.push(' res1D := &response1{\u000A Page: 1,\u000A Fruits: []string{\"apple\", \"peach\", \"pear\"}}\u000A res1B, _ := json.Marshal(res1D)\u000A fmt.Println(string(res1B))\u000A');codeLines.push(' res2D := &response2{\u000A Page: 1,\u000A Fruits: []string{\"apple\", \"peach\", \"pear\"}}\u000A res2B, _ := json.Marshal(res2D)\u000A fmt.Println(string(res2B))\u000A');codeLines.push(' byt := []byte(`{\"num\":6.13,\"strs\":[\"a\",\"b\"]}`)\u000A');codeLines.push(' var dat map[string]interface{}\u000A');codeLines.push(' if err := json.Unmarshal(byt, &dat); err != nil {\u000A panic(err)\u000A }\u000A fmt.Println(dat)\u000A');codeLines.push(' num := dat[\"num\"].(float64)\u000A fmt.Println(num)\u000A');codeLines.push(' strs := dat[\"strs\"].([]interface{})\u000A str1 := strs[0].(string)\u000A fmt.Println(str1)\u000A');codeLines.push(' str := `{\"page\": 1, \"fruits\": [\"apple\", \"peach\"]}`\u000A res := response2{}\u000A json.Unmarshal([]byte(str), &res)\u000A fmt.Println(res)\u000A fmt.Println(res.Fruits[0])\u000A');codeLines.push(' enc := json.NewEncoder(os.Stdout)\u000A d := map[string]int{\"apple\": 5, \"lettuce\": 7}\u000A enc.Encode(d)\u000A}\u000A');codeLines.push('');codeLines.push('');
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
41
public/line-filters
generated
41
public/line-filters
generated
@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Go в примерах: Строковые фильтры (Line Filters)</title>
|
|
||||||
<link rel=stylesheet href="site.css">
|
|
||||||
</head>
|
|
||||||
<script>
|
|
||||||
onkeydown = (e) => {
|
|
||||||
|
|
||||||
if (e.key == "ArrowLeft") {
|
|
||||||
window.location.href = 'writing-files';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (e.key == "ArrowRight") {
|
|
||||||
window.location.href = 'file-paths';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<body>
|
|
||||||
<div class="example" id="line-filters">
|
|
||||||
<h2><a href="./">Go в примерах</a>: Строковые фильтры (Line Filters)</h2>
|
|
||||||
|
|
||||||
|
|
||||||
<p class="next">
|
|
||||||
Следующий пример: <a href="file-paths">Пути к файлам (File Paths)</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="footer">
|
|
||||||
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/line-filters">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
var codeLines = [];
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script src="site.js" async></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user