-
Notifications
You must be signed in to change notification settings - Fork 0
/
go1.8.html
1666 lines (1428 loc) · 57.6 KB
/
go1.8.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.8 Release Notes",
"Path": "/doc/go1.8",
"Template": true
}-->
<!--
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>
ul li { margin: 0.5em 0; }
</style>
<h2 id="introduction">Introduction to Go 1.8</h2>
<p>
The latest Go release, version 1.8, arrives six months after <a href="go1.7">Go 1.7</a>.
Most of its changes are in the implementation of the toolchain, runtime, and libraries.
There are <a href="#language">two minor changes</a> 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 support for 32-bit MIPS</a>,
<a href="#compiler">updates the compiler back end</a> to generate more efficient code,
<a href="#gc">reduces GC pauses</a> by eliminating stop-the-world stack rescanning,
<a href="#h2push">adds HTTP/2 Push support</a>,
<a href="#http_shutdown">adds HTTP graceful shutdown</a>,
<a href="#more_context">adds more context support</a>,
<a href="#mutex_prof">enables profiling mutexes</a>,
and <a href="#sort_slice">simplifies sorting slices</a>.
</p>
<h2 id="language">Changes to the language</h2>
<p>
When explicitly converting a value from one struct type to another,
as of Go 1.8 the tags are ignored. Thus two structs that differ
only in their tags may be converted from one to the other:
</p>
<pre>
func example() {
type T1 struct {
X int `json:"foo"`
}
type T2 struct {
X int `json:"bar"`
}
var v1 T1
var v2 T2
v1 = T1(v2) // now legal
}
</pre>
<p> <!-- CL 17711 -->
The language specification now only requires that implementations
support up to 16-bit exponents in floating-point constants. This does not affect
either the “<a href="/cmd/compile/"><code>gc</code></a>” or
<code>gccgo</code> compilers, both of
which still support 32-bit exponents.
</p>
<h2 id="ports">Ports</h2>
<p>
Go now supports 32-bit MIPS on Linux for both big-endian
(<code>linux/mips</code>) and little-endian machines
(<code>linux/mipsle</code>) that implement the MIPS32r1 instruction set with FPU
or kernel FPU emulation. Note that many common MIPS-based routers lack an FPU and
have firmware that doesn't enable kernel FPU emulation; Go won't run on such machines.
</p>
<p>
On DragonFly BSD, Go now requires DragonFly 4.4.4 or later. <!-- CL 29491, CL 29971 -->
</p>
<p>
On OpenBSD, Go now requires OpenBSD 5.9 or later. <!-- CL 34093 -->
</p>
<p>
The Plan 9 port's networking support is now much more complete
and matches the behavior of Unix and Windows with respect to deadlines
and cancelation. For Plan 9 kernel requirements, see the
<a href="https://golang.org/wiki/Plan9">Plan 9 wiki page</a>.
</p>
<p>
Go 1.8 now only supports OS X 10.8 or later. This is likely the last
Go release to support 10.8. Compiling Go or running
binaries on older OS X versions is untested.
</p>
<p>
Go 1.8 will be the last release to support Linux on ARMv5E and ARMv6 processors:
Go 1.9 will likely require the ARMv6K (as found in the Raspberry Pi 1) or later.
To identify whether a Linux system is ARMv6K or later, run
“<code>go</code> <code>tool</code> <code>dist</code> <code>-check-armv6k</code>”
(to facilitate testing, it is also possible to just copy the <code>dist</code> command to the
system without installing a full copy of Go 1.8)
and if the program terminates with output "ARMv6K supported." then the system
implements ARMv6K or later.
Go on non-Linux ARM systems already requires ARMv6K or later.
</p>
<h3 id="known_issues">Known Issues</h3>
<p>
There are some instabilities on FreeBSD and NetBSD that are known but not understood.
These can lead to program crashes in rare cases.
See
<a href="https://golang.org/issue/15658">issue 15658</a> and
<a href="https://golang.org/issue/16511">issue 16511</a>.
Any help in solving these issues would be appreciated.
</p>
<h2 id="tools">Tools</h2>
<h3 id="cmd_asm">Assembler</h3>
<p>
For 64-bit x86 systems, the following instructions have been added:
<code>VBROADCASTSD</code>,
<code>BROADCASTSS</code>,
<code>MOVDDUP</code>,
<code>MOVSHDUP</code>,
<code>MOVSLDUP</code>,
<code>VMOVDDUP</code>,
<code>VMOVSHDUP</code>, and
<code>VMOVSLDUP</code>.
</p>
<p>
For 64-bit PPC systems, the common vector scalar instructions have been
added:
<code>LXS</code>,
<code>LXSDX</code>,
<code>LXSI</code>,
<code>LXSIWAX</code>,
<code>LXSIWZX</code>,
<code>LXV</code>,
<code>LXVD2X</code>,
<code>LXVDSX</code>,
<code>LXVW4X</code>,
<code>MFVSR</code>,
<code>MFVSRD</code>,
<code>MFVSRWZ</code>,
<code>MTVSR</code>,
<code>MTVSRD</code>,
<code>MTVSRWA</code>,
<code>MTVSRWZ</code>,
<code>STXS</code>,
<code>STXSDX</code>,
<code>STXSI</code>,
<code>STXSIWX</code>,
<code>STXV</code>,
<code>STXVD2X</code>,
<code>STXVW4X</code>,
<code>XSCV</code>,
<code>XSCVDPSP</code>,
<code>XSCVDPSPN</code>,
<code>XSCVDPSXDS</code>,
<code>XSCVDPSXWS</code>,
<code>XSCVDPUXDS</code>,
<code>XSCVDPUXWS</code>,
<code>XSCVSPDP</code>,
<code>XSCVSPDPN</code>,
<code>XSCVSXDDP</code>,
<code>XSCVSXDSP</code>,
<code>XSCVUXDDP</code>,
<code>XSCVUXDSP</code>,
<code>XSCVX</code>,
<code>XSCVXP</code>,
<code>XVCV</code>,
<code>XVCVDPSP</code>,
<code>XVCVDPSXDS</code>,
<code>XVCVDPSXWS</code>,
<code>XVCVDPUXDS</code>,
<code>XVCVDPUXWS</code>,
<code>XVCVSPDP</code>,
<code>XVCVSPSXDS</code>,
<code>XVCVSPSXWS</code>,
<code>XVCVSPUXDS</code>,
<code>XVCVSPUXWS</code>,
<code>XVCVSXDDP</code>,
<code>XVCVSXDSP</code>,
<code>XVCVSXWDP</code>,
<code>XVCVSXWSP</code>,
<code>XVCVUXDDP</code>,
<code>XVCVUXDSP</code>,
<code>XVCVUXWDP</code>,
<code>XVCVUXWSP</code>,
<code>XVCVX</code>,
<code>XVCVXP</code>,
<code>XXLAND</code>,
<code>XXLANDC</code>,
<code>XXLANDQ</code>,
<code>XXLEQV</code>,
<code>XXLNAND</code>,
<code>XXLNOR</code>,
<code>XXLOR</code>,
<code>XXLORC</code>,
<code>XXLORQ</code>,
<code>XXLXOR</code>,
<code>XXMRG</code>,
<code>XXMRGHW</code>,
<code>XXMRGLW</code>,
<code>XXPERM</code>,
<code>XXPERMDI</code>,
<code>XXSEL</code>,
<code>XXSI</code>,
<code>XXSLDWI</code>,
<code>XXSPLT</code>, and
<code>XXSPLTW</code>.
</p>
<h3 id="tool_yacc">Yacc</h3>
<p> <!-- CL 27324, CL 27325 -->
The <code>yacc</code> tool (previously available by running
“<code>go</code> <code>tool</code> <code>yacc</code>”) has been removed.
As of Go 1.7 it was no longer used by the Go compiler.
It has moved to the “tools” repository and is now available at
<code><a href="https://godoc.org/golang.org/x/tools/cmd/goyacc">golang.org/x/tools/cmd/goyacc</a></code>.
</p>
<h3 id="tool_fix">Fix</h3>
<p> <!-- CL 28872 -->
The <code>fix</code> tool has a new “<code>context</code>”
fix to change imports from “<code>golang.org/x/net/context</code>”
to “<a href="/pkg/context/"><code>context</code></a>”.
</p>
<h3 id="tool_pprof">Pprof</h3>
<p> <!-- CL 33157 -->
The <code>pprof</code> tool can now profile TLS servers
and skip certificate validation by using the “<code>https+insecure</code>”
URL scheme.
</p>
<p> <!-- CL 23781 -->
The callgrind output now has instruction-level granularity.
</p>
<h3 id="tool_trace">Trace</h3>
<p> <!-- CL 23324 -->
The <code>trace</code> tool has a new <code>-pprof</code> flag for
producing pprof-compatible blocking and latency profiles from an
execution trace.
</p>
<p> <!-- CL 30017, CL 30702 -->
Garbage collection events are now shown more clearly in the
execution trace viewer. Garbage collection activity is shown on its
own row and GC helper goroutines are annotated with their roles.
</p>
<h3 id="tool_vet">Vet</h3>
<p>Vet is stricter in some ways and looser where it
previously caused false positives.</p>
<p>Vet now checks for copying an array of locks,
duplicate JSON and XML struct field tags,
non-space-separated struct tags,
deferred calls to HTTP <code>Response.Body.Close</code>
before checking errors, and
indexed arguments in <code>Printf</code>.
It also improves existing checks.</p>
</p>
<h3 id="compiler">Compiler Toolchain</h3>
<p>
Go 1.7 introduced a new compiler back end for 64-bit x86 systems.
In Go 1.8, that back end has been developed further and is now used for
all architectures.
</p>
<p>
The new back end, based on
<a href="https://en.wikipedia.org/wiki/Static_single_assignment_form">static single assignment form</a> (SSA),
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 20-30%
on 32-bit ARM systems. For 64-bit x86 systems, which already used the SSA back end in
Go 1.7, the gains are a more modest 0-10%. Other architectures will likely
see improvements closer to the 32-bit ARM numbers.
</p>
<p>
The temporary <code>-ssa=0</code> compiler flag introduced in Go 1.7
to disable the new back end has been removed in Go 1.8.
</p>
<p>
In addition to enabling the new compiler back end for all systems,
Go 1.8 also introduces a new compiler front end. The new compiler
front end should not be noticeable to users but is the foundation for
future performance work.
</p>
<p>
The compiler and linker have been optimized and run faster in this
release than in Go 1.7, although they are still slower than we would
like and will continue to be optimized in future releases.
Compared to the previous release, Go 1.8 is
<a href="https://dave.cheney.net/2016/11/19/go-1-8-toolchain-improvements">about 15% faster</a>.
</p>
<h3 id="cmd_cgo">Cgo</h3>
<p> <!-- CL 31141 -->
The Go tool now remembers the value of the <code>CGO_ENABLED</code> environment
variable set during <code>make.bash</code> and applies it to all future compilations
by default to fix issue <a href="https://golang.org/issue/12808">#12808</a>.
When doing native compilation, it is rarely necessary to explicitly set
the <code>CGO_ENABLED</code> environment variable as <code>make.bash</code>
will detect the correct setting automatically. The main reason to explicitly
set the <code>CGO_ENABLED</code> environment variable is when your environment
supports cgo, but you explicitly do not want cgo support, in which case, set
<code>CGO_ENABLED=0</code> during <code>make.bash</code> or <code>all.bash</code>.
</p>
<p> <!-- CL 29991 -->
The environment variable <code>PKG_CONFIG</code> may now be used to
set the program to run to handle <code>#cgo</code> <code>pkg-config</code>
directives. The default is <code>pkg-config</code>, the program
always used by earlier releases. This is intended to make it easier
to cross-compile
<a href="/cmd/cgo/">cgo</a> code.
</p>
<p> <!-- CL 32354 -->
The <a href="/cmd/cgo/">cgo</a> tool now supports a <code>-srcdir</code>
option, which is used by the <a href="/cmd/go/">go</a> command.
</p>
<p> <!-- CL 31768, 31811 -->
If <a href="/cmd/cgo/">cgo</a> code calls <code>C.malloc</code>, and
<code>malloc</code> returns <code>NULL</code>, the program will now
crash with an out of memory error.
<code>C.malloc</code> will never return <code>nil</code>.
Unlike most C functions, <code>C.malloc</code> may not be used in a
two-result form returning an errno value.
</p>
<p> <!-- CL 33237 -->
If <a href="/cmd/cgo/">cgo</a> is used to call a C function passing a
pointer to a C union, and if the C union can contain any pointer
values, and if <a href="/cmd/cgo/#hdr-Passing_pointers">cgo pointer
checking</a> is enabled (as it is by default), the union value is now
checked for Go pointers.
</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.
We expect that the next release, GCC 7, will contain the Go 1.8
version of gccgo.
</p>
<h3 id="gopath">Default GOPATH</h3>
<p>
The
<a href="/cmd/go/#hdr-GOPATH_environment_variable"><code>GOPATH</code>
environment variable</a> now has a default value if it
is unset. It defaults to
<code>$HOME/go</code> on Unix and
<code>%USERPROFILE%/go</code> on Windows.
</p>
<h3 id="go_get">Go get</h3>
<p> <!-- CL 34818 -->
The “<code>go</code> <code>get</code>” command now always respects
HTTP proxy environment variables, regardless of whether
the <code style='white-space:nowrap'>-insecure</code> flag is used. In previous releases, the
<code style='white-space:nowrap'>-insecure</code> flag had the side effect of not using proxies.
</p>
<h3 id="go_bug">Go bug</h3>
<p>
The new
“<a href="/cmd/go/#hdr-Print_information_for_bug_reports"><code>go</code> <code>bug</code></a>”
command starts a bug report on GitHub, prefilled
with information about the current system.
</p>
<h3 id="cmd_doc">Go doc</h3>
<p> <!-- CL 25419 -->
The
“<a href="/cmd/go/#hdr-Show_documentation_for_package_or_symbol"><code>go</code> <code>doc</code></a>”
command now groups constants and variables with their type,
following the behavior of
<a href="/cmd/godoc/"><code>godoc</code></a>.
</p>
<p> <!-- CL 25420 -->
In order to improve the readability of <code>doc</code>'s
output, each summary of the first-level items is guaranteed to
occupy a single line.
</p>
<p> <!-- CL 31852 -->
Documentation for a specific method in an interface definition can
now be requested, as in
“<code>go</code> <code>doc</code> <code>net.Conn.SetDeadline</code>”.
</p>
<h3 id="plugin">Plugins</h3>
<p>
Go now provides early support for plugins with a “<code>plugin</code>”
build mode for generating plugins written in Go, and a
new <a href="/pkg/plugin/"><code>plugin</code></a> package for
loading such plugins at run time. Plugin support is currently only
available on Linux. Please report any issues.
</p>
<h2 id="runtime">Runtime</h2>
<h3 id="liveness">Argument Liveness</h3>
<p>
<!-- Issue 15843 --> The garbage collector no longer considers
arguments live throughout the entirety of a function. For more
information, and for how to force a variable to remain live, see
the <a href="/pkg/runtime/#KeepAlive"><code>runtime.KeepAlive</code></a>
function added in Go 1.7.
</p>
<p>
<i>Updating:</i>
Code that sets a finalizer on an allocated object may need to add
calls to <code>runtime.KeepAlive</code> in functions or methods
using that object.
Read the
<a href="/pkg/runtime/#KeepAlive"><code>KeepAlive</code>
documentation</a> and its example for more details.
</p>
<h3 id="mapiter">Concurrent Map Misuse</h3>
<p>
In Go 1.6, the runtime
<a href="/doc/go1.6#runtime">added lightweight,
best-effort detection of concurrent misuse of maps</a>. This release
improves that detector with support for detecting programs that
concurrently write to and iterate over a map.
</p>
<p>
As always, if one goroutine is writing to a map, no other goroutine should be
reading (which includes iterating) or writing the map concurrently.
If the runtime detects this condition, it prints a diagnosis and crashes the program.
The best way to find out more about the problem is to run the program
under the
<a href="https://blog.golang.org/race-detector">race detector</a>,
which will more reliably identify the race
and give more detail.
</p>
<h3 id="memstats">MemStats Documentation</h3>
<p> <!-- CL 28972 -->
The <a href="/pkg/runtime/#MemStats"><code>runtime.MemStats</code></a>
type has been more thoroughly documented.
</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 standard library.
</p>
<p>
There have been optimizations to implementations in the
<a href="/pkg/bytes/"><code>bytes</code></a>,
<a href="/pkg/crypto/aes/"><code>crypto/aes</code></a>,
<a href="/pkg/crypto/cipher/"><code>crypto/cipher</code></a>,
<a href="/pkg/crypto/elliptic/"><code>crypto/elliptic</code></a>,
<a href="/pkg/crypto/sha256/"><code>crypto/sha256</code></a>,
<a href="/pkg/crypto/sha512/"><code>crypto/sha512</code></a>,
<a href="/pkg/encoding/asn1/"><code>encoding/asn1</code></a>,
<a href="/pkg/encoding/csv/"><code>encoding/csv</code></a>,
<a href="/pkg/encoding/hex/"><code>encoding/hex</code></a>,
<a href="/pkg/encoding/json/"><code>encoding/json</code></a>,
<a href="/pkg/hash/crc32/"><code>hash/crc32</code></a>,
<a href="/pkg/image/color/"><code>image/color</code></a>,
<a href="/pkg/image/draw/"><code>image/draw</code></a>,
<a href="/pkg/math/"><code>math</code></a>,
<a href="/pkg/math/big/"><code>math/big</code></a>,
<a href="/pkg/reflect/"><code>reflect</code></a>,
<a href="/pkg/regexp/"><code>regexp</code></a>,
<a href="/pkg/runtime/"><code>runtime</code></a>,
<a href="/pkg/strconv/"><code>strconv</code></a>,
<a href="/pkg/strings/"><code>strings</code></a>,
<a href="/pkg/syscall/"><code>syscall</code></a>,
<a href="/pkg/text/template/"><code>text/template</code></a>, and
<a href="/pkg/unicode/utf8/"><code>unicode/utf8</code></a>
packages.
</p>
<h3 id="gc">Garbage Collector</h3>
<p>
Garbage collection pauses should be significantly shorter than they
were in Go 1.7, usually under 100 microseconds and often as low as
10 microseconds.
See the
<a href="https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md"
>document on eliminating stop-the-world stack re-scanning</a>
for details. More work remains for Go 1.9.
</p>
<h3 id="defer">Defer</h3>
<!-- CL 29656, CL 29656 -->
<p>
The overhead of <a href="/ref/spec/#Defer_statements">deferred
function calls</a> has been reduced by about half.
</p>
<h3 id="cgoperf">Cgo</h3>
<p>The overhead of calls from Go into C has been reduced by about half.</p>
<h2 id="library">Standard library</h2>
<h3 id="examples">Examples</h3>
<p>
Examples have been added to the documentation across many packages.
</p>
<h3 id="sort_slice">Sort</h3>
<p>
The <a href="/pkg/sort/">sort</a> package
now includes a convenience function
<a href="/pkg/sort/#Slice"><code>Slice</code></a> to sort a
slice given a <em>less</em> function.
In many cases this means that writing a new sorter type is not
necessary.
</p>
<p>
Also new are
<a href="/pkg/sort/#SliceStable"><code>SliceStable</code></a> and
<a href="/pkg/sort/#SliceIsSorted"><code>SliceIsSorted</code></a>.
</p>
<h3 id="h2push">HTTP/2 Push</h3>
<p>
The <a href="/pkg/net/http/">net/http</a> package now includes a
mechanism to
send HTTP/2 server pushes from a
<a href="/pkg/net/http/#Handler"><code>Handler</code></a>.
Similar to the existing <code>Flusher</code> and <code>Hijacker</code>
interfaces, an HTTP/2
<a href="/pkg/net/http/#ResponseWriter"><code>ResponseWriter</code></a>
now implements the new
<a href="/pkg/net/http/#Pusher"><code>Pusher</code></a> interface.
</p>
<h3 id="http_shutdown">HTTP Server Graceful Shutdown</h3>
<p> <!-- CL 32329 -->
The HTTP Server now has support for graceful shutdown using the new
<a href="/pkg/net/http/#Server.Shutdown"><code>Server.Shutdown</code></a>
method and abrupt shutdown using the new
<a href="/pkg/net/http/#Server.Close"><code>Server.Close</code></a>
method.
</p>
<h3 id="more_context">More Context Support</h3>
<p>
Continuing <a href="/doc/go1.7#context">Go 1.7's adoption</a>
of <a href="/pkg/context/#Context"><code>context.Context</code></a>
into the standard library, Go 1.8 adds more context support
to existing packages:
</p>
<ul>
<li>The new <a href="/pkg/net/http/#Server.Shutdown"><code>Server.Shutdown</code></a>
takes a context argument.</li>
<li>There have been <a href="#database_sql">significant additions</a> to the
<a href="/pkg/database/sql/">database/sql</a> package with context support.</li>
<li>All nine of the new <code>Lookup</code> methods on the new
<a href="/pkg/net/#Resolver"><code>net.Resolver</code></a> now
take a context.</li>
</ul>
<h3 id="mutex_prof">Mutex Contention Profiling</h3>
<p>
The runtime and tools now support profiling contended mutexes.
</p>
<p>
Most users will want to use the new <code>-mutexprofile</code>
flag with “<a href="/cmd/go/#hdr-Description_of_testing_flags"><code>go</code> <code>test</code></a>”,
and then use <a href="/cmd/pprof/">pprof</a> on the resultant file.
</p>
<p>
Lower-level support is also available via the new
<a href="/pkg/runtime/#MutexProfile"><code>MutexProfile</code></a>
and
<a href="/pkg/runtime/#SetMutexProfileFraction"><code>SetMutexProfileFraction</code></a>.
</p>
<p>
A known limitation for Go 1.8 is that the profile only reports contention for
<a href="/pkg/sync/#Mutex"><code>sync.Mutex</code></a>,
not
<a href="/pkg/sync/#RWMutex"><code>sync.RWMutex</code></a>.
</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. The following sections list the user visible changes and additions.
Optimizations and minor bug fixes are not listed.
</p>
<dl id="archive_tar"><dt><a href="/pkg/archive/tar/">archive/tar</a></dt>
<dd>
<p> <!-- CL 28471, CL 31440, CL 31441, CL 31444, CL 28418, CL 31439 -->
The tar implementation corrects many bugs in corner cases of the file format.
The <a href="/pkg/archive/tar/#Reader"><code>Reader</code></a>
is now able to process tar files in the PAX format with entries larger than 8GB.
The <a href="/pkg/archive/tar/#Writer"><code>Writer</code></a>
no longer produces invalid tar files in some situations involving long pathnames.
</p>
</dd>
</dl>
<dl id="compress_flate"><dt><a href="/pkg/compress/flate/">compress/flate</a></dt>
<dd>
<p> <!-- CL 31640, CL 31174, CL 32149 -->
There have been some minor fixes to the encoder to improve the
compression ratio in certain situations. As a result, the exact
encoded output of <code>DEFLATE</code> may be different from Go 1.7. Since
<code>DEFLATE</code> is the underlying compression of gzip, png, zlib, and zip,
those formats may have changed outputs.
</p>
<p> <!-- CL 31174 -->
The encoder, when operating in
<a href="/pkg/compress/flate/#NoCompression"><code>NoCompression</code></a>
mode, now produces a consistent output that is not dependent on
the size of the slices passed to the
<a href="/pkg/compress/flate/#Writer.Write"><code>Write</code></a>
method.
</p>
<p> <!-- CL 28216 -->
The decoder, upon encountering an error, now returns any
buffered data it had uncompressed along with the error.
</p>
</dd>
</dl>
<dl id="compress_gzip"><dt><a href="/pkg/compress/gzip/">compress/gzip</a></dt>
<dd>
<p>
The <a href="/pkg/compress/gzip/#Writer"><code>Writer</code></a>
now encodes a zero <code>MTIME</code> field when
the <a href="/pkg/compress/gzip/#Header"><code>Header.ModTime</code></a>
field is the zero value.
In previous releases of Go, the <code>Writer</code> would encode
a nonsensical value.
Similarly,
the <a href="/pkg/compress/gzip/#Reader"><code>Reader</code></a>
now reports a zero encoded <code>MTIME</code> field as a zero
<code>Header.ModTime</code>.
</p>
</dd>
</dl>
<dl id="context"><dt><a href="/pkg/context/">context</a></dt>
<dd>
<p> <!-- CL 30370 -->
The <a href="/pkg/context#DeadlineExceeded"><code>DeadlineExceeded</code></a>
error now implements
<a href="/pkg/net/#Error"><code>net.Error</code></a>
and reports true for both the <code>Timeout</code> and
<code>Temporary</code> methods.
</p>
</dd>
</dl>
<dl id="crypto_tls"><dt><a href="/pkg/crypto/tls/">crypto/tls</a></dt>
<dd>
<p> <!-- CL 25159, CL 31318 -->
The new method
<a href="/pkg/crypto/tls/#Conn.CloseWrite"><code>Conn.CloseWrite</code></a>
allows TLS connections to be half closed.
</p>
<p> <!-- CL 28075 -->
The new method
<a href="/pkg/crypto/tls/#Config.Clone"><code>Config.Clone</code></a>
clones a TLS configuration.
</p>
<p>
<!-- CL 30790 -->
The new <a href="/pkg/crypto/tls/#Config.GetConfigForClient"><code>Config.GetConfigForClient</code></a>
callback allows selecting a configuration for a client dynamically, based
on the client's
<a href="/pkg/crypto/tls/#ClientHelloInfo"><code>ClientHelloInfo</code></a>.
<!-- CL 31391, CL 32119 -->
The <a href="/pkg/crypto/tls/#ClientHelloInfo"><code>ClientHelloInfo</code></a>
struct now has new
fields <code>Conn</code>, <code>SignatureSchemes</code> (using
the new
type <a href="/kg/crypto/tls/#SignatureScheme"><code>SignatureScheme</code></a>),
<code>SupportedProtos</code>, and <code>SupportedVersions</code>.
</p>
<p> <!-- CL 32115 -->
The new <a href="/pkg/crypto/tls/#Config.GetClientCertificate"><code>Config.GetClientCertificate</code></a>
callback allows selecting a client certificate based on the server's
TLS <code>CertificateRequest</code> message, represented by the new
<a href="/pkg/crypto/tls/#CertificateRequestInfo"><code>CertificateRequestInfo</code></a>.
</p>
<p> <!-- CL 27434 -->
The new
<a href="/pkg/crypto/tls/#Config.KeyLogWriter"><code>Config.KeyLogWriter</code></a>
allows debugging TLS connections
in <a href="https://www.wireshark.org/">WireShark</a> and
similar tools.
</p>
<p> <!-- CL 32115 -->
The new
<a href="/pkg/crypto/tls/#Config.VerifyPeerCertificate"><code>Config.VerifyPeerCertificate</code></a>
callback allows additional validation of a peer's presented certificate.
</p>
<p> <!-- CL 18130 -->
The <code>crypto/tls</code> package now implements basic
countermeasures against CBC padding oracles. There should be
no explicit secret-dependent timings, but it does not attempt to
normalize memory accesses to prevent cache timing leaks.
</p>
<p>
The <code>crypto/tls</code> package now supports
X25519 and <!-- CL 30824, CL 30825 -->
ChaCha20-Poly1305. <!-- CL 30957, CL 30958 -->
ChaCha20-Poly1305 is now prioritized unless <!-- CL 32871 -->
hardware support for AES-GCM is present.
</p>
<p> <!-- CL 27315, CL 35290 -->
AES-128-CBC cipher suites with SHA-256 are also
now supported, but disabled by default.
</p>
</dd>
</dl>
<dl id="crypto_x509"><dt><a href="/pkg/crypto/x509/">crypto/x509</a></dt>
<dd>
<p> <!-- CL 24743 -->
PSS signatures are now supported.
</p>
<p> <!-- CL 32644 -->
<a href="/pkg/crypto/x509/#UnknownAuthorityError"><code>UnknownAuthorityError</code></a>
now has a <code>Cert</code> field, reporting the untrusted
certificate.
</p>
<p>
Certificate validation is more permissive in a few cases and
stricter in a few other cases.
<!--
crypto/x509: allow a leaf certificate to be specified directly as root (CL 27393)
crypto/x509: check that the issuer name matches the issuer's subject name (CL 23571)
crypto/x509: don't accept a root that already appears in a chain. (CL 32121)
crypto/x509: fix name constraints handling (CL 30155)
crypto/x509: parse all names in an RDN (CL 30810)
crypto/x509: recognise ISO OID for RSA+SHA1 (CL 27394)
crypto/x509: require a NULL parameters for RSA public keys (CL 16166, CL 27312)
crypto/x509: return error for missing SerialNumber (CL 27238)
-->
</p>
<p><!-- CL 30375 -->
Root certificates will now also be looked for
at <code>/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem</code>
on Linux, to support RHEL and CentOS.
</p>
</dd>
</dl>
<dl id="database_sql"><dt><a href="/pkg/database/sql/">database/sql</a></dt>
<dd>
<p>
The package now supports <code>context.Context</code>. There are new methods
ending in <code>Context</code> such as
<a href="/pkg/database/sql/#DB.QueryContext"><code>DB.QueryContext</code></a> and
<a href="/pkg/database/sql/#DB.PrepareContext"><code>DB.PrepareContext</code></a>
that take context arguments. Using the new <code>Context</code> methods ensures that
connections are closed and returned to the connection pool when the
request is done; enables canceling in-progress queries
should the driver support that; and allows the database
pool to cancel waiting for the next available connection.
</p>
<p>
The <a href="/pkg/database/sql#IsolationLevel"><code>IsolationLevel</code></a>
can now be set when starting a transaction by setting the isolation level
on <a href="/pkg/database/sql#TxOptions.Isolation"><code>TxOptions.Isolation</code></a> and passing
it to <a href="/pkg/database/sql#DB.BeginTx"><code>DB.BeginTx</code></a>.
An error will be returned if an isolation level is selected that the driver
does not support. A read-only attribute may also be set on the transaction
by setting <a href="/pkg/database/sql/#TxOptions.ReadOnly"><code>TxOptions.ReadOnly</code></a>
to true.
</p>
<p>
Queries now expose the SQL column type information for drivers that support it.
Rows can return <a href="/pkg/database/sql#Rows.ColumnTypes"><code>ColumnTypes</code></a>
which can include SQL type information, column type lengths, and the Go type.
</p>
<p>
A <a href="/pkg/database/sql/#Rows"><code>Rows</code></a>
can now represent multiple result sets. After
<a href="/pkg/database/sql/#Rows.Next"><code>Rows.Next</code></a> returns false,
<a href="/pkg/database/sql/#Rows.NextResultSet"><code>Rows.NextResultSet</code></a>
may be called to advance to the next result set. The existing <code>Rows</code>
should continue to be used after it advances to the next result set.
</p>
<p>
<a href="/pkg/database/sql/#NamedArg"><code>NamedArg</code></a> may be used
as query arguments. The new function <a href="/pkg/database/sql/#Named"><code>Named</code></a>
helps create a <a href="/pkg/database/sql/#NamedArg"><code>NamedArg</code></a>
more succinctly.
<p>
If a driver supports the new
<a href="/pkg/database/sql/driver/#Pinger"><code>Pinger</code></a>
interface, the
<a href="/pkg/database/sql/#DB.Ping"><code>DB.Ping</code></a>
and
<a href="/pkg/database/sql/#DB.PingContext"><code>DB.PingContext</code></a>
methods will use that interface to check whether a
database connection is still valid.
</p>
<p>
The new <code>Context</code> query methods work for all drivers, but
<code>Context</code> cancelation is not responsive unless the driver has been
updated to use them. The other features require driver support in
<a href="/pkg/database/sql/driver"><code>database/sql/driver</code></a>.
Driver authors should review the new interfaces. Users of existing
driver should review the driver documentation to see what
it supports and any system specific documentation on each feature.
</p>
</dd>
</dl>
<dl id="debug_pe"><dt><a href="/pkg/debug/pe/">debug/pe</a></dt>
<dd>
<p> <!-- CL 22720, CL 27212, CL 22181, CL 22332, CL 22336, Issue 15345 -->
The package has been extended and is now used by
<a href="/cmd/link/">the Go linker</a> to read <code>gcc</code>-generated object files.
The new
<a href="/pkg/debug/pe/#File.StringTable"><code>File.StringTable</code></a>
and
<a href="/pkg/debug/pe/#Section.Relocs"><code>Section.Relocs</code></a>
fields provide access to the COFF string table and COFF relocations.
The new
<a href="/pkg/debug/pe/#File.COFFSymbols"><code>File.COFFSymbols</code></a>
allows low-level access to the COFF symbol table.
</p>
</dd>
</dl>
<dl id="encoding_base64"><dt><a href="/pkg/encoding/base64/">encoding/base64</a></dt>
<dd>
<p> <!-- CL 24964 -->
The new
<a href="/pkg/encoding/base64/#Encoding.Strict"><code>Encoding.Strict</code></a>
method returns an <code>Encoding</code> that causes the decoder
to return an error when the trailing padding bits are not zero.
</p>
</dd>
</dl>
<dl id="encoding_binary"><dt><a href="/pkg/encoding/binary/">encoding/binary</a></dt>
<dd>
<p> <!-- CL 28514 -->
<a href="/pkg/encoding/binary/#Read"><code>Read</code></a>
and
<a href="/pkg/encoding/binary/#Write"><code>Write</code></a>
now support booleans.
</p>
</dd>
</dl>
<dl id="encoding_json"><dt><a href="/pkg/encoding/json/">encoding/json</a></dt>
<dd>
<p> <!-- CL 18692 -->
<a href="/pkg/encoding/json/#UnmarshalTypeError"><code>UnmarshalTypeError</code></a>
now includes the struct and field name.
</p>
<p> <!-- CL 31932 -->
A nil <a href="/pkg/encoding/json/#Marshaler"><code>Marshaler</code></a>
now marshals as a JSON <code>null</code> value.
</p>
<p> <!-- CL 21811 -->
A <a href="/pkg/encoding/json/#RawMessage"><code>RawMessage</code></a> value now
marshals the same as its pointer type.
</p>
<p> <!-- CL 30371 -->
<a href="/pkg/encoding/json/#Marshal"><code>Marshal</code></a>
encodes floating-point numbers using the same format as in ES6,
preferring decimal (not exponential) notation for a wider range of values.
In particular, all floating-point integers up to 2<sup>64</sup> format the
same as the equivalent <code>int64</code> representation.
</p>
<p> <!-- CL 30944 -->
In previous versions of Go, unmarshaling a JSON <code>null</code> into an
<a href="/pkg/encoding/json/#Unmarshaler"><code>Unmarshaler</code></a>
was considered a no-op; now the <code>Unmarshaler</code>'s
<code>UnmarshalJSON</code> method is called with the JSON literal
<code>null</code> and can define the semantics of that case.
</p>
</dd>
</dl>
<dl id="encoding_pem"><dt><a href="/pkg/encoding/pem/">encoding/pem</a></dt>
<dd>
<p> <!-- CL 27391 -->
<a href="/pkg/encoding/pem/#Decode"><code>Decode</code></a>
is now strict about the format of the ending line.
</p>
</dd>
</dl>
<dl id="encoding_xml"><dt><a href="/pkg/encoding/xml/">encoding/xml</a></dt>
<dd>
<p> <!-- CL 30946 -->
<a href="/pkg/encoding/xml/#Unmarshal"><code>Unmarshal</code></a>
now has wildcard support for collecting all attributes using
the new <code>",any,attr"</code> struct tag.
</p>
</dd>
</dl>
<dl id="expvar"><dt><a href="/pkg/expvar/">expvar</a></dt>
<dd>