-
Notifications
You must be signed in to change notification settings - Fork 0
/
go1.7.html
1281 lines (1103 loc) · 42.7 KB
/
go1.7.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!--{
"Title": "Go 1.7 Release Notes",
"Path": "/doc/go1.7",
"Template": true
}-->
<!--
for acme:
Edit .,s;^PKG:([a-z][A-Za-z0-9_/]+);<a href="/pkg/\1/"><code>\1</code></a>;g
Edit .,s;^([a-z][A-Za-z0-9_/]+)\.([A-Z][A-Za-z0-9_]+\.)?([A-Z][A-Za-z0-9_]+)([ .',)]|$);<a href="/pkg/\1/#\2\3"><code>\3</code></a>\4;g
Edit .,s;^FULL:([a-z][A-Za-z0-9_/]+)\.([A-Z][A-Za-z0-9_]+\.)?([A-Z][A-Za-z0-9_]+)([ .',)]|$);<a href="/pkg/\1/#\2\3"><code>\1.\2\3</code></a>\4;g
Edit .,s;^DPKG:([a-z][A-Za-z0-9_/]+);<dl id="\1"><a href="/pkg/\1/">\1</a></dl>;g
rsc last updated through 6729576
-->
<!--
NOTE: In this document and others in this directory, the convention is to
set fixed-width phrases with non-fixed-width spaces, as in
<code>hello</code> <code>world</code>.
Do not send CLs removing the interior tags from such phrases.
-->
<style>
main ul li { margin: 0.5em 0; }
</style>
<h2 id="introduction">Introduction to Go 1.7</h2>
<p>
The latest Go release, version 1.7, arrives six months after 1.6.
Most of its changes are in the implementation of the toolchain, runtime, and libraries.
There is one minor change to the language specification.
As always, the release maintains the Go 1 <a href="/doc/go1compat.html">promise of compatibility</a>.
We expect almost all Go programs to continue to compile and run as before.
</p>
<p>
The release <a href="#ports">adds a port to IBM LinuxOne</a>;
<a href="#compiler">updates the x86-64 compiler back end</a> to generate more efficient code;
includes the <a href="#context">context package</a>, promoted from the
<a href="https://golang.org/x/net/context">x/net subrepository</a>
and now used in the standard library;
and <a href="#testing">adds support in the testing package</a> for
creating hierarchies of tests and benchmarks.
The release also <a href="#cmd_go">finalizes the vendoring support</a>
started in Go 1.5, making it a standard feature.
</p>
<h2 id="language">Changes to the language</h2>
<p>
There is one tiny language change in this release.
The section on <a href="/ref/spec#Terminating_statements">terminating statements</a>
clarifies that to determine whether a statement list ends in a terminating statement,
the “final non-empty statement” is considered the end,
matching the existing behavior of the gc and gccgo compiler toolchains.
In earlier releases the definition referred only to the “final statement,”
leaving the effect of trailing empty statements at the least unclear.
The <a href="/pkg/go/types/"><code>go/types</code></a>
package has been updated to match the gc and gccgo compiler toolchains
in this respect.
This change has no effect on the correctness of existing programs.
</p>
<h2 id="ports">Ports</h2>
<p>
Go 1.7 adds support for macOS 10.12 Sierra.
Binaries built with versions of Go before 1.7 will not work
correctly on Sierra.
</p>
<p>
Go 1.7 adds an experimental port to <a href="https://en.wikipedia.org/wiki/Linux_on_z_Systems">Linux on z Systems</a> (<code>linux/s390x</code>)
and the beginning of a port to Plan 9 on ARM (<code>plan9/arm</code>).
</p>
<p>
The experimental ports to Linux on 64-bit MIPS (<code>linux/mips64</code> and <code>linux/mips64le</code>)
added in Go 1.6 now have full support for cgo and external linking.
</p>
<p>
The experimental port to Linux on little-endian 64-bit PowerPC (<code>linux/ppc64le</code>)
now requires the POWER8 architecture or later.
Big-endian 64-bit PowerPC (<code>linux/ppc64</code>) only requires the
POWER5 architecture.
</p>
<p>
The OpenBSD port now requires OpenBSD 5.6 or later, for access to the <a href="https://man.openbsd.org/getentropy.2"><i>getentropy</i>(2)</a> system call.
</p>
<h3 id="known_issues">Known Issues</h3>
<p>
There are some instabilities on FreeBSD that are known but not understood.
These can lead to program crashes in rare cases.
See <a href="https://golang.org/issue/16136">issue 16136</a>,
<a href="https://golang.org/issue/15658">issue 15658</a>,
and <a href="https://golang.org/issue/16396">issue 16396</a>.
Any help in solving these FreeBSD-specific issues would be appreciated.
</p>
<h2 id="tools">Tools</h2>
<h3 id="cmd_asm">Assembler</h3>
<p>
For 64-bit ARM systems, the vector register names have been
corrected to <code>V0</code> through <code>V31</code>;
previous releases incorrectly referred to them as <code>V32</code> through <code>V63</code>.
</p>
<p>
For 64-bit x86 systems, the following instructions have been added:
<code>PCMPESTRI</code>,
<code>RORXL</code>,
<code>RORXQ</code>,
<code>VINSERTI128</code>,
<code>VPADDD</code>,
<code>VPADDQ</code>,
<code>VPALIGNR</code>,
<code>VPBLENDD</code>,
<code>VPERM2F128</code>,
<code>VPERM2I128</code>,
<code>VPOR</code>,
<code>VPSHUFB</code>,
<code>VPSHUFD</code>,
<code>VPSLLD</code>,
<code>VPSLLDQ</code>,
<code>VPSLLQ</code>,
<code>VPSRLD</code>,
<code>VPSRLDQ</code>,
and
<code>VPSRLQ</code>.
</p>
<h3 id="compiler">Compiler Toolchain</h3>
<p>
This release includes a new code generation back end for 64-bit x86 systems,
following a <a href="https://golang.org/s/go17ssa">proposal from 2015</a>
that has been under development since then.
The new back end, based on
<a href="https://en.wikipedia.org/wiki/Static_single_assignment_form">SSA</a>,
generates more compact, more efficient code
and provides a better platform for optimizations
such as bounds check elimination.
The new back end reduces the CPU time required by
<a href="https://golang.org/test/bench/go1/">our benchmark programs</a> by 5-35%.
</p>
<p>
For this release, the new back end can be disabled by passing
<code>-ssa=0</code> to the compiler.
If you find that your program compiles or runs successfully
only with the new back end disabled, please
<a href="https://golang.org/issue/new">file a bug report</a>.
</p>
<p>
The format of exported metadata written by the compiler in package archives has changed:
the old textual format has been replaced by a more compact binary format.
This results in somewhat smaller package archives and fixes a few
long-standing corner case bugs.
</p>
<p>
For this release, the new export format can be disabled by passing
<code>-newexport=0</code> to the compiler.
If you find that your program compiles or runs successfully
only with the new export format disabled, please
<a href="https://golang.org/issue/new">file a bug report</a>.
</p>
<p>
The linker's <code>-X</code> option no longer supports the unusual two-argument form
<code>-X</code> <code>name</code> <code>value</code>,
as <a href="/doc/go1.6#compiler">announced</a> in the Go 1.6 release
and in warnings printed by the linker.
Use <code>-X</code> <code>name=value</code> instead.
</p>
<p>
The compiler and linker have been optimized and run significantly faster in this release than in Go 1.6,
although they are still slower than we would like and will continue to be optimized in future releases.
</p>
<p>
Due to changes across the compiler toolchain and standard library,
binaries built with this release should typically be smaller than binaries
built with Go 1.6,
sometimes by as much as 20-30%.
</p>
<p>
On x86-64 systems, Go programs now maintain stack frame pointers
as expected by profiling tools like Linux's perf and Intel's VTune,
making it easier to analyze and optimize Go programs using these tools.
The frame pointer maintenance has a small run-time overhead that varies
but averages around 2%. We hope to reduce this cost in future releases.
To build a toolchain that does not use frame pointers, set
<code>GOEXPERIMENT=noframepointer</code> when running
<code>make.bash</code>, <code>make.bat</code>, or <code>make.rc</code>.
</p>
<h3 id="cmd_cgo">Cgo</h3>
<p>
Packages using <a href="/cmd/cgo/">cgo</a> may now include
Fortran source files (in addition to C, C++, Objective C, and SWIG),
although the Go bindings must still use C language APIs.
</p>
<p>
Go bindings may now use a new helper function <code>C.CBytes</code>.
In contrast to <code>C.CString</code>, which takes a Go <code>string</code>
and returns a <code>*C.byte</code> (a C <code>char*</code>),
<code>C.CBytes</code> takes a Go <code>[]byte</code>
and returns an <code>unsafe.Pointer</code> (a C <code>void*</code>).
</p>
<p>
Packages and binaries built using <code>cgo</code> have in past releases
produced different output on each build,
due to the embedding of temporary directory names.
When using this release with
new enough versions of GCC or Clang
(those that support the <code>-fdebug-prefix-map</code> option),
those builds should finally be deterministic.
</p>
<h3 id="gccgo">Gccgo</h3>
<p>
Due to the alignment of Go's semiannual release schedule with GCC's annual release schedule,
GCC release 6 contains the Go 1.6.1 version of gccgo.
The next release, GCC 7, will likely have the Go 1.8 version of gccgo.
</p>
<h3 id="cmd_go">Go command</h3>
<p>
The <a href="/cmd/go/"><code>go</code></a> command's basic operation
is unchanged, but there are a number of changes worth noting.
</p>
<p>
This release removes support for the <code>GO15VENDOREXPERIMENT</code> environment variable,
as <a href="/doc/go1.6#go_command">announced</a> in the Go 1.6 release.
<a href="https://golang.org/s/go15vendor">Vendoring support</a>
is now a standard feature of the <code>go</code> command and toolchain.
</p>
<p>
The <code>Package</code> data structure made available to
“<code>go</code> <code>list</code>” now includes a
<code>StaleReason</code> field explaining why a particular package
is or is not considered stale (in need of rebuilding).
This field is available to the <code>-f</code> or <code>-json</code>
options and is useful for understanding why a target is being rebuilt.
</p>
<p>
The “<code>go</code> <code>get</code>” command now supports
import paths referring to <code>git.openstack.org</code>.
</p>
<p>
This release adds experimental, minimal support for building programs using
<a href="/pkg/go/build#hdr-Binary_Only_Packages">binary-only packages</a>,
packages distributed in binary form
without the corresponding source code.
This feature is needed in some commercial settings
but is not intended to be fully integrated into the rest of the toolchain.
For example, tools that assume access to complete source code
will not work with such packages, and there are no plans to support
such packages in the “<code>go</code> <code>get</code>” command.
</p>
<h3 id="cmd_doc">Go doc</h3>
<p>
The “<code>go</code> <code>doc</code>” command
now groups constructors with the type they construct,
following <a href="/cmd/godoc/"><code>godoc</code></a>.
</p>
<h3 id="cmd_vet">Go vet</h3>
<p>
The “<code>go</code> <code>vet</code>” command
has more accurate analysis in its <code>-copylock</code> and <code>-printf</code> checks,
and a new <code>-tests</code> check that checks the name and signature of likely test functions.
To avoid confusion with the new <code>-tests</code> check, the old, unadvertised
<code>-test</code> option has been removed; it was equivalent to <code>-all</code> <code>-shadow</code>.
</p>
<p id="vet_lostcancel">
The <code>vet</code> command also has a new check,
<code>-lostcancel</code>, which detects failure to call the
cancelation function returned by the <code>WithCancel</code>,
<code>WithTimeout</code>, and <code>WithDeadline</code> functions in
Go 1.7's new <code>context</code> package (see <a
href='#context'>below</a>).
Failure to call the function prevents the new <code>Context</code>
from being reclaimed until its parent is cancelled.
(The background context is never cancelled.)
</p>
<h3 id="cmd_dist">Go tool dist</h3>
<p>
The new subcommand “<code>go</code> <code>tool</code> <code>dist</code> <code>list</code>”
prints all supported operating system/architecture pairs.
</p>
<h3 id="cmd_trace">Go tool trace</h3>
<p>
The “<code>go</code> <code>tool</code> <code>trace</code>” command,
<a href="/doc/go1.5#trace_command">introduced in Go 1.5</a>,
has been refined in various ways.
</p>
<p>
First, collecting traces is significantly more efficient than in past releases.
In this release, the typical execution-time overhead of collecting a trace is about 25%;
in past releases it was at least 400%.
Second, trace files now include file and line number information,
making them more self-contained and making the
original executable optional when running the trace tool.
Third, the trace tool now breaks up large traces to avoid limits
in the browser-based viewer.
</p>
<p>
Although the trace file format has changed in this release,
the Go 1.7 tools can still read traces from earlier releases.
</p>
<h2 id="performance">Performance</h2>
<p>
As always, the changes are so general and varied that precise statements
about performance are difficult to make.
Most programs should run a bit faster,
due to speedups in the garbage collector and
optimizations in the core library.
On x86-64 systems, many programs will run significantly faster,
due to improvements in generated code brought by the
new compiler back end.
As noted above, in our own benchmarks,
the code generation changes alone typically reduce program CPU time by 5-35%.
</p>
<p>
<!-- git log -''-grep '-[0-9][0-9]\.[0-9][0-9]%' go1.6.. -->
There have been significant optimizations bringing more than 10% improvements
to implementations in the
<a href="/pkg/crypto/sha1/"><code>crypto/sha1</code></a>,
<a href="/pkg/crypto/sha256/"><code>crypto/sha256</code></a>,
<a href="/pkg/encoding/binary/"><code>encoding/binary</code></a>,
<a href="/pkg/fmt/"><code>fmt</code></a>,
<a href="/pkg/hash/adler32/"><code>hash/adler32</code></a>,
<a href="/pkg/hash/crc32/"><code>hash/crc32</code></a>,
<a href="/pkg/hash/crc64/"><code>hash/crc64</code></a>,
<a href="/pkg/image/color/"><code>image/color</code></a>,
<a href="/pkg/math/big/"><code>math/big</code></a>,
<a href="/pkg/strconv/"><code>strconv</code></a>,
<a href="/pkg/strings/"><code>strings</code></a>,
<a href="/pkg/unicode/"><code>unicode</code></a>,
and
<a href="/pkg/unicode/utf16/"><code>unicode/utf16</code></a>
packages.
</p>
<p>
Garbage collection pauses should be significantly shorter than they
were in Go 1.6 for programs with large numbers of idle goroutines,
substantial stack size fluctuation, or large package-level variables.
</p>
<h2 id="library">Core library</h2>
<h3 id="context">Context</h3>
<p>
Go 1.7 moves the <code>golang.org/x/net/context</code> package
into the standard library as <a href="/pkg/context/"><code>context</code></a>.
This allows the use of contexts for cancelation, timeouts, and passing
request-scoped data in other standard library packages,
including
<a href="#net">net</a>,
<a href="#net_http">net/http</a>,
and
<a href="#os_exec">os/exec</a>,
as noted below.
</p>
<p>
For more information about contexts, see the
<a href="/pkg/context/">package documentation</a>
and the Go blog post
“<a href="https://blog.golang.org/context">Go Concurrent Patterns: Context</a>.”
</p>
<h3 id="httptrace">HTTP Tracing</h3>
<p>
Go 1.7 introduces <a href="/pkg/net/http/httptrace/"><code>net/http/httptrace</code></a>,
a package that provides mechanisms for tracing events within HTTP requests.
</p>
<h3 id="testing">Testing</h3>
<p>
The <code>testing</code> package now supports the definition
of tests with subtests and benchmarks with sub-benchmarks.
This support makes it easy to write table-driven benchmarks
and to create hierarchical tests.
It also provides a way to share common setup and tear-down code.
See the <a href="/pkg/testing/#hdr-Subtests_and_Sub_benchmarks">package documentation</a> for details.
</p>
<h3 id="runtime">Runtime</h3>
<p>
All panics started by the runtime now use panic values
that implement both the
builtin <a href="/ref/spec#Errors"><code>error</code></a>,
and
<a href="/pkg/runtime/#Error"><code>runtime.Error</code></a>,
as
<a href="/ref/spec#Run_time_panics">required by the language specification</a>.
</p>
<p>
During panics, if a signal's name is known, it will be printed in the stack trace.
Otherwise, the signal's number will be used, as it was before Go1.7.
</p>
<p>
The new function
<a href="/pkg/runtime/#KeepAlive"><code>KeepAlive</code></a>
provides an explicit mechanism for declaring
that an allocated object must be considered reachable
at a particular point in a program,
typically to delay the execution of an associated finalizer.
</p>
<p>
The new function
<a href="/pkg/runtime/#CallersFrames"><code>CallersFrames</code></a>
translates a PC slice obtained from
<a href="/pkg/runtime/#Callers"><code>Callers</code></a>
into a sequence of frames corresponding to the call stack.
This new API should be preferred instead of direct use of
<a href="/pkg/runtime/#FuncForPC"><code>FuncForPC</code></a>,
because the frame sequence can more accurately describe
call stacks with inlined function calls.
</p>
<p>
The new function
<a href="/pkg/runtime/#SetCgoTraceback"><code>SetCgoTraceback</code></a>
facilitates tighter integration between Go and C code executing
in the same process called using cgo.
</p>
<p>
On 32-bit systems, the runtime can now use memory allocated
by the operating system anywhere in the address space,
eliminating the
“memory allocated by OS not in usable range” failure
common in some environments.
</p>
<p>
The runtime can now return unused memory to the operating system on
all architectures.
In Go 1.6 and earlier, the runtime could not
release memory on ARM64, 64-bit PowerPC, or MIPS.
</p>
<p>
On Windows, Go programs in Go 1.5 and earlier forced
the global Windows timer resolution to 1ms at startup
by calling <code>timeBeginPeriod(1)</code>.
Changing the global timer resolution caused problems on some systems,
and testing suggested that the call was not needed for good scheduler performance,
so Go 1.6 removed the call.
Go 1.7 brings the call back: under some workloads the call
is still needed for good scheduler performance.
</p>
<h3 id="minor_library_changes">Minor changes to the library</h3>
<p>
As always, there are various minor changes and updates to the library,
made with the Go 1 <a href="/doc/go1compat">promise of compatibility</a>
in mind.
</p>
<dl id="bufio"><dt><a href="/pkg/bufio/">bufio</a></dt>
<dd>
<p>
In previous releases of Go, if
<a href="/pkg/bufio/#Reader"><code>Reader</code></a>'s
<a href="/pkg/bufio/#Reader.Peek"><code>Peek</code></a> method
were asked for more bytes than fit in the underlying buffer,
it would return an empty slice and the error <code>ErrBufferFull</code>.
Now it returns the entire underlying buffer, still accompanied by the error <code>ErrBufferFull</code>.
</p>
</dd>
</dl>
<dl id="bytes"><dt><a href="/pkg/bytes/">bytes</a></dt>
<dd>
<p>
The new functions
<a href="/pkg/bytes/#ContainsAny"><code>ContainsAny</code></a> and
<a href="/pkg/bytes/#ContainsRune"><code>ContainsRune</code></a>
have been added for symmetry with
the <a href="/pkg/strings/"><code>strings</code></a> package.
</p>
<p>
In previous releases of Go, if
<a href="/pkg/bytes/#Reader"><code>Reader</code></a>'s
<a href="/pkg/bytes/#Reader.Read"><code>Read</code></a> method
were asked for zero bytes with no data remaining, it would
return a count of 0 and no error.
Now it returns a count of 0 and the error
<a href="/pkg/io/#EOF"><code>io.EOF</code></a>.
</p>
<p>
The
<a href="/pkg/bytes/#Reader"><code>Reader</code></a> type has a new method
<a href="/pkg/bytes/#Reader.Reset"><code>Reset</code></a> to allow reuse of a <code>Reader</code>.
</p>
</dd>
</dl>
<dl id="compress_flate"><dt><a href="/pkg/compress/flate/">compress/flate</a></dt>
<dd>
<p>
There are many performance optimizations throughout the package.
Decompression speed is improved by about 10%,
while compression for <code>DefaultCompression</code> is twice as fast.
</p>
<p>
In addition to those general improvements,
the
<code>BestSpeed</code>
compressor has been replaced entirely and uses an
algorithm similar to <a href="https://github.com/google/snappy">Snappy</a>,
resulting in about a 2.5X speed increase,
although the output can be 5-10% larger than with the previous algorithm.
</p>
<p>
There is also a new compression level
<code>HuffmanOnly</code>
that applies Huffman but not Lempel-Ziv encoding.
<a href="https://blog.klauspost.com/constant-time-gzipzip-compression/">Forgoing Lempel-Ziv encoding</a> means that
<code>HuffmanOnly</code> runs about 3X faster than the new <code>BestSpeed</code>
but at the cost of producing compressed outputs that are 20-40% larger than those
generated by the new <code>BestSpeed</code>.
</p>
<p>
It is important to note that both
<code>BestSpeed</code> and <code>HuffmanOnly</code> produce a compressed output that is
<a href="https://tools.ietf.org/html/rfc1951">RFC 1951</a> compliant.
In other words, any valid DEFLATE decompressor will continue to be able to decompress these outputs.
</p>
<p>
Lastly, there is a minor change to the decompressor's implementation of
<a href="/pkg/io/#Reader"><code>io.Reader</code></a>. In previous versions,
the decompressor deferred reporting
<a href="/pkg/io/#EOF"><code>io.EOF</code></a> until exactly no more bytes could be read.
Now, it reports
<a href="/pkg/io/#EOF"><code>io.EOF</code></a> more eagerly when reading the last set of bytes.
</p>
</dd>
</dl>
<dl id="crypto_tls"><dt><a href="/pkg/crypto/tls/">crypto/tls</a></dt>
<dd>
<p>
The TLS implementation sends the first few data packets on each connection
using small record sizes, gradually increasing to the TLS maximum record size.
This heuristic reduces the amount of data that must be received before
the first packet can be decrypted, improving communication latency over
low-bandwidth networks.
Setting
<a href="/pkg/crypto/tls/#Config"><code>Config</code></a>'s
<code>DynamicRecordSizingDisabled</code> field to true
forces the behavior of Go 1.6 and earlier, where packets are
as large as possible from the start of the connection.
</p>
<p>
The TLS client now has optional, limited support for server-initiated renegotiation,
enabled by setting the
<a href="/pkg/crypto/tls/#Config"><code>Config</code></a>'s
<code>Renegotiation</code> field.
This is needed for connecting to many Microsoft Azure servers.
</p>
<p>
The errors returned by the package now consistently begin with a
<code>tls:</code> prefix.
In past releases, some errors used a <code>crypto/tls:</code> prefix,
some used a <code>tls:</code> prefix, and some had no prefix at all.
</p>
<p>
When generating self-signed certificates, the package no longer sets the
“Authority Key Identifier” field by default.
</p>
</dd>
</dl>
<dl id="crypto_x509"><dt><a href="/pkg/crypto/x509/">crypto/x509</a></dt>
<dd>
<p>
The new function
<a href="/pkg/crypto/x509/#SystemCertPool"><code>SystemCertPool</code></a>
provides access to the entire system certificate pool if available.
There is also a new associated error type
<a href="/pkg/crypto/x509/#SystemRootsError"><code>SystemRootsError</code></a>.
</p>
</dd>
</dl>
<dl id="debug_dwarf"><dt><a href="/pkg/debug/dwarf/">debug/dwarf</a></dt>
<dd>
<p>
The
<a href="/pkg/debug/dwarf/#Reader"><code>Reader</code></a> type's new
<a href="/pkg/debug/dwarf/#Reader.SeekPC"><code>SeekPC</code></a> method and the
<a href="/pkg/debug/dwarf/#Data"><code>Data</code></a> type's new
<a href="/pkg/debug/dwarf/#Ranges"><code>Ranges</code></a> method
help to find the compilation unit to pass to a
<a href="/pkg/debug/dwarf/#LineReader"><code>LineReader</code></a>
and to identify the specific function for a given program counter.
</p>
</dd>
</dl>
<dl id="debug_elf"><dt><a href="/pkg/debug/elf/">debug/elf</a></dt>
<dd>
<p>
The new
<a href="/pkg/debug/elf/#R_390"><code>R_390</code></a> relocation type
and its many predefined constants
support the S390 port.
</p>
</dd>
</dl>
<dl id="encoding_asn1"><dt><a href="/pkg/encoding/asn1/">encoding/asn1</a></dt>
<dd>
<p>
The ASN.1 decoder now rejects non-minimal integer encodings.
This may cause the package to reject some invalid but formerly accepted ASN.1 data.
</p>
</dd>
</dl>
<dl id="encoding_json"><dt><a href="/pkg/encoding/json/">encoding/json</a></dt>
<dd>
<p>
The
<a href="/pkg/encoding/json/#Encoder"><code>Encoder</code></a>'s new
<a href="/pkg/encoding/json/#Encoder.SetIndent"><code>SetIndent</code></a> method
sets the indentation parameters for JSON encoding,
like in the top-level
<a href="/pkg/encoding/json/#Indent"><code>Indent</code></a> function.
</p>
<p>
The
<a href="/pkg/encoding/json/#Encoder"><code>Encoder</code></a>'s new
<a href="/pkg/encoding/json/#Encoder.SetEscapeHTML"><code>SetEscapeHTML</code></a> method
controls whether the
<code>&</code>, <code><</code>, and <code>></code>
characters in quoted strings should be escaped as
<code>\u0026</code>, <code>\u003c</code>, and <code>\u003e</code>,
respectively.
As in previous releases, the encoder defaults to applying this escaping,
to avoid certain problems that can arise when embedding JSON in HTML.
</p>
<p>
In earlier versions of Go, this package only supported encoding and decoding
maps using keys with string types.
Go 1.7 adds support for maps using keys with integer types:
the encoding uses a quoted decimal representation as the JSON key.
Go 1.7 also adds support for encoding maps using non-string keys that implement
the <code>MarshalText</code>
(see
<a href="/pkg/encoding/#TextMarshaler"><code>encoding.TextMarshaler</code></a>)
method,
as well as support for decoding maps using non-string keys that implement
the <code>UnmarshalText</code>
(see
<a href="/pkg/encoding/#TextUnmarshaler"><code>encoding.TextUnmarshaler</code></a>)
method.
These methods are ignored for keys with string types in order to preserve
the encoding and decoding used in earlier versions of Go.
</p>
<p>
When encoding a slice of typed bytes,
<a href="/pkg/encoding/json/#Marshal"><code>Marshal</code></a>
now generates an array of elements encoded using
that byte type's
<code>MarshalJSON</code>
or
<code>MarshalText</code>
method if present,
only falling back to the default base64-encoded string data if neither method is available.
Earlier versions of Go accept both the original base64-encoded string encoding
and the array encoding (assuming the byte type also implements
<code>UnmarshalJSON</code>
or
<code>UnmarshalText</code>
as appropriate),
so this change should be semantically backwards compatible with earlier versions of Go,
even though it does change the chosen encoding.
</p>
</dd>
</dl>
<dl id="go_build"><dt><a href="/pkg/go/build/">go/build</a></dt>
<dd>
<p>
To implement the go command's new support for binary-only packages
and for Fortran code in cgo-based packages,
the
<a href="/pkg/go/build/#Package"><code>Package</code></a> type
adds new fields <code>BinaryOnly</code>, <code>CgoFFLAGS</code>, and <code>FFiles</code>.
</p>
</dd>
</dl>
<dl id="go_doc"><dt><a href="/pkg/go/doc/">go/doc</a></dt>
<dd>
<p>
To support the corresponding change in <code>go</code> <code>test</code> described above,
<a href="/pkg/go/doc/#Example"><code>Example</code></a> struct adds a Unordered field
indicating whether the example may generate its output lines in any order.
</p>
</dd>
</dl>
<dl id="io"><dt><a href="/pkg/io/">io</a></dt>
<dd>
<p>
The package adds new constants
<code>SeekStart</code>, <code>SeekCurrent</code>, and <code>SeekEnd</code>,
for use with
<a href="/pkg/io/#Seeker"><code>Seeker</code></a>
implementations.
These constants are preferred over <code>os.SEEK_SET</code>, <code>os.SEEK_CUR</code>, and <code>os.SEEK_END</code>,
but the latter will be preserved for compatibility.
</p>
</dd>
</dl>
<dl id="math_big"><dt><a href="/pkg/math/big/">math/big</a></dt>
<dd>
<p>
The
<a href="/pkg/math/big/#Float"><code>Float</code></a> type adds
<a href="/pkg/math/big/#Float.GobEncode"><code>GobEncode</code></a> and
<a href="/pkg/math/big/#Float.GobDecode"><code>GobDecode</code></a> methods,
so that values of type <code>Float</code> can now be encoded and decoded using the
<a href="/pkg/encoding/gob/"><code>encoding/gob</code></a>
package.
</p>
</dd>
</dl>
<dl id="math_rand"><dt><a href="/pkg/math/rand/">math/rand</a></dt>
<dd>
<p>
The
<a href="/pkg/math/rand/#Read"><code>Read</code></a> function and
<a href="/pkg/math/rand/#Rand"><code>Rand</code></a>'s
<a href="/pkg/math/rand/#Rand.Read"><code>Read</code></a> method
now produce a pseudo-random stream of bytes that is consistent and not
dependent on the size of the input buffer.
</p>
<p>
The documentation clarifies that
Rand's <a href="/pkg/math/rand/#Rand.Seed"><code>Seed</code></a>
and <a href="/pkg/math/rand/#Rand.Read"><code>Read</code></a> methods
are not safe to call concurrently, though the global
functions <a href="/pkg/math/rand/#Seed"><code>Seed</code></a>
and <a href="/pkg/math/rand/#Read"><code>Read</code></a> are (and have
always been) safe.
</p>
</dd>
</dl>
<dl id="mime_multipart"><dt><a href="/pkg/mime/multipart/">mime/multipart</a></dt>
<dd>
<p>
The
<a href="/pkg/mime/multipart/#Writer"><code>Writer</code></a>
implementation now emits each multipart section's header sorted by key.
Previously, iteration over a map caused the section header to use a
non-deterministic order.
</p>
</dd>
</dl>
<dl id="net"><dt><a href="/pkg/net/">net</a></dt>
<dd>
<p>
As part of the introduction of <a href="#context">context</a>, the
<a href="/pkg/net/#Dialer"><code>Dialer</code></a> type has a new method
<a href="/pkg/net/#Dialer.DialContext"><code>DialContext</code></a>, like
<a href="/pkg/net/#Dialer.Dial"><code>Dial</code></a> but adding the
<a href="/pkg/context/#Context"><code>context.Context</code></a>
for the dial operation.
The context is intended to obsolete the <code>Dialer</code>'s
<code>Cancel</code> and <code>Deadline</code> fields,
but the implementation continues to respect them,
for backwards compatibility.
</p>
<p>
The
<a href="/pkg/net/#IP"><code>IP</code></a> type's
<a href="/pkg/net/#IP.String"><code>String</code></a> method has changed its result for invalid <code>IP</code> addresses.
In past releases, if an <code>IP</code> byte slice had length other than 0, 4, or 16, <code>String</code>
returned <code>"?"</code>.
Go 1.7 adds the hexadecimal encoding of the bytes, as in <code>"?12ab"</code>.
</p>
<p>
The pure Go <a href="/pkg/net/#hdr-Name_Resolution">name resolution</a>
implementation now respects <code>nsswitch.conf</code>'s
stated preference for the priority of DNS lookups compared to
local file (that is, <code>/etc/hosts</code>) lookups.
</p>
</dd>
</dl>
<dl id="net_http"><dt><a href="/pkg/net/http/">net/http</a></dt>
<dd>
<p>
<a href="/pkg/net/http/#ResponseWriter"><code>ResponseWriter</code></a>'s
documentation now makes clear that beginning to write the response
may prevent future reads on the request body.
For maximal compatibility, implementations are encouraged to
read the request body completely before writing any part of the response.
</p>
<p>
As part of the introduction of <a href="#context">context</a>, the
<a href="/pkg/net/http/#Request"><code>Request</code></a> has a new methods
<a href="/pkg/net/http/#Request.Context"><code>Context</code></a>, to retrieve the associated context, and
<a href="/pkg/net/http/#Request.WithContext"><code>WithContext</code></a>, to construct a copy of <code>Request</code>
with a modified context.
</p>
<p>
In the
<a href="/pkg/net/http/#Server"><code>Server</code></a> implementation,
<a href="/pkg/net/http/#Server.Serve"><code>Serve</code></a> records in the request context
both the underlying <code>*Server</code> using the key <code>ServerContextKey</code>
and the local address on which the request was received (a
<a href="/pkg/net/#Addr"><code>Addr</code></a>) using the key <code>LocalAddrContextKey</code>.
For example, the address on which a request received is
<code>req.Context().Value(http.LocalAddrContextKey).(net.Addr)</code>.
</p>
<p>
The server's <a href="/pkg/net/http/#Server.Serve"><code>Serve</code></a> method
now only enables HTTP/2 support if the <code>Server.TLSConfig</code> field is <code>nil</code>
or includes <code>"h2"</code> in its <code>TLSConfig.NextProtos</code>.
</p>
<p>
The server implementation now
pads response codes less than 100 to three digits
as required by the protocol,
so that <code>w.WriteHeader(5)</code> uses the HTTP response
status <code>005</code>, not just <code>5</code>.
</p>
<p>
The server implementation now correctly sends only one "Transfer-Encoding" header when "chunked"
is set explicitly, following <a href="https://tools.ietf.org/html/rfc7230#section-3.3.1">RFC 7230</a>.
</p>
<p>
The server implementation is now stricter about rejecting requests with invalid HTTP versions.
Invalid requests claiming to be HTTP/0.x are now rejected (HTTP/0.9 was never fully supported),
and plaintext HTTP/2 requests other than the "PRI * HTTP/2.0" upgrade request are now rejected as well.
The server continues to handle encrypted HTTP/2 requests.
</p>
<p>
In the server, a 200 status code is sent back by the timeout handler on an empty
response body, instead of sending back 0 as the status code.
</p>
<p>
In the client, the
<a href="/pkg/net/http/#Transport"><code>Transport</code></a> implementation passes the request context
to any dial operation connecting to the remote server.
If a custom dialer is needed, the new <code>Transport</code> field
<code>DialContext</code> is preferred over the existing <code>Dial</code> field,
to allow the transport to supply a context.
</p>
<p>
The
<a href="/pkg/net/http/#Transport"><code>Transport</code></a> also adds fields
<code>IdleConnTimeout</code>,
<code>MaxIdleConns</code>,
and
<code>MaxResponseHeaderBytes</code>
to help control client resources consumed
by idle or chatty servers.
</p>
<p>
A
<a href="/pkg/net/http/#Client"><code>Client</code></a>'s configured <code>CheckRedirect</code> function can now
return <code>ErrUseLastResponse</code> to indicate that the
most recent redirect response should be returned as the
result of the HTTP request.
That response is now available to the <code>CheckRedirect</code> function
as <code>req.Response</code>.
</p>
<p>
Since Go 1, the default behavior of the HTTP client is
to request server-side compression
using the <code>Accept-Encoding</code> request header
and then to decompress the response body transparently,
and this behavior is adjustable using the
<a href="/pkg/net/http/#Transport"><code>Transport</code></a>'s <code>DisableCompression</code> field.
In Go 1.7, to aid the implementation of HTTP proxies, the
<a href="/pkg/net/http/#Response"><code>Response</code></a>'s new
<code>Uncompressed</code> field reports whether
this transparent decompression took place.
</p>
<p>
<a href="/pkg/net/http/#DetectContentType"><code>DetectContentType</code></a>
adds support for a few new audio and video content types.
</p>
</dd>
</dl>
<dl id="net_http_cgi"><dt><a href="/pkg/net/http/cgi/">net/http/cgi</a></dt>
<dd>
<p>
The
<a href="/pkg/net/http/cgi/#Handler"><code>Handler</code></a>
adds a new field
<code>Stderr</code>
that allows redirection of the child process's
standard error away from the host process's
standard error.
</p>