mirror of
https://github.com/golang/go.git
synced 2026-01-30 07:32:05 +03:00
Compare commits
68 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62ec3dd260 | ||
|
|
d29b4ea305 | ||
|
|
ba83a7c452 | ||
|
|
35c41e21bb | ||
|
|
19dea72f5f | ||
|
|
ac02fdec7c | ||
|
|
4fc9d3bc58 | ||
|
|
92e78f7e8d | ||
|
|
c4e9966a32 | ||
|
|
5ca2cf89e7 | ||
|
|
fcc527344f | ||
|
|
731ebf4d87 | ||
|
|
8b086a2b7f | ||
|
|
499088f6dd | ||
|
|
991583017c | ||
|
|
578e281583 | ||
|
|
8acc2ea68b | ||
|
|
ec06e9ba45 | ||
|
|
aeb9d03e4a | ||
|
|
827c5d5355 | ||
|
|
e552f772f7 | ||
|
|
fc6457d1d2 | ||
|
|
ff048033e4 | ||
|
|
c1d8d9d8be | ||
|
|
0380c9ad38 | ||
|
|
100b6739fc | ||
|
|
82d12bdcf7 | ||
|
|
32355f5c31 | ||
|
|
35ddc140c4 | ||
|
|
746edd459d | ||
|
|
ad8ebb9e85 | ||
|
|
6fc1242ea8 | ||
|
|
f9d0594a47 | ||
|
|
7294ede961 | ||
|
|
f062f48c1f | ||
|
|
a40b76a40c | ||
|
|
7e880151b1 | ||
|
|
4dd46a678f | ||
|
|
0ea746023f | ||
|
|
6ff06c19fd | ||
|
|
71b8a3bc87 | ||
|
|
91fd14b824 | ||
|
|
162b3610e6 | ||
|
|
a2884af3b6 | ||
|
|
c55fb33612 | ||
|
|
4754cba67f | ||
|
|
491b7bcff5 | ||
|
|
05e77d4191 | ||
|
|
297d394cab | ||
|
|
6e501da62e | ||
|
|
6ae7c0bc6d | ||
|
|
efc6d86965 | ||
|
|
a718f939d2 | ||
|
|
da1f5d376a | ||
|
|
35e6a10c90 | ||
|
|
320da8d149 | ||
|
|
b840ae1e16 | ||
|
|
fc60d9dd6e | ||
|
|
96d39207d1 | ||
|
|
a4aee30cb4 | ||
|
|
e3a53db2b8 | ||
|
|
52d020260d | ||
|
|
9527a465f3 | ||
|
|
fa5e4baf87 | ||
|
|
0cfe46ce74 | ||
|
|
74f0f6939c | ||
|
|
7ab5e0c5e2 | ||
|
|
1af509d46e |
14
.gitattributes
vendored
14
.gitattributes
vendored
@@ -1,16 +1,10 @@
|
||||
# Treat all files in the Go repo as binary, with no git magic updating
|
||||
# line endings. This produces predictable results in different environments.
|
||||
#
|
||||
# Windows users contributing to Go will need to use a modern version
|
||||
# of git and editors capable of LF line endings.
|
||||
#
|
||||
# Windows .bat files are known to have multiple bugs when run with LF
|
||||
# endings, and so they are checked in with CRLF endings, with a test
|
||||
# in test/winbatch.go to catch problems. (See golang.org/issue/37791.)
|
||||
# line endings. Windows users contributing to Go will need to use a
|
||||
# modern version of git and editors capable of LF line endings.
|
||||
#
|
||||
# We'll prevent accidental CRLF line endings from entering the repo
|
||||
# via the git-codereview gofmt checks and tests.
|
||||
# via the git-review gofmt checks.
|
||||
#
|
||||
# See golang.org/issue/9281.
|
||||
# See golang.org/issue/9281
|
||||
|
||||
* -text
|
||||
|
||||
6
.github/ISSUE_TEMPLATE
vendored
6
.github/ISSUE_TEMPLATE
vendored
@@ -1,7 +1,4 @@
|
||||
<!--
|
||||
Please answer these questions before submitting your issue. Thanks!
|
||||
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
|
||||
-->
|
||||
<!-- Please answer these questions before submitting your issue. Thanks! -->
|
||||
|
||||
### What version of Go are you using (`go version`)?
|
||||
|
||||
@@ -36,3 +33,4 @@ A link on play.golang.org is best.
|
||||
|
||||
|
||||
### What did you see instead?
|
||||
|
||||
|
||||
13
AUTHORS
13
AUTHORS
@@ -47,7 +47,7 @@ Ahmy Yulrizka <yulrizka@gmail.com>
|
||||
Aiden Scandella <ai@uber.com>
|
||||
Ainar Garipov <gugl.zadolbal@gmail.com>
|
||||
Aishraj Dahal <aishraj@users.noreply.github.com>
|
||||
Akhil Indurti <aindurti@gmail.com>
|
||||
Akhil Indurti <contact@akhilindurti.com>
|
||||
Akihiro Suda <suda.kyoto@gmail.com>
|
||||
Akshat Kumar <seed@mail.nanosouffle.net>
|
||||
Alan Shreve <alan@inconshreveable.com>
|
||||
@@ -96,7 +96,6 @@ Alexei Sholik <alcosholik@gmail.com>
|
||||
Alexey Borzenkov <snaury@gmail.com>
|
||||
Alexey Neganov <neganovalexey@gmail.com>
|
||||
Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
|
||||
Alexey Semenyuk <alexsemenyuk88@gmail.com>
|
||||
Alexis Hildebrandt <surryhill@gmail.com>
|
||||
Ali Rizvi-Santiago <arizvisa@gmail.com>
|
||||
Aliaksandr Valialkin <valyala@gmail.com>
|
||||
@@ -145,7 +144,6 @@ Andy Davis <andy@bigandian.com>
|
||||
Andy Finkenstadt <afinkenstadt@zynga.com>
|
||||
Andy Lindeman <andy@lindeman.io>
|
||||
Andy Maloney <asmaloney@gmail.com>
|
||||
Andy Pan <panjf2000@gmail.com>
|
||||
Andy Walker <walkeraj@gmail.com>
|
||||
Anfernee Yongkun Gui <anfernee.gui@gmail.com>
|
||||
Angelo Bulfone <mbulfone@gmail.com>
|
||||
@@ -563,7 +561,6 @@ Hitoshi Mitake <mitake.hitoshi@gmail.com>
|
||||
Holden Huang <ttyh061@gmail.com>
|
||||
Hong Ruiqi <hongruiqi@gmail.com>
|
||||
Hongfei Tan <feilengcui008@gmail.com>
|
||||
Hootsuite Inc.
|
||||
Hsin-Ho Yeh <yhh92u@gmail.com>
|
||||
Hu Keping <hukeping@huawei.com>
|
||||
Hugues Bruant <hugues.bruant@gmail.com>
|
||||
@@ -931,11 +928,10 @@ Maxim Khitrov <max@mxcrypt.com>
|
||||
Maxime de Roucy <maxime.deroucy@gmail.com>
|
||||
Máximo Cuadros Ortiz <mcuadros@gmail.com>
|
||||
Maxwell Krohn <themax@gmail.com>
|
||||
Maya Rashish <maya@netbsd.org>
|
||||
Mayank Kumar <krmayankk@gmail.com>
|
||||
MediaMath, Inc
|
||||
Meir Fischer <meirfischer@gmail.com>
|
||||
Meng Zhuo <mengzhuo1203@gmail.com> <mzh@golangcn.org>
|
||||
Meng Zhuo <mengzhuo1203@gmail.com>
|
||||
Meteor Development Group
|
||||
Mhd Sulhan <m.shulhan@gmail.com>
|
||||
Micah Stetson <micah.stetson@gmail.com>
|
||||
@@ -1045,7 +1041,6 @@ Niels Widger <niels.widger@gmail.com>
|
||||
Nigel Kerr <nigel.kerr@gmail.com>
|
||||
Nik Nyby <nnyby@columbia.edu>
|
||||
Nikhil Benesch <nikhil.benesch@gmail.com>
|
||||
Nikita Gillmann <nikita@n0.is> <ng0@n0.is>
|
||||
Niklas Schnelle <niklas.schnelle@gmail.com>
|
||||
Niko Dziemba <niko@dziemba.com>
|
||||
Nikolay Turpitko <nikolay@turpitko.com>
|
||||
@@ -1144,11 +1139,9 @@ Pietro Gagliardi <pietro10@mac.com>
|
||||
Piyush Mishra <piyush@codeitout.com>
|
||||
Platform.sh
|
||||
Pontus Leitzler <leitzler@gmail.com>
|
||||
Prasanga Siripala <pj@pjebs.com.au>
|
||||
Prashant Varanasi <prashant@prashantv.com>
|
||||
Pravendra Singh <hackpravj@gmail.com>
|
||||
Preetam Jinka <pj@preet.am>
|
||||
Qais Patankar <qaisjp@gmail.com>
|
||||
Qiuxuan Zhu <ilsh1022@gmail.com>
|
||||
Qualcomm Data Center, Inc.
|
||||
Quan Tran <qeed.quan@gmail.com>
|
||||
@@ -1314,7 +1307,6 @@ Szabolcs Nagy <nsz@port70.net>
|
||||
Taavi Kivisik <taavi.kivisik@gmail.com>
|
||||
Tad Fisher <tadfisher@gmail.com>
|
||||
Tad Glines <tad.glines@gmail.com>
|
||||
Tailscale Inc.
|
||||
Taj Khattra <taj.khattra@gmail.com>
|
||||
Takayoshi Nishida <takayoshi.nishida@gmail.com>
|
||||
Takeshi YAMANASHI <9.nashi@gmail.com>
|
||||
@@ -1399,7 +1391,6 @@ Upthere, Inc.
|
||||
Uriel Mangado <uriel@berlinblue.org>
|
||||
Vadim Grek <vadimprog@gmail.com>
|
||||
Vadim Vygonets <unixdj@gmail.com>
|
||||
Vee Zhang <veezhang@126.com> <vveezhang@gmail.com>
|
||||
Vendasta
|
||||
Veselkov Konstantin <kostozyb@gmail.com>
|
||||
Victor Vrantchan <vrancean+github@gmail.com>
|
||||
|
||||
446
CONTRIBUTORS
446
CONTRIBUTORS
File diff suppressed because it is too large
Load Diff
13
SECURITY.md
13
SECURITY.md
@@ -1,13 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
We support the past two Go releases (for example, Go 1.12.x and Go 1.13.x).
|
||||
|
||||
See https://golang.org/wiki/Go-Release-Cycle and in particular the
|
||||
[Release Maintenance](https://github.com/golang/go/wiki/Go-Release-Cycle#release-maintenance)
|
||||
part of that page.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
See https://golang.org/security for how to report a vulnerability.
|
||||
@@ -8,6 +8,10 @@ pkg os (linux-arm), const O_SYNC = 4096
|
||||
pkg os (linux-arm-cgo), const O_SYNC = 4096
|
||||
pkg os (linux-arm), const O_SYNC = 1052672
|
||||
pkg os (linux-arm-cgo), const O_SYNC = 1052672
|
||||
pkg syscall (darwin-386), const ImplementsGetwd = false
|
||||
pkg syscall (darwin-386), func Fchflags(string, int) error
|
||||
pkg syscall (darwin-386-cgo), const ImplementsGetwd = false
|
||||
pkg syscall (darwin-386-cgo), func Fchflags(string, int) error
|
||||
pkg syscall (darwin-amd64), const ImplementsGetwd = false
|
||||
pkg syscall (darwin-amd64), func Fchflags(string, int) error
|
||||
pkg syscall (darwin-amd64-cgo), const ImplementsGetwd = false
|
||||
@@ -453,7 +457,3 @@ pkg syscall (freebsd-arm-cgo), type Stat_t struct, Nlink uint16
|
||||
pkg syscall (freebsd-arm-cgo), type Stat_t struct, Rdev uint32
|
||||
pkg syscall (freebsd-arm-cgo), type Statfs_t struct, Mntfromname [88]int8
|
||||
pkg syscall (freebsd-arm-cgo), type Statfs_t struct, Mntonname [88]int8
|
||||
pkg text/scanner, const GoTokens = 1012
|
||||
pkg unicode, const Version = "10.0.0"
|
||||
pkg unicode, const Version = "11.0.0"
|
||||
pkg unicode, const Version = "12.0.0"
|
||||
|
||||
8032
api/go1.13.txt
8032
api/go1.13.txt
File diff suppressed because it is too large
Load Diff
197
api/go1.14.txt
197
api/go1.14.txt
@@ -1,197 +0,0 @@
|
||||
pkg crypto/tls, const TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 52393
|
||||
pkg crypto/tls, const TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 uint16
|
||||
pkg crypto/tls, const TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 52392
|
||||
pkg crypto/tls, const TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 uint16
|
||||
pkg crypto/tls, func CipherSuiteName(uint16) string
|
||||
pkg crypto/tls, func CipherSuites() []*CipherSuite
|
||||
pkg crypto/tls, func InsecureCipherSuites() []*CipherSuite
|
||||
pkg crypto/tls, method (*CertificateRequestInfo) SupportsCertificate(*Certificate) error
|
||||
pkg crypto/tls, method (*ClientHelloInfo) SupportsCertificate(*Certificate) error
|
||||
pkg crypto/tls, type Certificate struct, SupportedSignatureAlgorithms []SignatureScheme
|
||||
pkg crypto/tls, type CertificateRequestInfo struct, Version uint16
|
||||
pkg crypto/tls, type CipherSuite struct
|
||||
pkg crypto/tls, type CipherSuite struct, ID uint16
|
||||
pkg crypto/tls, type CipherSuite struct, Insecure bool
|
||||
pkg crypto/tls, type CipherSuite struct, Name string
|
||||
pkg crypto/tls, type CipherSuite struct, SupportedVersions []uint16
|
||||
pkg debug/dwarf, const AttrAddrBase = 115
|
||||
pkg debug/dwarf, const AttrAddrBase Attr
|
||||
pkg debug/dwarf, const AttrAlignment = 136
|
||||
pkg debug/dwarf, const AttrAlignment Attr
|
||||
pkg debug/dwarf, const AttrBinaryScale = 91
|
||||
pkg debug/dwarf, const AttrBinaryScale Attr
|
||||
pkg debug/dwarf, const AttrCallAllCalls = 122
|
||||
pkg debug/dwarf, const AttrCallAllCalls Attr
|
||||
pkg debug/dwarf, const AttrCallAllSourceCalls = 123
|
||||
pkg debug/dwarf, const AttrCallAllSourceCalls Attr
|
||||
pkg debug/dwarf, const AttrCallAllTailCalls = 124
|
||||
pkg debug/dwarf, const AttrCallAllTailCalls Attr
|
||||
pkg debug/dwarf, const AttrCallDataLocation = 133
|
||||
pkg debug/dwarf, const AttrCallDataLocation Attr
|
||||
pkg debug/dwarf, const AttrCallDataValue = 134
|
||||
pkg debug/dwarf, const AttrCallDataValue Attr
|
||||
pkg debug/dwarf, const AttrCallOrigin = 127
|
||||
pkg debug/dwarf, const AttrCallOrigin Attr
|
||||
pkg debug/dwarf, const AttrCallPC = 129
|
||||
pkg debug/dwarf, const AttrCallPC Attr
|
||||
pkg debug/dwarf, const AttrCallParameter = 128
|
||||
pkg debug/dwarf, const AttrCallParameter Attr
|
||||
pkg debug/dwarf, const AttrCallReturnPC = 125
|
||||
pkg debug/dwarf, const AttrCallReturnPC Attr
|
||||
pkg debug/dwarf, const AttrCallTailCall = 130
|
||||
pkg debug/dwarf, const AttrCallTailCall Attr
|
||||
pkg debug/dwarf, const AttrCallTarget = 131
|
||||
pkg debug/dwarf, const AttrCallTarget Attr
|
||||
pkg debug/dwarf, const AttrCallTargetClobbered = 132
|
||||
pkg debug/dwarf, const AttrCallTargetClobbered Attr
|
||||
pkg debug/dwarf, const AttrCallValue = 126
|
||||
pkg debug/dwarf, const AttrCallValue Attr
|
||||
pkg debug/dwarf, const AttrConstExpr = 108
|
||||
pkg debug/dwarf, const AttrConstExpr Attr
|
||||
pkg debug/dwarf, const AttrDataBitOffset = 107
|
||||
pkg debug/dwarf, const AttrDataBitOffset Attr
|
||||
pkg debug/dwarf, const AttrDecimalScale = 92
|
||||
pkg debug/dwarf, const AttrDecimalScale Attr
|
||||
pkg debug/dwarf, const AttrDecimalSign = 94
|
||||
pkg debug/dwarf, const AttrDecimalSign Attr
|
||||
pkg debug/dwarf, const AttrDefaulted = 139
|
||||
pkg debug/dwarf, const AttrDefaulted Attr
|
||||
pkg debug/dwarf, const AttrDeleted = 138
|
||||
pkg debug/dwarf, const AttrDeleted Attr
|
||||
pkg debug/dwarf, const AttrDigitCount = 95
|
||||
pkg debug/dwarf, const AttrDigitCount Attr
|
||||
pkg debug/dwarf, const AttrDwoName = 118
|
||||
pkg debug/dwarf, const AttrDwoName Attr
|
||||
pkg debug/dwarf, const AttrElemental = 102
|
||||
pkg debug/dwarf, const AttrElemental Attr
|
||||
pkg debug/dwarf, const AttrEndianity = 101
|
||||
pkg debug/dwarf, const AttrEndianity Attr
|
||||
pkg debug/dwarf, const AttrEnumClass = 109
|
||||
pkg debug/dwarf, const AttrEnumClass Attr
|
||||
pkg debug/dwarf, const AttrExplicit = 99
|
||||
pkg debug/dwarf, const AttrExplicit Attr
|
||||
pkg debug/dwarf, const AttrExportSymbols = 137
|
||||
pkg debug/dwarf, const AttrExportSymbols Attr
|
||||
pkg debug/dwarf, const AttrLinkageName = 110
|
||||
pkg debug/dwarf, const AttrLinkageName Attr
|
||||
pkg debug/dwarf, const AttrLoclistsBase = 140
|
||||
pkg debug/dwarf, const AttrLoclistsBase Attr
|
||||
pkg debug/dwarf, const AttrMacros = 121
|
||||
pkg debug/dwarf, const AttrMacros Attr
|
||||
pkg debug/dwarf, const AttrMainSubprogram = 106
|
||||
pkg debug/dwarf, const AttrMainSubprogram Attr
|
||||
pkg debug/dwarf, const AttrMutable = 97
|
||||
pkg debug/dwarf, const AttrMutable Attr
|
||||
pkg debug/dwarf, const AttrNoreturn = 135
|
||||
pkg debug/dwarf, const AttrNoreturn Attr
|
||||
pkg debug/dwarf, const AttrObjectPointer = 100
|
||||
pkg debug/dwarf, const AttrObjectPointer Attr
|
||||
pkg debug/dwarf, const AttrPictureString = 96
|
||||
pkg debug/dwarf, const AttrPictureString Attr
|
||||
pkg debug/dwarf, const AttrPure = 103
|
||||
pkg debug/dwarf, const AttrPure Attr
|
||||
pkg debug/dwarf, const AttrRank = 113
|
||||
pkg debug/dwarf, const AttrRank Attr
|
||||
pkg debug/dwarf, const AttrRecursive = 104
|
||||
pkg debug/dwarf, const AttrRecursive Attr
|
||||
pkg debug/dwarf, const AttrReference = 119
|
||||
pkg debug/dwarf, const AttrReference Attr
|
||||
pkg debug/dwarf, const AttrRnglistsBase = 116
|
||||
pkg debug/dwarf, const AttrRnglistsBase Attr
|
||||
pkg debug/dwarf, const AttrRvalueReference = 120
|
||||
pkg debug/dwarf, const AttrRvalueReference Attr
|
||||
pkg debug/dwarf, const AttrSignature = 105
|
||||
pkg debug/dwarf, const AttrSignature Attr
|
||||
pkg debug/dwarf, const AttrSmall = 93
|
||||
pkg debug/dwarf, const AttrSmall Attr
|
||||
pkg debug/dwarf, const AttrStrOffsetsBase = 114
|
||||
pkg debug/dwarf, const AttrStrOffsetsBase Attr
|
||||
pkg debug/dwarf, const AttrStringLengthBitSize = 111
|
||||
pkg debug/dwarf, const AttrStringLengthBitSize Attr
|
||||
pkg debug/dwarf, const AttrStringLengthByteSize = 112
|
||||
pkg debug/dwarf, const AttrStringLengthByteSize Attr
|
||||
pkg debug/dwarf, const AttrThreadsScaled = 98
|
||||
pkg debug/dwarf, const AttrThreadsScaled Attr
|
||||
pkg debug/dwarf, const ClassAddrPtr = 15
|
||||
pkg debug/dwarf, const ClassAddrPtr Class
|
||||
pkg debug/dwarf, const ClassLocList = 16
|
||||
pkg debug/dwarf, const ClassLocList Class
|
||||
pkg debug/dwarf, const ClassRngList = 17
|
||||
pkg debug/dwarf, const ClassRngList Class
|
||||
pkg debug/dwarf, const ClassRngListsPtr = 18
|
||||
pkg debug/dwarf, const ClassRngListsPtr Class
|
||||
pkg debug/dwarf, const ClassStrOffsetsPtr = 19
|
||||
pkg debug/dwarf, const ClassStrOffsetsPtr Class
|
||||
pkg debug/dwarf, const TagAtomicType = 71
|
||||
pkg debug/dwarf, const TagAtomicType Tag
|
||||
pkg debug/dwarf, const TagCallSite = 72
|
||||
pkg debug/dwarf, const TagCallSite Tag
|
||||
pkg debug/dwarf, const TagCallSiteParameter = 73
|
||||
pkg debug/dwarf, const TagCallSiteParameter Tag
|
||||
pkg debug/dwarf, const TagCoarrayType = 68
|
||||
pkg debug/dwarf, const TagCoarrayType Tag
|
||||
pkg debug/dwarf, const TagDynamicType = 70
|
||||
pkg debug/dwarf, const TagDynamicType Tag
|
||||
pkg debug/dwarf, const TagGenericSubrange = 69
|
||||
pkg debug/dwarf, const TagGenericSubrange Tag
|
||||
pkg debug/dwarf, const TagImmutableType = 75
|
||||
pkg debug/dwarf, const TagImmutableType Tag
|
||||
pkg debug/dwarf, const TagSkeletonUnit = 74
|
||||
pkg debug/dwarf, const TagSkeletonUnit Tag
|
||||
pkg debug/dwarf, method (*Data) AddSection(string, []uint8) error
|
||||
pkg debug/dwarf, method (*LineReader) Files() []*LineFile
|
||||
pkg debug/dwarf, method (*Reader) ByteOrder() binary.ByteOrder
|
||||
pkg encoding/asn1, const TagBMPString = 30
|
||||
pkg encoding/asn1, const TagBMPString ideal-int
|
||||
pkg encoding/json, method (*Decoder) InputOffset() int64
|
||||
pkg go/build, type Context struct, Dir string
|
||||
pkg go/doc, func NewFromFiles(*token.FileSet, []*ast.File, string, ...interface{}) (*Package, error)
|
||||
pkg go/doc, type Example struct, Suffix string
|
||||
pkg go/doc, type Func struct, Examples []*Example
|
||||
pkg go/doc, type Package struct, Examples []*Example
|
||||
pkg go/doc, type Type struct, Examples []*Example
|
||||
pkg hash/maphash, func MakeSeed() Seed
|
||||
pkg hash/maphash, method (*Hash) BlockSize() int
|
||||
pkg hash/maphash, method (*Hash) Reset()
|
||||
pkg hash/maphash, method (*Hash) Seed() Seed
|
||||
pkg hash/maphash, method (*Hash) SetSeed(Seed)
|
||||
pkg hash/maphash, method (*Hash) Size() int
|
||||
pkg hash/maphash, method (*Hash) Sum([]uint8) []uint8
|
||||
pkg hash/maphash, method (*Hash) Sum64() uint64
|
||||
pkg hash/maphash, method (*Hash) Write([]uint8) (int, error)
|
||||
pkg hash/maphash, method (*Hash) WriteByte(uint8) error
|
||||
pkg hash/maphash, method (*Hash) WriteString(string) (int, error)
|
||||
pkg hash/maphash, type Hash struct
|
||||
pkg hash/maphash, type Seed struct
|
||||
pkg log, const Lmsgprefix = 64
|
||||
pkg log, const Lmsgprefix ideal-int
|
||||
pkg math, func FMA(float64, float64, float64) float64
|
||||
pkg math/bits, func Rem(uint, uint, uint) uint
|
||||
pkg math/bits, func Rem32(uint32, uint32, uint32) uint32
|
||||
pkg math/bits, func Rem64(uint64, uint64, uint64) uint64
|
||||
pkg mime/multipart, method (*Reader) NextRawPart() (*Part, error)
|
||||
pkg net/http, method (Header) Values(string) []string
|
||||
pkg net/http, type Transport struct, DialTLSContext func(context.Context, string, string) (net.Conn, error)
|
||||
pkg net/http/httptest, type Server struct, EnableHTTP2 bool
|
||||
pkg net/textproto, method (MIMEHeader) Values(string) []string
|
||||
pkg strconv, method (*NumError) Unwrap() error
|
||||
pkg syscall (windows-386), const CTRL_CLOSE_EVENT = 2
|
||||
pkg syscall (windows-386), const CTRL_CLOSE_EVENT ideal-int
|
||||
pkg syscall (windows-386), const CTRL_LOGOFF_EVENT = 5
|
||||
pkg syscall (windows-386), const CTRL_LOGOFF_EVENT ideal-int
|
||||
pkg syscall (windows-386), const CTRL_SHUTDOWN_EVENT = 6
|
||||
pkg syscall (windows-386), const CTRL_SHUTDOWN_EVENT ideal-int
|
||||
pkg syscall (windows-amd64), const CTRL_CLOSE_EVENT = 2
|
||||
pkg syscall (windows-amd64), const CTRL_CLOSE_EVENT ideal-int
|
||||
pkg syscall (windows-amd64), const CTRL_LOGOFF_EVENT = 5
|
||||
pkg syscall (windows-amd64), const CTRL_LOGOFF_EVENT ideal-int
|
||||
pkg syscall (windows-amd64), const CTRL_SHUTDOWN_EVENT = 6
|
||||
pkg syscall (windows-amd64), const CTRL_SHUTDOWN_EVENT ideal-int
|
||||
pkg testing, method (*B) Cleanup(func())
|
||||
pkg testing, method (*T) Cleanup(func())
|
||||
pkg testing, type TB interface, Cleanup(func())
|
||||
pkg unicode, const Version = "12.0.0"
|
||||
pkg unicode, var Elymaic *RangeTable
|
||||
pkg unicode, var Nandinagari *RangeTable
|
||||
pkg unicode, var Nyiakeng_Puachue_Hmong *RangeTable
|
||||
pkg unicode, var Wancho *RangeTable
|
||||
130
api/go1.15.txt
130
api/go1.15.txt
@@ -1,130 +0,0 @@
|
||||
pkg bufio, var ErrBadReadCount error
|
||||
pkg crypto, method (Hash) String() string
|
||||
pkg crypto/ecdsa, func SignASN1(io.Reader, *PrivateKey, []uint8) ([]uint8, error)
|
||||
pkg crypto/ecdsa, func VerifyASN1(*PublicKey, []uint8, []uint8) bool
|
||||
pkg crypto/ecdsa, method (*PrivateKey) Equal(crypto.PrivateKey) bool
|
||||
pkg crypto/ecdsa, method (*PublicKey) Equal(crypto.PublicKey) bool
|
||||
pkg crypto/ed25519, method (PrivateKey) Equal(crypto.PrivateKey) bool
|
||||
pkg crypto/ed25519, method (PublicKey) Equal(crypto.PublicKey) bool
|
||||
pkg crypto/elliptic, func MarshalCompressed(Curve, *big.Int, *big.Int) []uint8
|
||||
pkg crypto/elliptic, func UnmarshalCompressed(Curve, []uint8) (*big.Int, *big.Int)
|
||||
pkg crypto/rsa, method (*PrivateKey) Equal(crypto.PrivateKey) bool
|
||||
pkg crypto/rsa, method (*PublicKey) Equal(crypto.PublicKey) bool
|
||||
pkg crypto/tls, method (*Dialer) Dial(string, string) (net.Conn, error)
|
||||
pkg crypto/tls, method (*Dialer) DialContext(context.Context, string, string) (net.Conn, error)
|
||||
pkg crypto/tls, method (ClientAuthType) String() string
|
||||
pkg crypto/tls, method (CurveID) String() string
|
||||
pkg crypto/tls, method (SignatureScheme) String() string
|
||||
pkg crypto/tls, type Config struct, VerifyConnection func(ConnectionState) error
|
||||
pkg crypto/tls, type Dialer struct
|
||||
pkg crypto/tls, type Dialer struct, Config *Config
|
||||
pkg crypto/tls, type Dialer struct, NetDialer *net.Dialer
|
||||
pkg crypto/x509, func CreateRevocationList(io.Reader, *RevocationList, *Certificate, crypto.Signer) ([]uint8, error)
|
||||
pkg crypto/x509, type RevocationList struct
|
||||
pkg crypto/x509, type RevocationList struct, ExtraExtensions []pkix.Extension
|
||||
pkg crypto/x509, type RevocationList struct, NextUpdate time.Time
|
||||
pkg crypto/x509, type RevocationList struct, Number *big.Int
|
||||
pkg crypto/x509, type RevocationList struct, RevokedCertificates []pkix.RevokedCertificate
|
||||
pkg crypto/x509, type RevocationList struct, SignatureAlgorithm SignatureAlgorithm
|
||||
pkg crypto/x509, type RevocationList struct, ThisUpdate time.Time
|
||||
pkg database/sql, method (*DB) SetConnMaxIdleTime(time.Duration)
|
||||
pkg database/sql, method (*Row) Err() error
|
||||
pkg database/sql, type DBStats struct, MaxIdleTimeClosed int64
|
||||
pkg database/sql/driver, type Validator interface { IsValid }
|
||||
pkg database/sql/driver, type Validator interface, IsValid() bool
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_APPCONTAINER = 4096
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_APPCONTAINER ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE = 64
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY = 128
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_GUARD_CF = 16384
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_GUARD_CF ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA = 32
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_NO_BIND = 2048
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_NO_BIND ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_NO_ISOLATION = 512
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_NO_ISOLATION ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_NO_SEH = 1024
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_NO_SEH ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_NX_COMPAT = 256
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_NX_COMPAT ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = 32768
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE ideal-int
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = 8192
|
||||
pkg debug/pe, const IMAGE_DLLCHARACTERISTICS_WDM_DRIVER ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_32BIT_MACHINE = 256
|
||||
pkg debug/pe, const IMAGE_FILE_32BIT_MACHINE ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_AGGRESIVE_WS_TRIM = 16
|
||||
pkg debug/pe, const IMAGE_FILE_AGGRESIVE_WS_TRIM ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_BYTES_REVERSED_HI = 32768
|
||||
pkg debug/pe, const IMAGE_FILE_BYTES_REVERSED_HI ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_BYTES_REVERSED_LO = 128
|
||||
pkg debug/pe, const IMAGE_FILE_BYTES_REVERSED_LO ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_DEBUG_STRIPPED = 512
|
||||
pkg debug/pe, const IMAGE_FILE_DEBUG_STRIPPED ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_DLL = 8192
|
||||
pkg debug/pe, const IMAGE_FILE_DLL ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_EXECUTABLE_IMAGE = 2
|
||||
pkg debug/pe, const IMAGE_FILE_EXECUTABLE_IMAGE ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_LARGE_ADDRESS_AWARE = 32
|
||||
pkg debug/pe, const IMAGE_FILE_LARGE_ADDRESS_AWARE ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_LINE_NUMS_STRIPPED = 4
|
||||
pkg debug/pe, const IMAGE_FILE_LINE_NUMS_STRIPPED ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_LOCAL_SYMS_STRIPPED = 8
|
||||
pkg debug/pe, const IMAGE_FILE_LOCAL_SYMS_STRIPPED ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_NET_RUN_FROM_SWAP = 2048
|
||||
pkg debug/pe, const IMAGE_FILE_NET_RUN_FROM_SWAP ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_RELOCS_STRIPPED = 1
|
||||
pkg debug/pe, const IMAGE_FILE_RELOCS_STRIPPED ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 1024
|
||||
pkg debug/pe, const IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_SYSTEM = 4096
|
||||
pkg debug/pe, const IMAGE_FILE_SYSTEM ideal-int
|
||||
pkg debug/pe, const IMAGE_FILE_UP_SYSTEM_ONLY = 16384
|
||||
pkg debug/pe, const IMAGE_FILE_UP_SYSTEM_ONLY ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_EFI_APPLICATION = 10
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_EFI_APPLICATION ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_EFI_ROM = 13
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_EFI_ROM ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_NATIVE = 1
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_NATIVE ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_NATIVE_WINDOWS = 8
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_NATIVE_WINDOWS ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_OS2_CUI = 5
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_OS2_CUI ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_POSIX_CUI = 7
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_POSIX_CUI ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_UNKNOWN = 0
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_UNKNOWN ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_WINDOWS_CE_GUI ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_WINDOWS_CUI = 3
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_WINDOWS_CUI ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_WINDOWS_GUI = 2
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_WINDOWS_GUI ideal-int
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX = 14
|
||||
pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX ideal-int
|
||||
pkg math/big, method (*Int) FillBytes([]uint8) []uint8
|
||||
pkg net, method (*Resolver) LookupIP(context.Context, string, string) ([]IP, error)
|
||||
pkg net/url, method (*URL) EscapedFragment() string
|
||||
pkg net/url, method (*URL) Redacted() string
|
||||
pkg net/url, type URL struct, RawFragment string
|
||||
pkg os, method (*File) ReadFrom(io.Reader) (int64, error)
|
||||
pkg os, var ErrDeadlineExceeded error
|
||||
pkg regexp, method (*Regexp) SubexpIndex(string) int
|
||||
pkg strconv, func FormatComplex(complex128, uint8, int, int) string
|
||||
pkg strconv, func ParseComplex(string, int) (complex128, error)
|
||||
pkg sync, method (*Map) LoadAndDelete(interface{}) (interface{}, bool)
|
||||
pkg testing, method (*B) TempDir() string
|
||||
pkg testing, method (*T) Deadline() (time.Time, bool)
|
||||
pkg testing, method (*T) TempDir() string
|
||||
pkg testing, type TB interface, TempDir() string
|
||||
pkg time, method (*Ticker) Reset(Duration)
|
||||
19
api/next.txt
19
api/next.txt
@@ -1,19 +0,0 @@
|
||||
pkg unicode, const Version = "13.0.0"
|
||||
pkg unicode, var Chorasmian *RangeTable
|
||||
pkg unicode, var Dives_Akuru *RangeTable
|
||||
pkg unicode, var Khitan_Small_Script *RangeTable
|
||||
pkg unicode, var Yezidi *RangeTable
|
||||
pkg text/template/parse, const NodeComment = 20
|
||||
pkg text/template/parse, const NodeComment NodeType
|
||||
pkg text/template/parse, const ParseComments = 1
|
||||
pkg text/template/parse, const ParseComments Mode
|
||||
pkg text/template/parse, method (*CommentNode) Copy() Node
|
||||
pkg text/template/parse, method (*CommentNode) String() string
|
||||
pkg text/template/parse, method (CommentNode) Position() Pos
|
||||
pkg text/template/parse, method (CommentNode) Type() NodeType
|
||||
pkg text/template/parse, type CommentNode struct
|
||||
pkg text/template/parse, type CommentNode struct, Text string
|
||||
pkg text/template/parse, type CommentNode struct, embedded NodeType
|
||||
pkg text/template/parse, type CommentNode struct, embedded Pos
|
||||
pkg text/template/parse, type Mode uint
|
||||
pkg text/template/parse, type Tree struct, Mode Mode
|
||||
|
||||
@@ -74,7 +74,7 @@ important, the use of the tool itself.</p>
|
||||
<p>The <code>go</code> command requires that code adheres to a few key,
|
||||
well-established conventions.</p>
|
||||
|
||||
<p>First, the import path is derived in a known way from the URL of the
|
||||
<p>First, the import path is derived in an known way from the URL of the
|
||||
source code. For Bitbucket, GitHub, Google Code, and Launchpad, the
|
||||
root directory of the repository is identified by the repository's
|
||||
main URL, without the <code>http://</code> prefix. Subdirectories are named by
|
||||
|
||||
@@ -133,11 +133,6 @@ cost of increased memory usage.
|
||||
<code>halt_on_error</code> (default <code>0</code>): Controls whether the program
|
||||
exits after reporting first data race.
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<code>atexit_sleep_ms</code> (default <code>1000</code>): Amount of milliseconds
|
||||
to sleep in the main goroutine before exiting.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
@@ -379,46 +374,11 @@ func (w *Watchdog) Start() {
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h3 id="Unsynchronized_send_and_close_operations">Unsynchronized send and close operations</h3>
|
||||
|
||||
<p>
|
||||
As this example demonstrates, unsynchronized send and close operations
|
||||
on the same channel can also be a race condition:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
c := make(chan struct{}) // or buffered channel
|
||||
|
||||
// The race detector cannot derive the happens before relation
|
||||
// for the following send and close operations. These two operations
|
||||
// are unsynchronized and happen concurrently.
|
||||
go func() { c <- struct{}{} }()
|
||||
close(c)
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
According to the Go memory model, a send on a channel happens before
|
||||
the corresponding receive from that channel completes. To synchronize
|
||||
send and close operations, use a receive operation that guarantees
|
||||
the send is done before the close:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
c := make(chan struct{}) // or buffered channel
|
||||
|
||||
go func() { c <- struct{}{} }()
|
||||
<-c
|
||||
close(c)
|
||||
</pre>
|
||||
|
||||
<h2 id="Supported_Systems">Supported Systems</h2>
|
||||
|
||||
<p>
|
||||
The race detector runs on
|
||||
<code>linux/amd64</code>, <code>linux/ppc64le</code>,
|
||||
<code>linux/arm64</code>, <code>freebsd/amd64</code>,
|
||||
<code>netbsd/amd64</code>, <code>darwin/amd64</code>,
|
||||
and <code>windows/amd64</code>.
|
||||
The race detector runs on <code>darwin/amd64</code>, <code>freebsd/amd64</code>,
|
||||
<code>linux/amd64</code>, and <code>windows/amd64</code>.
|
||||
</p>
|
||||
|
||||
<h2 id="Runtime_Overheads">Runtime Overhead</h2>
|
||||
@@ -427,14 +387,3 @@ close(c)
|
||||
The cost of race detection varies by program, but for a typical program, memory
|
||||
usage may increase by 5-10x and execution time by 2-20x.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The race detector currently allocates an extra 8 bytes per <code>defer</code>
|
||||
and <code>recover</code> statement. Those extra allocations <a
|
||||
href="https://golang.org/issue/26813">are not recovered until the goroutine
|
||||
exits</a>. This means that if you have a long-running goroutine that is
|
||||
periodically issuing <code>defer</code> and <code>recover</code> calls,
|
||||
the program memory usage may grow without bound. These memory allocations
|
||||
will not show up in the output of <code>runtime.ReadMemStats</code> or
|
||||
<code>runtime/pprof</code>.
|
||||
</p>
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -92,7 +90,7 @@ func getTitle(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||
m := validPath.FindStringSubmatch(r.URL.Path)
|
||||
if m == nil {
|
||||
http.NotFound(w, r)
|
||||
return "", errors.New("invalid Page Title")
|
||||
return "", errors.New("Invalid Page Title")
|
||||
}
|
||||
return m[2], nil // The title is the second subexpression.
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
27
doc/articles/wiki/final-test.patch
Normal file
27
doc/articles/wiki/final-test.patch
Normal file
@@ -0,0 +1,27 @@
|
||||
--- final.go 2017-08-31 13:19:00.422925489 -0700
|
||||
+++ final-test.go 2017-08-31 13:23:43.381391659 -0700
|
||||
@@ -8,6 +8,7 @@
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
+ "net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
@@ -86,5 +87,15 @@
|
||||
http.HandleFunc("/edit/", makeHandler(editHandler))
|
||||
http.HandleFunc("/save/", makeHandler(saveHandler))
|
||||
|
||||
- log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
+ l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
+ if err != nil {
|
||||
+ log.Fatal(err)
|
||||
+ }
|
||||
+ err = ioutil.WriteFile("final-test-port.txt", []byte(l.Addr().String()), 0644)
|
||||
+ if err != nil {
|
||||
+ log.Fatal(err)
|
||||
+ }
|
||||
+ s := &http.Server{}
|
||||
+ s.Serve(l)
|
||||
+ return
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func serve() error {
|
||||
l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(l.Addr().String())
|
||||
s := &http.Server{}
|
||||
return s.Serve(l)
|
||||
}
|
||||
63
doc/articles/wiki/get.go
Normal file
63
doc/articles/wiki/get.go
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
post = flag.String("post", "", "urlencoded form data to POST")
|
||||
addr = flag.Bool("addr", false, "find open address and print to stdout")
|
||||
wait = flag.Duration("wait_for_port", 0, "if non-zero, the amount of time to wait for the address to become available")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *addr {
|
||||
l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer l.Close()
|
||||
fmt.Print(l.Addr())
|
||||
return
|
||||
}
|
||||
url := flag.Arg(0)
|
||||
if url == "" {
|
||||
log.Fatal("no url supplied")
|
||||
}
|
||||
var r *http.Response
|
||||
var err error
|
||||
loopUntil := time.Now().Add(*wait)
|
||||
for {
|
||||
if *post != "" {
|
||||
b := strings.NewReader(*post)
|
||||
r, err = http.Post(url, "application/x-www-form-urlencoded", b)
|
||||
} else {
|
||||
r, err = http.Get(url)
|
||||
}
|
||||
if err == nil || *wait == 0 || time.Now().After(loopUntil) {
|
||||
break
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer r.Body.Close()
|
||||
_, err = io.Copy(os.Stdout, r.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module doc/articles/wiki
|
||||
|
||||
go 1.14
|
||||
@@ -1,5 +1,3 @@
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -257,7 +257,6 @@ To use the <code>net/http</code> package, it must be imported:
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
<b>"net/http"</b>
|
||||
)
|
||||
</pre>
|
||||
@@ -582,7 +581,7 @@ this, we can write a function to validate the title with a regular expression.
|
||||
|
||||
<p>
|
||||
First, add <code>"regexp"</code> to the <code>import</code> list.
|
||||
Then we can create a global variable to store our validation
|
||||
Then we can create a global variable to store our validation
|
||||
expression:
|
||||
</p>
|
||||
|
||||
@@ -675,7 +674,7 @@ The closure returned by <code>makeHandler</code> is a function that takes
|
||||
an <code>http.ResponseWriter</code> and <code>http.Request</code> (in other
|
||||
words, an <code>http.HandlerFunc</code>).
|
||||
The closure extracts the <code>title</code> from the request path, and
|
||||
validates it with the <code>validPath</code> regexp. If the
|
||||
validates it with the <code>TitleValidator</code> regexp. If the
|
||||
<code>title</code> is invalid, an error will be written to the
|
||||
<code>ResponseWriter</code> using the <code>http.NotFound</code> function.
|
||||
If the <code>title</code> is valid, the enclosed handler function
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
58
doc/articles/wiki/test.bash
Executable file
58
doc/articles/wiki/test.bash
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2010 The Go Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
set -e
|
||||
|
||||
if ! which patch > /dev/null; then
|
||||
echo "Skipping test; patch command not found."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
wiki_pid=
|
||||
cleanup() {
|
||||
kill $wiki_pid
|
||||
rm -f test_*.out Test.txt final-test.go final-test.bin final-test-port.txt a.out get.bin
|
||||
}
|
||||
trap cleanup 0 INT
|
||||
|
||||
rm -f get.bin final-test.bin a.out
|
||||
|
||||
# If called with -all, check that all code snippets compile.
|
||||
if [ "$1" = "-all" ]; then
|
||||
for fn in *.go; do
|
||||
go build -o a.out $fn
|
||||
done
|
||||
fi
|
||||
|
||||
go build -o get.bin get.go
|
||||
cp final.go final-test.go
|
||||
patch final-test.go final-test.patch > /dev/null
|
||||
go build -o final-test.bin final-test.go
|
||||
./final-test.bin &
|
||||
wiki_pid=$!
|
||||
|
||||
l=0
|
||||
while [ ! -f ./final-test-port.txt ]
|
||||
do
|
||||
l=$(($l+1))
|
||||
if [ "$l" -gt 5 ]
|
||||
then
|
||||
echo "port not available within 5 seconds"
|
||||
exit 1
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
addr=$(cat final-test-port.txt)
|
||||
./get.bin http://$addr/edit/Test > test_edit.out
|
||||
diff -u test_edit.out test_edit.good
|
||||
./get.bin -post=body=some%20content http://$addr/save/Test > test_save.out
|
||||
diff -u test_save.out test_view.good # should be the same as viewing
|
||||
diff -u Test.txt test_Test.txt.good
|
||||
./get.bin http://$addr/view/Test > test_view.out
|
||||
diff -u test_view.out test_view.good
|
||||
|
||||
echo PASS
|
||||
@@ -1,165 +0,0 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSnippetsCompile(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping slow builds in short mode")
|
||||
}
|
||||
|
||||
goFiles, err := filepath.Glob("*.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, f := range goFiles {
|
||||
if strings.HasSuffix(f, "_test.go") {
|
||||
continue
|
||||
}
|
||||
f := f
|
||||
t.Run(f, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cmd := exec.Command("go", "build", "-o", os.DevNull, f)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, out)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWikiServer(t *testing.T) {
|
||||
must := func(err error) {
|
||||
if err != nil {
|
||||
t.Helper()
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
dir, err := ioutil.TempDir("", t.Name())
|
||||
must(err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
// We're testing a walkthrough example of how to write a server.
|
||||
//
|
||||
// That server hard-codes a port number to make the walkthrough simpler, but
|
||||
// we can't assume that the hard-coded port is available on an arbitrary
|
||||
// builder. So we'll patch out the hard-coded port, and replace it with a
|
||||
// function that writes the server's address to stdout
|
||||
// so that we can read it and know where to send the test requests.
|
||||
|
||||
finalGo, err := ioutil.ReadFile("final.go")
|
||||
must(err)
|
||||
const patchOld = `log.Fatal(http.ListenAndServe(":8080", nil))`
|
||||
patched := bytes.ReplaceAll(finalGo, []byte(patchOld), []byte(`log.Fatal(serve())`))
|
||||
if bytes.Equal(patched, finalGo) {
|
||||
t.Fatalf("Can't patch final.go: %q not found.", patchOld)
|
||||
}
|
||||
must(ioutil.WriteFile(filepath.Join(dir, "final_patched.go"), patched, 0644))
|
||||
|
||||
// Build the server binary from the patched sources.
|
||||
// The 'go' command requires that they all be in the same directory.
|
||||
// final_test.go provides the implemtation for our serve function.
|
||||
must(copyFile(filepath.Join(dir, "final_srv.go"), "final_test.go"))
|
||||
cmd := exec.Command("go", "build",
|
||||
"-o", filepath.Join(dir, "final.exe"),
|
||||
filepath.Join(dir, "final_patched.go"),
|
||||
filepath.Join(dir, "final_srv.go"))
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, out)
|
||||
}
|
||||
|
||||
// Run the server in our temporary directory so that it can
|
||||
// write its content there. It also needs a couple of template files,
|
||||
// and looks for them in the same directory.
|
||||
must(copyFile(filepath.Join(dir, "edit.html"), "edit.html"))
|
||||
must(copyFile(filepath.Join(dir, "view.html"), "view.html"))
|
||||
cmd = exec.Command(filepath.Join(dir, "final.exe"))
|
||||
cmd.Dir = dir
|
||||
stderr := bytes.NewBuffer(nil)
|
||||
cmd.Stderr = stderr
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
must(err)
|
||||
must(cmd.Start())
|
||||
|
||||
defer func() {
|
||||
cmd.Process.Kill()
|
||||
err := cmd.Wait()
|
||||
if stderr.Len() > 0 {
|
||||
t.Logf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, stderr)
|
||||
}
|
||||
}()
|
||||
|
||||
var addr string
|
||||
if _, err := fmt.Fscanln(stdout, &addr); err != nil || addr == "" {
|
||||
t.Fatalf("Failed to read server address: %v", err)
|
||||
}
|
||||
|
||||
// The server is up and has told us its address.
|
||||
// Make sure that its HTTP API works as described in the article.
|
||||
|
||||
r, err := http.Get(fmt.Sprintf("http://%s/edit/Test", addr))
|
||||
must(err)
|
||||
responseMustMatchFile(t, r, "test_edit.good")
|
||||
|
||||
r, err = http.Post(fmt.Sprintf("http://%s/save/Test", addr),
|
||||
"application/x-www-form-urlencoded",
|
||||
strings.NewReader("body=some%20content"))
|
||||
must(err)
|
||||
responseMustMatchFile(t, r, "test_view.good")
|
||||
|
||||
gotTxt, err := ioutil.ReadFile(filepath.Join(dir, "Test.txt"))
|
||||
must(err)
|
||||
wantTxt, err := ioutil.ReadFile("test_Test.txt.good")
|
||||
must(err)
|
||||
if !bytes.Equal(wantTxt, gotTxt) {
|
||||
t.Fatalf("Test.txt differs from expected after posting to /save.\ngot:\n%s\nwant:\n%s", gotTxt, wantTxt)
|
||||
}
|
||||
|
||||
r, err = http.Get(fmt.Sprintf("http://%s/view/Test", addr))
|
||||
must(err)
|
||||
responseMustMatchFile(t, r, "test_view.good")
|
||||
}
|
||||
|
||||
func responseMustMatchFile(t *testing.T, r *http.Response, filename string) {
|
||||
t.Helper()
|
||||
|
||||
defer r.Body.Close()
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
wantBody, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(body, wantBody) {
|
||||
t.Fatalf("%v: body does not match %s.\ngot:\n%s\nwant:\n%s", r.Request.URL, filename, body, wantBody)
|
||||
}
|
||||
}
|
||||
|
||||
func copyFile(dst, src string) error {
|
||||
buf, err := ioutil.ReadFile(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(dst, buf, 0644)
|
||||
}
|
||||
158
doc/asm.html
158
doc/asm.html
@@ -57,66 +57,59 @@ func main() {
|
||||
println(3)
|
||||
}
|
||||
$ GOOS=linux GOARCH=amd64 go tool compile -S x.go # or: go build -gcflags -S x.go
|
||||
"".main STEXT size=74 args=0x0 locals=0x10
|
||||
0x0000 00000 (x.go:3) TEXT "".main(SB), $16-0
|
||||
0x0000 00000 (x.go:3) MOVQ (TLS), CX
|
||||
0x0009 00009 (x.go:3) CMPQ SP, 16(CX)
|
||||
0x000d 00013 (x.go:3) JLS 67
|
||||
0x000f 00015 (x.go:3) SUBQ $16, SP
|
||||
0x0013 00019 (x.go:3) MOVQ BP, 8(SP)
|
||||
0x0018 00024 (x.go:3) LEAQ 8(SP), BP
|
||||
0x001d 00029 (x.go:3) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
|
||||
0x001d 00029 (x.go:3) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
|
||||
0x001d 00029 (x.go:3) FUNCDATA $2, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
|
||||
0x001d 00029 (x.go:4) PCDATA $0, $0
|
||||
0x001d 00029 (x.go:4) PCDATA $1, $0
|
||||
0x001d 00029 (x.go:4) CALL runtime.printlock(SB)
|
||||
0x0022 00034 (x.go:4) MOVQ $3, (SP)
|
||||
0x002a 00042 (x.go:4) CALL runtime.printint(SB)
|
||||
0x002f 00047 (x.go:4) CALL runtime.printnl(SB)
|
||||
0x0034 00052 (x.go:4) CALL runtime.printunlock(SB)
|
||||
0x0039 00057 (x.go:5) MOVQ 8(SP), BP
|
||||
0x003e 00062 (x.go:5) ADDQ $16, SP
|
||||
0x0042 00066 (x.go:5) RET
|
||||
0x0043 00067 (x.go:5) NOP
|
||||
0x0043 00067 (x.go:3) PCDATA $1, $-1
|
||||
0x0043 00067 (x.go:3) PCDATA $0, $-1
|
||||
0x0043 00067 (x.go:3) CALL runtime.morestack_noctxt(SB)
|
||||
0x0048 00072 (x.go:3) JMP 0
|
||||
|
||||
--- prog list "main" ---
|
||||
0000 (x.go:3) TEXT main+0(SB),$8-0
|
||||
0001 (x.go:3) FUNCDATA $0,gcargs·0+0(SB)
|
||||
0002 (x.go:3) FUNCDATA $1,gclocals·0+0(SB)
|
||||
0003 (x.go:4) MOVQ $3,(SP)
|
||||
0004 (x.go:4) PCDATA $0,$8
|
||||
0005 (x.go:4) CALL ,runtime.printint+0(SB)
|
||||
0006 (x.go:4) PCDATA $0,$-1
|
||||
0007 (x.go:4) PCDATA $0,$0
|
||||
0008 (x.go:4) CALL ,runtime.printnl+0(SB)
|
||||
0009 (x.go:4) PCDATA $0,$-1
|
||||
0010 (x.go:5) RET ,
|
||||
...
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
The <code>FUNCDATA</code> and <code>PCDATA</code> directives contain information
|
||||
for use by the garbage collector; they are introduced by the compiler.
|
||||
</p>
|
||||
</p>
|
||||
|
||||
<!-- Commenting out because the feature is gone but it's popular and may come back.
|
||||
|
||||
<p>
|
||||
To see what gets put in the binary after linking, use <code>go tool objdump</code>:
|
||||
To see what gets put in the binary after linking, add the <code>-a</code> flag to the linker:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ go build -o x.exe x.go
|
||||
$ go tool objdump -s main.main x.exe
|
||||
TEXT main.main(SB) /tmp/x.go
|
||||
x.go:3 0x10501c0 65488b0c2530000000 MOVQ GS:0x30, CX
|
||||
x.go:3 0x10501c9 483b6110 CMPQ 0x10(CX), SP
|
||||
x.go:3 0x10501cd 7634 JBE 0x1050203
|
||||
x.go:3 0x10501cf 4883ec10 SUBQ $0x10, SP
|
||||
x.go:3 0x10501d3 48896c2408 MOVQ BP, 0x8(SP)
|
||||
x.go:3 0x10501d8 488d6c2408 LEAQ 0x8(SP), BP
|
||||
x.go:4 0x10501dd e86e45fdff CALL runtime.printlock(SB)
|
||||
x.go:4 0x10501e2 48c7042403000000 MOVQ $0x3, 0(SP)
|
||||
x.go:4 0x10501ea e8e14cfdff CALL runtime.printint(SB)
|
||||
x.go:4 0x10501ef e8ec47fdff CALL runtime.printnl(SB)
|
||||
x.go:4 0x10501f4 e8d745fdff CALL runtime.printunlock(SB)
|
||||
x.go:5 0x10501f9 488b6c2408 MOVQ 0x8(SP), BP
|
||||
x.go:5 0x10501fe 4883c410 ADDQ $0x10, SP
|
||||
x.go:5 0x1050202 c3 RET
|
||||
x.go:3 0x1050203 e83882ffff CALL runtime.morestack_noctxt(SB)
|
||||
x.go:3 0x1050208 ebb6 JMP main.main(SB)
|
||||
$ go tool 6l -a x.6 # or: go build -ldflags -a x.go
|
||||
codeblk [0x2000,0x1d059) at offset 0x1000
|
||||
002000 main.main | (3) TEXT main.main+0(SB),$8
|
||||
002000 65488b0c25a0080000 | (3) MOVQ 2208(GS),CX
|
||||
002009 483b21 | (3) CMPQ SP,(CX)
|
||||
00200c 7707 | (3) JHI ,2015
|
||||
00200e e83da20100 | (3) CALL ,1c250+runtime.morestack00
|
||||
002013 ebeb | (3) JMP ,2000
|
||||
002015 4883ec08 | (3) SUBQ $8,SP
|
||||
002019 | (3) FUNCDATA $0,main.gcargs·0+0(SB)
|
||||
002019 | (3) FUNCDATA $1,main.gclocals·0+0(SB)
|
||||
002019 48c7042403000000 | (4) MOVQ $3,(SP)
|
||||
002021 | (4) PCDATA $0,$8
|
||||
002021 e8aad20000 | (4) CALL ,f2d0+runtime.printint
|
||||
002026 | (4) PCDATA $0,$-1
|
||||
002026 | (4) PCDATA $0,$0
|
||||
002026 e865d40000 | (4) CALL ,f490+runtime.printnl
|
||||
00202b | (4) PCDATA $0,$-1
|
||||
00202b 4883c408 | (5) ADDQ $8,SP
|
||||
00202f c3 | (5) RET ,
|
||||
...
|
||||
</pre>
|
||||
|
||||
-->
|
||||
|
||||
<h3 id="constants">Constants</h3>
|
||||
|
||||
<p>
|
||||
@@ -273,7 +266,7 @@ that assembly programming is a fraught endeavor.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
In Go object files and binaries, the full name of a symbol is the
|
||||
In Go object files and binaries, the full name of a symbol is the
|
||||
package path followed by a period and the symbol name:
|
||||
<code>fmt.Printf</code> or <code>math/rand.Int</code>.
|
||||
Because the assembler's parser treats period and slash as punctuation,
|
||||
@@ -437,31 +430,6 @@ This is a wrapper function and should not count as disabling <code>recover</code
|
||||
(For <code>TEXT</code> items.)
|
||||
This function is a closure so it uses its incoming context register.
|
||||
</li>
|
||||
<li>
|
||||
<code>LOCAL</code> = 128
|
||||
<br>
|
||||
This symbol is local to the dynamic shared object.
|
||||
</li>
|
||||
<li>
|
||||
<code>TLSBSS</code> = 256
|
||||
<br>
|
||||
(For <code>DATA</code> and <code>GLOBL</code> items.)
|
||||
Put this data in thread local storage.
|
||||
</li>
|
||||
<li>
|
||||
<code>NOFRAME</code> = 512
|
||||
<br>
|
||||
(For <code>TEXT</code> items.)
|
||||
Do not insert instructions to allocate a stack frame and save/restore the return
|
||||
address, even if this is not a leaf function.
|
||||
Only valid on functions that declare a frame size of 0.
|
||||
</li>
|
||||
<li>
|
||||
<code>TOPFRAME</code> = 2048
|
||||
<br>
|
||||
(For <code>TEXT</code> items.)
|
||||
Function is the top of the call stack. Traceback should stop at this function.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3 id="runtime">Runtime Coordination</h3>
|
||||
@@ -517,7 +485,7 @@ even for assembly functions not called directly from Go.
|
||||
At the start of the function, the arguments are assumed
|
||||
to be initialized but the results are assumed uninitialized.
|
||||
If the results will hold live pointers during a call instruction,
|
||||
the function should start by zeroing the results and then
|
||||
the function should start by zeroing the results and then
|
||||
executing the pseudo-instruction <code>GO_RESULTS_INITIALIZED</code>.
|
||||
This instruction records that the results are now initialized
|
||||
and should be scanned during stack movement and garbage collection.
|
||||
@@ -535,7 +503,7 @@ on the <code>TEXT</code> instruction.
|
||||
The pointer information can also be omitted if the
|
||||
function contains no call instructions.
|
||||
Otherwise, the local stack frame must not contain pointers,
|
||||
and the assembly must confirm this fact by executing the
|
||||
and the assembly must confirm this fact by executing the
|
||||
pseudo-instruction <code>NO_LOCAL_POINTERS</code>.
|
||||
Because stack resizing is implemented by moving the stack,
|
||||
the stack pointer may change during any function call:
|
||||
@@ -615,37 +583,27 @@ Here follow some descriptions of key Go-specific details for the supported archi
|
||||
<p>
|
||||
The runtime pointer to the <code>g</code> structure is maintained
|
||||
through the value of an otherwise unused (as far as Go is concerned) register in the MMU.
|
||||
An OS-dependent macro <code>get_tls</code> is defined for the assembler if the source is
|
||||
in the <code>runtime</code> package and includes a special header, <code>go_tls.h</code>:
|
||||
A OS-dependent macro <code>get_tls</code> is defined for the assembler if the source includes
|
||||
a special header, <code>go_asm.h</code>:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
#include "go_tls.h"
|
||||
#include "go_asm.h"
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Within the runtime, the <code>get_tls</code> macro loads its argument register
|
||||
with a pointer to the <code>g</code> pointer, and the <code>g</code> struct
|
||||
contains the <code>m</code> pointer.
|
||||
There's another special header containing the offsets for each
|
||||
element of <code>g</code>, called <code>go_asm.h</code>.
|
||||
The sequence to load <code>g</code> and <code>m</code> using <code>CX</code> looks like this:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
#include "go_tls.h"
|
||||
#include "go_asm.h"
|
||||
...
|
||||
get_tls(CX)
|
||||
MOVL g(CX), AX // Move g into AX.
|
||||
MOVL g_m(AX), BX // Move g.m into BX.
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Note: The code above works only in the <code>runtime</code> package, while <code>go_tls.h</code> also
|
||||
applies to <a href="#arm">arm</a>, <a href="#amd64">amd64</a> and amd64p32, and <code>go_asm.h</code> applies to all architectures.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Addressing modes:
|
||||
</p>
|
||||
@@ -687,13 +645,6 @@ MOVQ g(CX), AX // Move g into AX.
|
||||
MOVQ g_m(AX), BX // Move g.m into BX.
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Register <code>BP</code> is callee-save.
|
||||
The assembler automatically inserts <code>BP</code> save/restore when frame size is larger than zero.
|
||||
Using <code>BP</code> as a general purpose register is allowed,
|
||||
however it can interfere with sampling-based profiling.
|
||||
</p>
|
||||
|
||||
<h3 id="arm">ARM</h3>
|
||||
|
||||
<p>
|
||||
@@ -864,16 +815,27 @@ The other extensions include <code>SXTH</code> (16-bit), <code>SXTW</code> (32-b
|
||||
Reference: <a href="/pkg/cmd/internal/obj/arm64">Go ARM64 Assembly Instructions Reference Manual</a>
|
||||
</p>
|
||||
|
||||
<h3 id="ppc64">PPC64</h3>
|
||||
<h3 id="ppc64">64-bit PowerPC, a.k.a. ppc64</h3>
|
||||
|
||||
<p>
|
||||
This assembler is used by GOARCH values ppc64 and ppc64le.
|
||||
The 64-bit PowerPC port is in an experimental state.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Reference: <a href="/pkg/cmd/internal/obj/ppc64">Go PPC64 Assembly Instructions Reference Manual</a>
|
||||
Addressing modes:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
|
||||
<li>
|
||||
<code>(R5)(R6*1)</code>: The location at <code>R5</code> plus <code>R6</code>. It is a scaled
|
||||
mode as on the x86, but the only scale allowed is <code>1</code>.
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<code>(R5+R6)</code>: Alias for (R5)(R6*1)
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<h3 id="s390x">IBM z/Architecture, a.k.a. s390x</h3>
|
||||
|
||||
@@ -49,6 +49,7 @@ The <code>go</code> program manages Go source code and runs the other
|
||||
commands listed here.
|
||||
See the command docs for usage
|
||||
details.
|
||||
<br><br>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
648
doc/code.html
Normal file
648
doc/code.html
Normal file
@@ -0,0 +1,648 @@
|
||||
<!--{
|
||||
"Title": "How to Write Go Code"
|
||||
}-->
|
||||
|
||||
<h2 id="Introduction">Introduction</h2>
|
||||
|
||||
<p>
|
||||
This document demonstrates the development of a simple Go package and
|
||||
introduces the <a href="/cmd/go/">go tool</a>, the standard way to fetch,
|
||||
build, and install Go packages and commands.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The <code>go</code> tool requires you to organize your code in a specific
|
||||
way. Please read this document carefully.
|
||||
It explains the simplest way to get up and running with your Go installation.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A similar explanation is available as a
|
||||
<a href="//www.youtube.com/watch?v=XCsL89YtqCs">screencast</a>.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="Organization">Code organization</h2>
|
||||
|
||||
<h3 id="Overview">Overview</h3>
|
||||
|
||||
<ul>
|
||||
<li>Go programmers typically keep all their Go code in a single <i>workspace</i>.</li>
|
||||
<li>A workspace contains many version control <i>repositories</i>
|
||||
(managed by Git, for example).</li>
|
||||
<li>Each repository contains one or more <i>packages</i>.</li>
|
||||
<li>Each package consists of one or more Go source files in a single directory.</li>
|
||||
<li>The path to a package's directory determines its <i>import path</i>.</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
Note that this differs from other programming environments in which every
|
||||
project has a separate workspace and workspaces are closely tied to version
|
||||
control repositories.
|
||||
</p>
|
||||
|
||||
<h3 id="Workspaces">Workspaces</h3>
|
||||
|
||||
<p>
|
||||
A workspace is a directory hierarchy with two directories at its root:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li><code>src</code> contains Go source files, and
|
||||
<li><code>bin</code> contains executable commands.
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
The <code>go</code> tool builds and installs binaries to the <code>bin</code> directory.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The <code>src</code> subdirectory typically contains multiple version control
|
||||
repositories (such as for Git or Mercurial) that track the development of one
|
||||
or more source packages.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To give you an idea of how a workspace looks in practice, here's an example:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
bin/
|
||||
hello # command executable
|
||||
outyet # command executable
|
||||
src/
|
||||
<a href="https://github.com/golang/example/">github.com/golang/example/</a>
|
||||
.git/ # Git repository metadata
|
||||
hello/
|
||||
hello.go # command source
|
||||
outyet/
|
||||
main.go # command source
|
||||
main_test.go # test source
|
||||
stringutil/
|
||||
reverse.go # package source
|
||||
reverse_test.go # test source
|
||||
<a href="https://golang.org/x/image/">golang.org/x/image/</a>
|
||||
.git/ # Git repository metadata
|
||||
bmp/
|
||||
reader.go # package source
|
||||
writer.go # package source
|
||||
... (many more repositories and packages omitted) ...
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
The tree above shows a workspace containing two repositories
|
||||
(<code>example</code> and <code>image</code>).
|
||||
The <code>example</code> repository contains two commands (<code>hello</code>
|
||||
and <code>outyet</code>) and one library (<code>stringutil</code>).
|
||||
The <code>image</code> repository contains the <code>bmp</code> package
|
||||
and <a href="https://godoc.org/golang.org/x/image">several others</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A typical workspace contains many source repositories containing many
|
||||
packages and commands. Most Go programmers keep <i>all</i> their Go source code
|
||||
and dependencies in a single workspace.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Note that symbolic links should <b>not</b> be used to link files or directories into your workspace.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Commands and libraries are built from different kinds of source packages.
|
||||
We will discuss the distinction <a href="#PackageNames">later</a>.
|
||||
</p>
|
||||
|
||||
|
||||
<h3 id="GOPATH">The <code>GOPATH</code> environment variable</h3>
|
||||
|
||||
<p>
|
||||
The <code>GOPATH</code> environment variable specifies the location of your
|
||||
workspace. It defaults to a directory named <code>go</code> inside your home directory,
|
||||
so <code>$HOME/go</code> on Unix,
|
||||
<code>$home/go</code> on Plan 9,
|
||||
and <code>%USERPROFILE%\go</code> (usually <code>C:\Users\YourName\go</code>) on Windows.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you would like to work in a different location, you will need to
|
||||
<a href="https://golang.org/wiki/SettingGOPATH">set <code>GOPATH</code></a>
|
||||
to the path to that directory.
|
||||
(Another common setup is to set <code>GOPATH=$HOME</code>.)
|
||||
Note that <code>GOPATH</code> must <b>not</b> be the
|
||||
same path as your Go installation.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The command <code>go</code> <code>env</code> <code>GOPATH</code>
|
||||
prints the effective current <code>GOPATH</code>;
|
||||
it prints the default location if the environment variable is unset.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For convenience, add the workspace's <code>bin</code> subdirectory
|
||||
to your <code>PATH</code>:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>export PATH=$PATH:$(go env GOPATH)/bin</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
The scripts in the rest of this document use <code>$GOPATH</code>
|
||||
instead of <code>$(go env GOPATH)</code> for brevity.
|
||||
To make the scripts run as written
|
||||
if you have not set GOPATH,
|
||||
you can substitute $HOME/go in those commands
|
||||
or else run:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>export GOPATH=$(go env GOPATH)</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
To learn more about the <code>GOPATH</code> environment variable, see
|
||||
<a href="/cmd/go/#hdr-GOPATH_environment_variable"><code>'go help gopath'</code></a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To use a custom workspace location,
|
||||
<a href="https://golang.org/wiki/SettingGOPATH">set the <code>GOPATH</code> environment variable</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="ImportPaths">Import paths</h3>
|
||||
|
||||
<p>
|
||||
An <i>import path</i> is a string that uniquely identifies a package.
|
||||
A package's import path corresponds to its location inside a workspace
|
||||
or in a remote repository (explained below).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The packages from the standard library are given short import paths such as
|
||||
<code>"fmt"</code> and <code>"net/http"</code>.
|
||||
For your own packages, you must choose a base path that is unlikely to
|
||||
collide with future additions to the standard library or other external
|
||||
libraries.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you keep your code in a source repository somewhere, then you should use the
|
||||
root of that source repository as your base path.
|
||||
For instance, if you have a <a href="https://github.com/">GitHub</a> account at
|
||||
<code>github.com/user</code>, that should be your base path.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Note that you don't need to publish your code to a remote repository before you
|
||||
can build it. It's just a good habit to organize your code as if you will
|
||||
publish it someday. In practice you can choose any arbitrary path name,
|
||||
as long as it is unique to the standard library and greater Go ecosystem.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
We'll use <code>github.com/user</code> as our base path. Create a directory
|
||||
inside your workspace in which to keep source code:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>mkdir -p $GOPATH/src/github.com/user</b>
|
||||
</pre>
|
||||
|
||||
|
||||
<h3 id="Command">Your first program</h3>
|
||||
|
||||
<p>
|
||||
To compile and run a simple program, first choose a package path (we'll use
|
||||
<code>github.com/user/hello</code>) and create a corresponding package directory
|
||||
inside your workspace:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>mkdir $GOPATH/src/github.com/user/hello</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Next, create a file named <code>hello.go</code> inside that directory,
|
||||
containing the following Go code.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, world.")
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Now you can build and install that program with the <code>go</code> tool:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>go install github.com/user/hello</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Note that you can run this command from anywhere on your system. The
|
||||
<code>go</code> tool finds the source code by looking for the
|
||||
<code>github.com/user/hello</code> package inside the workspace specified by
|
||||
<code>GOPATH</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You can also omit the package path if you run <code>go install</code> from the
|
||||
package directory:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>cd $GOPATH/src/github.com/user/hello</b>
|
||||
$ <b>go install</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
This command builds the <code>hello</code> command, producing an executable
|
||||
binary. It then installs that binary to the workspace's <code>bin</code>
|
||||
directory as <code>hello</code> (or, under Windows, <code>hello.exe</code>).
|
||||
In our example, that will be <code>$GOPATH/bin/hello</code>, which is
|
||||
<code>$HOME/go/bin/hello</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The <code>go</code> tool will only print output when an error occurs, so if
|
||||
these commands produce no output they have executed successfully.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You can now run the program by typing its full path at the command line:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>$GOPATH/bin/hello</b>
|
||||
Hello, world.
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Or, as you have added <code>$GOPATH/bin</code> to your <code>PATH</code>,
|
||||
just type the binary name:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>hello</b>
|
||||
Hello, world.
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
If you're using a source control system, now would be a good time to initialize
|
||||
a repository, add the files, and commit your first change. Again, this step is
|
||||
optional: you do not need to use source control to write Go code.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>cd $GOPATH/src/github.com/user/hello</b>
|
||||
$ <b>git init</b>
|
||||
Initialized empty Git repository in /home/user/work/src/github.com/user/hello/.git/
|
||||
$ <b>git add hello.go</b>
|
||||
$ <b>git commit -m "initial commit"</b>
|
||||
[master (root-commit) 0b4507d] initial commit
|
||||
1 file changed, 1 insertion(+)
|
||||
create mode 100644 hello.go
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Pushing the code to a remote repository is left as an exercise for the reader.
|
||||
</p>
|
||||
|
||||
|
||||
<h3 id="Library">Your first library</h3>
|
||||
|
||||
<p>
|
||||
Let's write a library and use it from the <code>hello</code> program.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Again, the first step is to choose a package path (we'll use
|
||||
<code>github.com/user/stringutil</code>) and create the package directory:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>mkdir $GOPATH/src/github.com/user/stringutil</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Next, create a file named <code>reverse.go</code> in that directory with the
|
||||
following contents.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
// Package stringutil contains utility functions for working with strings.
|
||||
package stringutil
|
||||
|
||||
// Reverse returns its argument string reversed rune-wise left to right.
|
||||
func Reverse(s string) string {
|
||||
r := []rune(s)
|
||||
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
|
||||
r[i], r[j] = r[j], r[i]
|
||||
}
|
||||
return string(r)
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Now, test that the package compiles with <code>go build</code>:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>go build github.com/user/stringutil</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Or, if you are working in the package's source directory, just:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>go build</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
This won't produce an output file.
|
||||
Instead it saves the compiled package in the local build cache.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
After confirming that the <code>stringutil</code> package builds,
|
||||
modify your original <code>hello.go</code> (which is in
|
||||
<code>$GOPATH/src/github.com/user/hello</code>) to use it:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
<b>"github.com/user/stringutil"</b>
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(stringutil.Reverse("!oG ,olleH"))
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Install the <code>hello</code> program:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>go install github.com/user/hello</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Running the new version of the program, you should see a new, reversed message:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>hello</b>
|
||||
Hello, Go!
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
After the steps above, your workspace should look like this:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
bin/
|
||||
hello # command executable
|
||||
src/
|
||||
github.com/user/
|
||||
hello/
|
||||
hello.go # command source
|
||||
stringutil/
|
||||
reverse.go # package source
|
||||
</pre>
|
||||
|
||||
<h3 id="PackageNames">Package names</h3>
|
||||
|
||||
<p>
|
||||
The first statement in a Go source file must be
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
package <i>name</i>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
where <code><i>name</i></code> is the package's default name for imports.
|
||||
(All files in a package must use the same <code><i>name</i></code>.)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Go's convention is that the package name is the last element of the
|
||||
import path: the package imported as "<code>crypto/rot13</code>"
|
||||
should be named <code>rot13</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Executable commands must always use <code>package main</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
There is no requirement that package names be unique
|
||||
across all packages linked into a single binary,
|
||||
only that the import paths (their full file names) be unique.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
See <a href="/doc/effective_go.html#names">Effective Go</a> to learn more about
|
||||
Go's naming conventions.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="Testing">Testing</h2>
|
||||
|
||||
<p>
|
||||
Go has a lightweight test framework composed of the <code>go test</code>
|
||||
command and the <code>testing</code> package.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You write a test by creating a file with a name ending in <code>_test.go</code>
|
||||
that contains functions named <code>TestXXX</code> with signature
|
||||
<code>func (t *testing.T)</code>.
|
||||
The test framework runs each such function;
|
||||
if the function calls a failure function such as <code>t.Error</code> or
|
||||
<code>t.Fail</code>, the test is considered to have failed.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Add a test to the <code>stringutil</code> package by creating the file
|
||||
<code>$GOPATH/src/github.com/user/stringutil/reverse_test.go</code> containing
|
||||
the following Go code.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
package stringutil
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestReverse(t *testing.T) {
|
||||
cases := []struct {
|
||||
in, want string
|
||||
}{
|
||||
{"Hello, world", "dlrow ,olleH"},
|
||||
{"Hello, 世界", "界世 ,olleH"},
|
||||
{"", ""},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := Reverse(c.in)
|
||||
if got != c.want {
|
||||
t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Then run the test with <code>go test</code>:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>go test github.com/user/stringutil</b>
|
||||
ok github.com/user/stringutil 0.165s
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
As always, if you are running the <code>go</code> tool from the package
|
||||
directory, you can omit the package path:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>go test</b>
|
||||
ok github.com/user/stringutil 0.165s
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Run <code><a href="/cmd/go/#hdr-Test_packages">go help test</a></code> and see the
|
||||
<a href="/pkg/testing/">testing package documentation</a> for more detail.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="remote">Remote packages</h2>
|
||||
|
||||
<p>
|
||||
An import path can describe how to obtain the package source code using a
|
||||
revision control system such as Git or Mercurial. The <code>go</code> tool uses
|
||||
this property to automatically fetch packages from remote repositories.
|
||||
For instance, the examples described in this document are also kept in a
|
||||
Git repository hosted at GitHub
|
||||
<code><a href="https://github.com/golang/example">github.com/golang/example</a></code>.
|
||||
If you include the repository URL in the package's import path,
|
||||
<code>go get</code> will fetch, build, and install it automatically:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ <b>go get github.com/golang/example/hello</b>
|
||||
$ <b>$GOPATH/bin/hello</b>
|
||||
Hello, Go examples!
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
If the specified package is not present in a workspace, <code>go get</code>
|
||||
will place it inside the first workspace specified by <code>GOPATH</code>.
|
||||
(If the package does already exist, <code>go get</code> skips the remote
|
||||
fetch and behaves the same as <code>go install</code>.)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
After issuing the above <code>go get</code> command, the workspace directory
|
||||
tree should now look like this:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
bin/
|
||||
hello # command executable
|
||||
src/
|
||||
github.com/golang/example/
|
||||
.git/ # Git repository metadata
|
||||
hello/
|
||||
hello.go # command source
|
||||
stringutil/
|
||||
reverse.go # package source
|
||||
reverse_test.go # test source
|
||||
github.com/user/
|
||||
hello/
|
||||
hello.go # command source
|
||||
stringutil/
|
||||
reverse.go # package source
|
||||
reverse_test.go # test source
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
The <code>hello</code> command hosted at GitHub depends on the
|
||||
<code>stringutil</code> package within the same repository. The imports in
|
||||
<code>hello.go</code> file use the same import path convention, so the
|
||||
<code>go get</code> command is able to locate and install the dependent
|
||||
package, too.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
import "github.com/golang/example/stringutil"
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
This convention is the easiest way to make your Go packages available for
|
||||
others to use.
|
||||
The <a href="//golang.org/wiki/Projects">Go Wiki</a>
|
||||
and <a href="//godoc.org/">godoc.org</a>
|
||||
provide lists of external Go projects.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For more information on using remote repositories with the <code>go</code> tool, see
|
||||
<code><a href="/cmd/go/#hdr-Remote_import_paths">go help importpath</a></code>.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="next">What's next</h2>
|
||||
|
||||
<p>
|
||||
Subscribe to the
|
||||
<a href="//groups.google.com/group/golang-announce">golang-announce</a>
|
||||
mailing list to be notified when a new stable version of Go is released.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
See <a href="/doc/effective_go.html">Effective Go</a> for tips on writing
|
||||
clear, idiomatic Go code.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Take <a href="//tour.golang.org/">A Tour of Go</a> to learn the language
|
||||
proper.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Visit the <a href="/doc/#articles">documentation page</a> for a set of in-depth
|
||||
articles about the Go language and its libraries and tools.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="help">Getting help</h2>
|
||||
|
||||
<p>
|
||||
For real-time help, ask the helpful gophers in <code>#go-nuts</code> on the
|
||||
<a href="https://freenode.net/">Freenode</a> IRC server.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The official mailing list for discussion of the Go language is
|
||||
<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Report bugs using the
|
||||
<a href="//golang.org/issue">Go issue tracker</a>.
|
||||
</p>
|
||||
@@ -1,52 +0,0 @@
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestMarkov tests the code dependency of markov.xml.
|
||||
func TestMarkov(t *testing.T) {
|
||||
cmd := exec.Command("go", "run", "markov.go")
|
||||
cmd.Stdin = strings.NewReader("foo")
|
||||
cmd.Stderr = bytes.NewBuffer(nil)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr)
|
||||
}
|
||||
|
||||
if !bytes.Equal(out, []byte("foo\n")) {
|
||||
t.Fatalf(`%s with input "foo" did not output "foo":\n%s`, strings.Join(cmd.Args, " "), out)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPig tests the code dependency of functions.xml.
|
||||
func TestPig(t *testing.T) {
|
||||
cmd := exec.Command("go", "run", "pig.go")
|
||||
cmd.Stderr = bytes.NewBuffer(nil)
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr)
|
||||
}
|
||||
|
||||
const want = "Wins, losses staying at k = 100: 210/990 (21.2%), 780/990 (78.8%)\n"
|
||||
if !bytes.Contains(out, []byte(want)) {
|
||||
t.Fatalf(`%s: unexpected output\ngot:\n%s\nwant output containing:\n%s`, strings.Join(cmd.Args, " "), out, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestURLPoll tests the code dependency of sharemem.xml.
|
||||
func TestURLPoll(t *testing.T) {
|
||||
cmd := exec.Command("go", "build", "-o", os.DevNull, "urlpoll.go")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, out)
|
||||
}
|
||||
}
|
||||
21
doc/codewalk/run
Executable file
21
doc/codewalk/run
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2013 The Go Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
set -e
|
||||
|
||||
function fail {
|
||||
echo FAIL: doc/codewalk/$1
|
||||
exit 1
|
||||
}
|
||||
|
||||
# markov.xml
|
||||
echo foo | go run markov.go | grep foo > /dev/null || fail markov
|
||||
|
||||
# functions.xml
|
||||
go run pig.go | grep 'Wins, losses staying at k = 100: 210/990 (21.2%), 780/990 (78.8%)' > /dev/null || fail pig
|
||||
|
||||
# sharemem.xml: only build the example, as it uses the network
|
||||
go build urlpoll.go || fail urlpoll
|
||||
rm -f urlpoll
|
||||
211
doc/conduct.html
Normal file
211
doc/conduct.html
Normal file
@@ -0,0 +1,211 @@
|
||||
<!--{
|
||||
"Title": "Go Community Code of Conduct",
|
||||
"Path": "/conduct",
|
||||
"Template": true
|
||||
}-->
|
||||
|
||||
<style>
|
||||
ul {
|
||||
max-width: 800px;
|
||||
}
|
||||
ul ul {
|
||||
margin: 0 0 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<h2 id="about">About</h2>
|
||||
|
||||
<p>
|
||||
Online communities include people from many different backgrounds.
|
||||
The Go contributors are committed to providing a friendly, safe and welcoming
|
||||
environment for all, regardless of gender identity and expression, sexual orientation,
|
||||
disabilities, neurodiversity, physical appearance, body size, ethnicity, nationality,
|
||||
race, age, religion, or similar personal characteristics.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The first goal of the Code of Conduct is to specify a baseline standard
|
||||
of behavior so that people with different social values and communication
|
||||
styles can talk about Go effectively, productively, and respectfully.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The second goal is to provide a mechanism for resolving conflicts in the
|
||||
community when they arise.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The third goal of the Code of Conduct is to make our community welcoming to
|
||||
people from different backgrounds.
|
||||
Diversity is critical to the project; for Go to be successful, it needs
|
||||
contributors and users from all backgrounds.
|
||||
(See <a href="https://blog.golang.org/open-source">Go, Open Source, Community</a>.)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
We believe that healthy debate and disagreement are essential to a healthy project and community.
|
||||
However, it is never ok to be disrespectful.
|
||||
We value diverse opinions, but we value respectful behavior more.
|
||||
</p>
|
||||
|
||||
<h2 id="values">Gopher values</h2>
|
||||
|
||||
<p>
|
||||
These are the values to which people in the Go community (“Gophers”) should aspire.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li>Be friendly and welcoming
|
||||
<li>Be patient
|
||||
<ul>
|
||||
<li>Remember that people have varying communication styles and that not
|
||||
everyone is using their native language.
|
||||
(Meaning and tone can be lost in translation.)
|
||||
</ul>
|
||||
<li>Be thoughtful
|
||||
<ul>
|
||||
<li>Productive communication requires effort.
|
||||
Think about how your words will be interpreted.
|
||||
<li>Remember that sometimes it is best to refrain entirely from commenting.
|
||||
</ul>
|
||||
<li>Be respectful
|
||||
<ul>
|
||||
<li>In particular, respect differences of opinion.
|
||||
</ul>
|
||||
<li>Be charitable
|
||||
<ul>
|
||||
<li>Interpret the arguments of others in good faith, do not seek to disagree.
|
||||
<li>When we do disagree, try to understand why.
|
||||
</ul>
|
||||
<li>Avoid destructive behavior:
|
||||
<ul>
|
||||
<li>Derailing: stay on topic; if you want to talk about something else,
|
||||
start a new conversation.
|
||||
<li>Unconstructive criticism: don't merely decry the current state of affairs;
|
||||
offer—or at least solicit—suggestions as to how things may be improved.
|
||||
<li>Snarking (pithy, unproductive, sniping comments)
|
||||
<li>Discussing potentially offensive or sensitive issues;
|
||||
this all too often leads to unnecessary conflict.
|
||||
<li>Microaggressions: brief and commonplace verbal, behavioral and
|
||||
environmental indignities that communicate hostile, derogatory or negative
|
||||
slights and insults to a person or group.
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
People are complicated.
|
||||
You should expect to be misunderstood and to misunderstand others;
|
||||
when this inevitably occurs, resist the urge to be defensive or assign blame.
|
||||
Try not to take offense where no offense was intended.
|
||||
Give people the benefit of the doubt.
|
||||
Even if the intent was to provoke, do not rise to it.
|
||||
It is the responsibility of <i>all parties</i> to de-escalate conflict when it arises.
|
||||
</p>
|
||||
|
||||
<h2 id="code">Code of Conduct</h2>
|
||||
|
||||
<h3 id="our-pledge">Our Pledge</h3>
|
||||
|
||||
<p>In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of
|
||||
experience, education, socio-economic status, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.</p>
|
||||
|
||||
<h3 id="our-standards">Our Standards</h3>
|
||||
|
||||
<p>Examples of behavior that contributes to creating a positive environment
|
||||
include:</p>
|
||||
|
||||
<ul>
|
||||
<li>Using welcoming and inclusive language</li>
|
||||
<li>Being respectful of differing viewpoints and experiences</li>
|
||||
<li>Gracefully accepting constructive criticism</li>
|
||||
<li>Focusing on what is best for the community</li>
|
||||
<li>Showing empathy towards other community members</li>
|
||||
</ul>
|
||||
|
||||
<p>Examples of unacceptable behavior by participants include:</p>
|
||||
|
||||
<ul>
|
||||
<li>The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances</li>
|
||||
<li>Trolling, insulting/derogatory comments, and personal or political attacks</li>
|
||||
<li>Public or private harassment</li>
|
||||
<li>Publishing others’ private information, such as a physical or electronic
|
||||
address, without explicit permission</li>
|
||||
<li>Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting</li>
|
||||
</ul>
|
||||
|
||||
<h3 id="our-responsibilities">Our Responsibilities</h3>
|
||||
|
||||
<p>Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.</p>
|
||||
|
||||
<p>Project maintainers have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, or to ban temporarily or permanently any
|
||||
contributor for other behaviors that they deem inappropriate, threatening,
|
||||
offensive, or harmful.</p>
|
||||
|
||||
<h3 id="scope">Scope</h3>
|
||||
|
||||
<p>This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.</p>
|
||||
|
||||
<p>This Code of Conduct also applies outside the project spaces when the Project
|
||||
Steward has a reasonable belief that an individual’s behavior may have a
|
||||
negative impact on the project or its community.</p>
|
||||
|
||||
<h3 id="conflict-resolution"></a>Conflict Resolution</h3>
|
||||
|
||||
<p>We do not believe that all conflict is bad; healthy debate and disagreement
|
||||
often yield positive results. However, it is never okay to be disrespectful or
|
||||
to engage in behavior that violates the project’s code of conduct.</p>
|
||||
|
||||
<p>If you see someone violating the code of conduct, you are encouraged to address
|
||||
the behavior directly with those involved. Many issues can be resolved quickly
|
||||
and easily, and this gives people more control over the outcome of their
|
||||
dispute. If you are unable to resolve the matter for any reason, or if the
|
||||
behavior is threatening or harassing, report it. We are dedicated to providing
|
||||
an environment where participants feel welcome and safe.</p>
|
||||
|
||||
<p id="reporting">Reports should be directed to Cassandra Salisbury, the
|
||||
Go Project Steward, at <i>conduct@golang.org</i>.
|
||||
It is the Project Steward’s duty to
|
||||
receive and address reported violations of the code of conduct. They will then
|
||||
work with a committee consisting of representatives from the Open Source
|
||||
Programs Office and the Google Open Source Strategy team. If for any reason you
|
||||
are uncomfortable reaching out the Project Steward, please email
|
||||
the Google Open Source Programs Office at <i>opensource@google.com</i>.</p>
|
||||
|
||||
<p>We will investigate every complaint, but you may not receive a direct response.
|
||||
We will use our discretion in determining when and how to follow up on reported
|
||||
incidents, which may range from not taking action to permanent expulsion from
|
||||
the project and project-sponsored spaces. We will notify the accused of the
|
||||
report and provide them an opportunity to discuss it before any action is taken.
|
||||
The identity of the reporter will be omitted from the details of the report
|
||||
supplied to the accused. In potentially harmful situations, such as ongoing
|
||||
harassment or threats to anyone’s safety, we may take action without notice.</p>
|
||||
|
||||
<h3 id="attribution">Attribution</h3>
|
||||
|
||||
<p>This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
|
||||
available at
|
||||
<a href="https://www.contributor-covenant.org/version/1/4/code-of-conduct.html">https://www.contributor-covenant.org/version/1/4/code-of-conduct.html</a></p>
|
||||
|
||||
<h2 id="summary">Summary</h2>
|
||||
|
||||
<ul>
|
||||
<li>Treat everyone with respect and kindness.
|
||||
<li>Be thoughtful in how you communicate.
|
||||
<li>Don’t be destructive or inflammatory.
|
||||
<li>If you encounter an issue, please mail <a href="mailto:conduct@golang.org">conduct@golang.org</a>.
|
||||
</ul>
|
||||
131
doc/contrib.html
Normal file
131
doc/contrib.html
Normal file
@@ -0,0 +1,131 @@
|
||||
<!--{
|
||||
"Title": "The Go Project",
|
||||
"Path": "/project/"
|
||||
}-->
|
||||
|
||||
<img class="gopher" src="/doc/gopher/project.png" />
|
||||
|
||||
<div id="manual-nav"></div>
|
||||
|
||||
<p>
|
||||
Go is an open source project developed by a team at
|
||||
<a href="//google.com/">Google</a> and many
|
||||
<a href="/CONTRIBUTORS">contributors</a> from the open source community.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Go is distributed under a <a href="/LICENSE">BSD-style license</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="announce"><a href="//groups.google.com/group/golang-announce">Announcements Mailing List</a></h3>
|
||||
<p>
|
||||
A low traffic mailing list for important announcements, such as new releases.
|
||||
</p>
|
||||
<p>
|
||||
We encourage all Go users to subscribe to
|
||||
<a href="//groups.google.com/group/golang-announce">golang-announce</a>.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="go1">Version history</h2>
|
||||
|
||||
<h3 id="release"><a href="/doc/devel/release.html">Release History</a></h3>
|
||||
|
||||
<p>A <a href="/doc/devel/release.html">summary</a> of the changes between Go releases. Notes for the major releases:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="/doc/go1.12">Go 1.12</a> <small>(February 2019)</small></li>
|
||||
<li><a href="/doc/go1.11">Go 1.11</a> <small>(August 2018)</small></li>
|
||||
<li><a href="/doc/go1.10">Go 1.10</a> <small>(February 2018)</small></li>
|
||||
<li><a href="/doc/go1.9">Go 1.9</a> <small>(August 2017)</small></li>
|
||||
<li><a href="/doc/go1.8">Go 1.8</a> <small>(February 2017)</small></li>
|
||||
<li><a href="/doc/go1.7">Go 1.7</a> <small>(August 2016)</small></li>
|
||||
<li><a href="/doc/go1.6">Go 1.6</a> <small>(February 2016)</small></li>
|
||||
<li><a href="/doc/go1.5">Go 1.5</a> <small>(August 2015)</small></li>
|
||||
<li><a href="/doc/go1.4">Go 1.4</a> <small>(December 2014)</small></li>
|
||||
<li><a href="/doc/go1.3">Go 1.3</a> <small>(June 2014)</small></li>
|
||||
<li><a href="/doc/go1.2">Go 1.2</a> <small>(December 2013)</small></li>
|
||||
<li><a href="/doc/go1.1">Go 1.1</a> <small>(May 2013)</small></li>
|
||||
<li><a href="/doc/go1">Go 1</a> <small>(March 2012)</small></li>
|
||||
</ul>
|
||||
|
||||
<h3 id="go1compat"><a href="/doc/go1compat">Go 1 and the Future of Go Programs</a></h3>
|
||||
<p>
|
||||
What Go 1 defines and the backwards-compatibility guarantees one can expect as
|
||||
Go 1 matures.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="resources">Developer Resources</h2>
|
||||
|
||||
<h3 id="source"><a href="https://golang.org/change">Source Code</a></h3>
|
||||
<p>Check out the Go source code.</p>
|
||||
|
||||
<h3 id="discuss"><a href="//groups.google.com/group/golang-nuts">Discussion Mailing List</a></h3>
|
||||
<p>
|
||||
A mailing list for general discussion of Go programming.
|
||||
</p>
|
||||
<p>
|
||||
Questions about using Go or announcements relevant to other Go users should be sent to
|
||||
<a href="//groups.google.com/group/golang-nuts">golang-nuts</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="golang-dev"><a href="https://groups.google.com/group/golang-dev">Developer</a> and
|
||||
<a href="https://groups.google.com/group/golang-codereviews">Code Review Mailing List</a></h3>
|
||||
<p>The <a href="https://groups.google.com/group/golang-dev">golang-dev</a>
|
||||
mailing list is for discussing code changes to the Go project.
|
||||
The <a href="https://groups.google.com/group/golang-codereviews">golang-codereviews</a>
|
||||
mailing list is for actual reviewing of the code changes (CLs).</p>
|
||||
|
||||
<h3 id="golang-checkins"><a href="https://groups.google.com/group/golang-checkins">Checkins Mailing List</a></h3>
|
||||
<p>A mailing list that receives a message summarizing each checkin to the Go repository.</p>
|
||||
|
||||
<h3 id="build_status"><a href="//build.golang.org/">Build Status</a></h3>
|
||||
<p>View the status of Go builds across the supported operating
|
||||
systems and architectures.</p>
|
||||
|
||||
|
||||
<h2 id="howto">How you can help</h2>
|
||||
|
||||
<h3><a href="//golang.org/issue">Reporting issues</a></h3>
|
||||
|
||||
<p>
|
||||
If you spot bugs, mistakes, or inconsistencies in the Go project's code or
|
||||
documentation, please let us know by
|
||||
<a href="//golang.org/issue/new">filing a ticket</a>
|
||||
on our <a href="//golang.org/issue">issue tracker</a>.
|
||||
(Of course, you should check it's not an existing issue before creating
|
||||
a new one.)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
We pride ourselves on being meticulous; no issue is too small.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Security-related issues should be reported to
|
||||
<a href="mailto:security@golang.org">security@golang.org</a>.<br>
|
||||
See the <a href="/security">security policy</a> for more details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Community-related issues should be reported to
|
||||
<a href="mailto:conduct@golang.org">conduct@golang.org</a>.<br>
|
||||
See the <a href="/conduct">Code of Conduct</a> for more details.
|
||||
</p>
|
||||
|
||||
<h3><a href="/doc/contribute.html">Contributing code</a></h3>
|
||||
|
||||
<p>
|
||||
Go is an open source project and we welcome contributions from the community.
|
||||
</p>
|
||||
<p>
|
||||
To get started, read these <a href="/doc/contribute.html">contribution
|
||||
guidelines</a> for information on design, testing, and our code review process.
|
||||
</p>
|
||||
<p>
|
||||
Check <a href="//golang.org/issue">the tracker</a> for
|
||||
open issues that interest you. Those labeled
|
||||
<a href="https://github.com/golang/go/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22">help wanted</a>
|
||||
are particularly in need of outside help.
|
||||
</p>
|
||||
@@ -26,7 +26,7 @@ see <a href="gccgo_contribute.html">Contributing to gccgo</a>.
|
||||
|
||||
<h2 id="contributor">Becoming a contributor</h2>
|
||||
|
||||
<h3 id="contrib_overview">Overview</h3>
|
||||
<h3>Overview</h3>
|
||||
|
||||
<p>
|
||||
The first step is registering as a Go contributor and configuring your environment.
|
||||
@@ -46,8 +46,7 @@ CLA (Contributor License Agreement).
|
||||
<li>
|
||||
<b>Step 2</b>: Configure authentication credentials for the Go Git repository.
|
||||
Visit <a href="https://go.googlesource.com/">go.googlesource.com</a>, click
|
||||
on the gear icon (top right), then on "Obtain password", and follow the
|
||||
instructions.
|
||||
on "Generate Password" (top right), and follow the instructions.
|
||||
</li>
|
||||
<li>
|
||||
<b>Step 3</b>: Register for Gerrit, the code review tool used by the Go team,
|
||||
@@ -174,7 +173,7 @@ The main Go repository is located at
|
||||
a Git server hosted by Google.
|
||||
Authentication on the web server is made through your Google account, but
|
||||
you also need to configure <code>git</code> on your computer to access it.
|
||||
Follow these steps:
|
||||
Follow this steps:
|
||||
</p>
|
||||
|
||||
<ol>
|
||||
@@ -238,16 +237,14 @@ $ git codereview help
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
prints help text, not an error. If it prints an error, make sure that
|
||||
<code>$GOPATH/bin</code> is in your <code>$PATH</code>.
|
||||
prints help text, not an error.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
On Windows, when using git-bash you must make sure that
|
||||
<code>git-codereview.exe</code> is in your <code>git</code> exec-path.
|
||||
Run <code>git --exec-path</code> to discover the right location then create a
|
||||
symbolic link or just copy the executable from <code>$GOPATH/bin</code> to this
|
||||
directory.
|
||||
symbolic link or just copy the executable from $GOPATH/bin to this directory.
|
||||
</p>
|
||||
|
||||
|
||||
@@ -263,25 +260,7 @@ a new issue</a> or by claiming
|
||||
an <a href="https://golang.org/issues">existing one</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="where">Where to contribute</h3>
|
||||
|
||||
<p>
|
||||
The Go project consists of the main
|
||||
<a href="https://go.googlesource.com/go">go</a> repository, which contains the
|
||||
source code for the Go language, as well as many golang.org/x/... repostories.
|
||||
These contain the various tools and infrastructure that support Go. For
|
||||
example, <a href="https://go.googlesource.com/pkgsite">golang.org/x/pkgsite</a>
|
||||
is for <a href="https://pkg.go.dev">pkg.go.dev</a>,
|
||||
<a href="https://go.googlesource.com/playground">golang.org/x/playground</a>
|
||||
is for the Go playground, and
|
||||
<a href="https://go.googlesource.com/tools">golang.org/x/tools</a> contains
|
||||
a variety of Go tools, including the Go language server,
|
||||
<a href="https://golang.org/s/gopls">gopls</a>. You can see a
|
||||
list of all the golang.org/x/... repositories on
|
||||
<a href="https://go.googlesource.com">go.googlesource.com</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="check_tracker">Check the issue tracker</h3>
|
||||
<h3>Check the issue tracker</h3>
|
||||
|
||||
<p>
|
||||
Whether you already know what contribution to make, or you are searching for
|
||||
@@ -290,13 +269,6 @@ always the first place to go.
|
||||
Issues are triaged to categorize them and manage the workflow.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The majority of the golang.org/x/... repos also use the main Go
|
||||
issue tracker. However, a few of these repositories manage their issues
|
||||
separately, so please be sure to check the right tracker for the repository to
|
||||
which you would like to contribute.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Most issues will be marked with one of the following workflow labels:
|
||||
</p>
|
||||
@@ -310,7 +282,7 @@ Most issues will be marked with one of the following workflow labels:
|
||||
<b>NeedsDecision</b>: the issue is relatively well understood, but the
|
||||
Go team hasn't yet decided the best way to address it.
|
||||
It would be better to wait for a decision before writing code.
|
||||
If you are interested in working on an issue in this state,
|
||||
If you are interested on working on an issue in this state,
|
||||
feel free to "ping" maintainers in the issue's comments
|
||||
if some time has passed without a decision.
|
||||
</li>
|
||||
@@ -354,16 +326,11 @@ the code review tool is not the place for high-level discussions.
|
||||
|
||||
<p>
|
||||
When planning work, please note that the Go project follows a <a
|
||||
href="https://golang.org/wiki/Go-Release-Cycle">six-month development cycle</a>
|
||||
for the main Go repository. The latter half of each cycle is a three-month
|
||||
feature freeze during which only bug fixes and documentation updates are
|
||||
accepted. New contributions can be sent during a feature freeze, but they will
|
||||
not be merged until the freeze is over. The freeze applies to the entire main
|
||||
repository as well as to the code in golang.org/x/... repositories that is
|
||||
needed to build the binaries included in the release. See the lists of packages
|
||||
vendored into
|
||||
<a href="https://github.com/golang/go/blob/master/src/vendor/modules.txt">the standard library</a>
|
||||
and the <a href="https://github.com/golang/go/blob/master/src/cmd/vendor/modules.txt"><code>go</code> command</a>.
|
||||
href="https://golang.org/wiki/Go-Release-Cycle">six-month development cycle</a>.
|
||||
The latter half of each cycle is a three-month feature freeze during
|
||||
which only bug fixes and documentation updates are accepted.
|
||||
New contributions can be sent during a feature freeze, but they will
|
||||
not be merged until the freeze is over.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@@ -430,7 +397,7 @@ It's different but powerful and familiarity with it will help you understand
|
||||
the flow.
|
||||
</p>
|
||||
|
||||
<h3 id="gerrit_overview">Overview</h3>
|
||||
<h3>Overview</h3>
|
||||
|
||||
<p>
|
||||
This is an overview of the overall process:
|
||||
@@ -438,29 +405,13 @@ This is an overview of the overall process:
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<b>Step 1:</b> Clone the source code from <code>go.googlesource.com</code> and
|
||||
make sure it's stable by compiling and testing it once.
|
||||
|
||||
<p>If you're making a change to the
|
||||
<a href="https://go.googlesource.com/go">main Go repository</a>:</p>
|
||||
|
||||
<b>Step 1:</b> Clone the Go source code from <code>go.googlesource.com</code>
|
||||
and make sure it's stable by compiling and testing it once:
|
||||
<pre>
|
||||
$ git clone https://go.googlesource.com/go
|
||||
$ cd go/src
|
||||
$ ./all.bash # compile and test
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
If you're making a change to one of the golang.org/x/... repositories
|
||||
(<a href="https://go.googlesource.com/tools">golang.org/x/tools</a>,
|
||||
in this example):
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ git clone https://go.googlesource.com/tools
|
||||
$ cd tools
|
||||
$ go test ./... # compile and test
|
||||
</pre>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
@@ -480,18 +431,10 @@ $ [etc.]
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<b>Step 3:</b> Test your changes, either by running the tests in the package
|
||||
you edited or by re-running <code>all.bash</code>.
|
||||
|
||||
<p>In the main Go repository:</p>
|
||||
<b>Step 3:</b> Test your changes, re-running <code>all.bash</code>.
|
||||
<pre>
|
||||
$ ./all.bash # recompile and test
|
||||
</pre>
|
||||
|
||||
<p>In a golang.org/x/... repository:</p>
|
||||
<pre>
|
||||
$ go test ./... # recompile and test
|
||||
</pre>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
@@ -519,7 +462,7 @@ The rest of this section describes these steps in more detail.
|
||||
</p>
|
||||
|
||||
|
||||
<h3 id="checkout_go">Step 1: Clone the source code</h3>
|
||||
<h3 id="checkout_go">Step 1: Clone the Go source code</h3>
|
||||
|
||||
<p>
|
||||
In addition to a recent Go installation, you need to have a local copy of the source
|
||||
@@ -529,19 +472,11 @@ you want as long as it's outside your <code>GOPATH</code>.
|
||||
Clone from <code>go.googlesource.com</code> (not GitHub):
|
||||
</p>
|
||||
|
||||
<p>Main Go repository:</p>
|
||||
<pre>
|
||||
$ git clone https://go.googlesource.com/go
|
||||
$ cd go
|
||||
</pre>
|
||||
|
||||
<p>golang.org/x/... repository</p>
|
||||
(<a href="https://go.googlesource.com/tools">golang.org/x/tools</a> in this example):
|
||||
<pre>
|
||||
$ git clone https://go.googlesource.com/tools
|
||||
$ cd tools
|
||||
</pre>
|
||||
|
||||
<h3 id="make_branch">Step 2: Prepare changes in a new branch</h3>
|
||||
|
||||
<p>
|
||||
@@ -605,20 +540,18 @@ into a single one.
|
||||
<p>
|
||||
You've <a href="code.html">written and tested your code</a>, but
|
||||
before sending code out for review, run <i>all the tests for the whole
|
||||
tree</i> to make sure the changes don't break other packages or programs.
|
||||
tree</i> to make sure the changes don't break other packages or programs:
|
||||
</p>
|
||||
|
||||
<h4 id="test-gorepo">In the main Go repository</h4>
|
||||
|
||||
<p>This can be done by running <code>all.bash</code>:</p>
|
||||
|
||||
<pre>
|
||||
$ cd go/src
|
||||
$ ./all.bash
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
(To build under Windows use <code>all.bat</code>)
|
||||
(To build under Windows use <code>all.bat</code>; this also requires
|
||||
setting the environment variable <code>GOROOT_BOOTSTRAP</code> to the
|
||||
directory holding the Go tree for the bootstrap compiler.)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@@ -640,33 +573,6 @@ See also
|
||||
the section on how to <a href="#quick_test">test your changes quickly</a>.
|
||||
</p>
|
||||
|
||||
<h4 id="test-xrepo">In the golang.org/x/... repositories</h4>
|
||||
|
||||
<p>
|
||||
Run the tests for the entire repository
|
||||
(<a href="https://go.googlesource.com/tools">golang.org/x/tools</a>,
|
||||
in this example):
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ cd tools
|
||||
$ go test ./...
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
If you're concerned about the build status,
|
||||
you can check the <a href="https://build.golang.org">Build Dashboard</a>.
|
||||
Test failures may also be caught by the TryBots in code review.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Some repositories, like
|
||||
<a href="https://go.googlesource.com/vscode-go">golang.org/x/vscode-go</a> will
|
||||
have different testing infrastructures, so always check the documentation
|
||||
for the repository in which you are working. The README file in the root of the
|
||||
repository will usually have this information.
|
||||
</p>
|
||||
|
||||
<h3 id="mail">Step 4: Send changes for review</h3>
|
||||
|
||||
<p>
|
||||
@@ -759,7 +665,7 @@ The algorithm is described at https://wikipedia.org/wiki/McGillicutty_Algorithm
|
||||
Fixes #159
|
||||
</pre>
|
||||
|
||||
<h3 id="first_line">First line</h3>
|
||||
<h3>First line</h3>
|
||||
|
||||
<p>
|
||||
The first line of the change description is conventionally a short one-line
|
||||
@@ -777,7 +683,7 @@ and actually summarizes the result of the change.
|
||||
Follow the first line by a blank line.
|
||||
</p>
|
||||
|
||||
<h3 id="main_content">Main content</h3>
|
||||
<h3>Main content</h3>
|
||||
|
||||
<p>
|
||||
The rest of the description elaborates and should provide context for the
|
||||
@@ -795,7 +701,7 @@ tool is conventionally used to format
|
||||
benchmark data for change descriptions.
|
||||
</p>
|
||||
|
||||
<h3 id="ref_issues">Referencing issues</h3>
|
||||
<h3>Referencing issues</h3>
|
||||
|
||||
<p>
|
||||
The special notation "Fixes #12345" associates the change with issue 12345 in the
|
||||
@@ -813,10 +719,10 @@ when the change is applied.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you are sending a change against a golang.org/x/... repository, you must use
|
||||
If you are sending a change against a subrepository, you must use
|
||||
the fully-qualified syntax supported by GitHub to make sure the change is
|
||||
linked to the issue in the main repository, not the x/ repository.
|
||||
Most issues are tracked in the main repository's issue tracker.
|
||||
linked to the issue in the main repository, not the subrepository.
|
||||
All issues are tracked in the main repository's issue tracker.
|
||||
The correct form is "Fixes golang/go#159".
|
||||
</p>
|
||||
|
||||
@@ -1016,13 +922,13 @@ New files that you contribute should use the standard copyright header:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
// Copyright 2020 The Go Authors. All rights reserved.
|
||||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
(Use the current year if you're reading this in 2021 or beyond.)
|
||||
(Use the current year if you're reading this in 2020 or beyond.)
|
||||
Files in the repository are copyrighted the year they are added.
|
||||
Do not update the copyright year on files that you change.
|
||||
</p>
|
||||
@@ -1099,7 +1005,7 @@ followed by <code>run.bash</code>.
|
||||
|
||||
<li>
|
||||
In this section, we'll call the directory into which you cloned the Go repository <code>$GODIR</code>.
|
||||
The <code>go</code> tool built by <code>$GODIR/src/make.bash</code> will be installed
|
||||
The <code>go</code> tool built by <code>$GODIR/make.bash</code> will be installed
|
||||
in <code>$GODIR/bin/go</code> and you
|
||||
can invoke it to test your code.
|
||||
For instance, if you
|
||||
@@ -1163,6 +1069,25 @@ $ $GODIR/bin/go run run.go
|
||||
</pre>
|
||||
</ul>
|
||||
|
||||
<h3 id="subrepos">Contributing to subrepositories (golang.org/x/...)</h3>
|
||||
|
||||
<p>
|
||||
If you are contributing a change to a subrepository, obtain the
|
||||
Go package using <code>go get</code>.
|
||||
For example, to contribute
|
||||
to <code>golang.org/x/oauth2</code>, check out the code by running:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ go get -d golang.org/x/oauth2/...
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Then, change your directory to the package's source directory
|
||||
(<code>$GOPATH/src/golang.org/x/oauth2</code>), and follow the
|
||||
normal contribution flow.
|
||||
</p>
|
||||
|
||||
|
||||
<h3 id="cc">Specifying a reviewer / CCing others</h3>
|
||||
|
||||
@@ -1283,5 +1208,5 @@ $ git codereview mail HEAD
|
||||
|
||||
<p>
|
||||
Make sure to explicitly specify <code>HEAD</code>, which is usually not required when sending
|
||||
single changes. More details can be found in the <a href="https://pkg.go.dev/golang.org/x/review/git-codereview?tab=doc#hdr-Multiple_Commit_Work_Branches">git-codereview documentation</a>.
|
||||
single changes.
|
||||
</p>
|
||||
|
||||
@@ -18,13 +18,13 @@ Gccgo has native gdb support.
|
||||
</p>
|
||||
<p>
|
||||
Note that
|
||||
<a href="https://github.com/go-delve/delve">Delve</a> is a better
|
||||
<a href="https://github.com/derekparker/delve">Delve</a> is a better
|
||||
alternative to GDB when debugging Go programs built with the standard
|
||||
toolchain. It understands the Go runtime, data structures, and
|
||||
expressions better than GDB. Delve currently supports Linux, OSX,
|
||||
and Windows on <code>amd64</code>.
|
||||
For the most up-to-date list of supported platforms, please see
|
||||
<a href="https://github.com/go-delve/delve/tree/master/Documentation/installation">
|
||||
<a href="https://github.com/derekparker/delve/tree/master/Documentation/installation">
|
||||
the Delve documentation</a>.
|
||||
</p>
|
||||
</i>
|
||||
@@ -149,9 +149,6 @@ Inspecting goroutines:
|
||||
(gdb) <b>help goroutine</b></pre>
|
||||
For example:
|
||||
<pre>(gdb) <b>goroutine 12 bt</b></pre>
|
||||
You can inspect all goroutines by passing <code>all</code> instead of a specific goroutine's ID.
|
||||
For example:
|
||||
<pre>(gdb) <b>goroutine all bt</b></pre>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
455
doc/devel/pre_go1.html
Normal file
455
doc/devel/pre_go1.html
Normal file
@@ -0,0 +1,455 @@
|
||||
<!--{
|
||||
"Title": "Pre-Go 1 Release History"
|
||||
}-->
|
||||
|
||||
<p>
|
||||
This page summarizes the changes between stable releases of Go prior to Go 1.
|
||||
See the <a href="release.html">Release History</a> page for notes on recent releases.
|
||||
</p>
|
||||
|
||||
<h2 id="r60">r60 (released 2011/09/07)</h2>
|
||||
|
||||
<p>
|
||||
The r60 release corresponds to
|
||||
<code><a href="weekly.html#2011-08-17">weekly.2011-08-17</a></code>.
|
||||
This section highlights the most significant changes in this release.
|
||||
For a more detailed summary, see the
|
||||
<a href="weekly.html#2011-08-17">weekly release notes</a>.
|
||||
For complete information, see the
|
||||
<a href="//code.google.com/p/go/source/list?r=release-branch.r60">Mercurial change list</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="r60.lang">Language</h3>
|
||||
|
||||
<p>
|
||||
An "else" block is now required to have braces except if the body of the "else"
|
||||
is another "if". Since gofmt always puts those braces in anyway,
|
||||
gofmt-formatted programs will not be affected.
|
||||
To fix other programs, run gofmt.
|
||||
</p>
|
||||
|
||||
<h3 id="r60.pkg">Packages</h3>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/http/">Package http</a>'s URL parsing and query escaping code
|
||||
(such as <code>ParseURL</code> and <code>URLEscape</code>) has been moved to
|
||||
the new <a href="/pkg/url/">url package</a>, with several simplifications to
|
||||
the names. Client code can be updated automatically with gofix.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/image/">Package image</a> has had significant changes made to the
|
||||
<code>Pix</code> field of struct types such as
|
||||
<a href="/pkg/image/#RGBA">image.RGBA</a> and
|
||||
<a href="/pkg/image/#NRGBA">image.NRGBA</a>.
|
||||
The <a href="/pkg/image/#Image">image.Image</a> interface type has not changed,
|
||||
though, and you should not need to change your code if you don't explicitly
|
||||
refer to <code>Pix</code> fields. For example, if you decode a number of images
|
||||
using the <a href="/pkg/image/jpeg/">image/jpeg</a> package, compose them using
|
||||
<a href="/pkg/image/draw/">image/draw</a>, and then encode the result using
|
||||
<a href="/pkg/img/png">image/png</a>, then your code should still work as
|
||||
before.
|
||||
If your code <i>does</i> refer to <code>Pix</code> fields see the
|
||||
<a href="/doc/devel/weekly.html#2011-07-19">weekly.2011-07-19</a>
|
||||
snapshot notes for how to update your code.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/template/">Package template</a> has been replaced with a new
|
||||
templating package (formerly <code>exp/template</code>). The original template
|
||||
package is still available as <a href="/pkg/old/template/">old/template</a>.
|
||||
The <code>old/template</code> package is deprecated and will be removed.
|
||||
The Go tree has been updated to use the new template package. We encourage
|
||||
users of the old template package to switch to the new one. Code that uses
|
||||
<code>template</code> or <code>exp/template</code> will need to change its
|
||||
import lines to <code>"old/template"</code> or <code>"template"</code>,
|
||||
respectively.
|
||||
</p>
|
||||
|
||||
<h3 id="r60.cmd">Tools</h3>
|
||||
|
||||
<p>
|
||||
<a href="/cmd/goinstall/">Goinstall</a> now uses a new tag selection scheme.
|
||||
When downloading or updating, goinstall looks for a tag or branch with the
|
||||
<code>"go."</code> prefix that corresponds to the local Go version. For Go
|
||||
<code>release.r58</code> it looks for <code>go.r58</code>. For
|
||||
<code>weekly.2011-06-03</code> it looks for <code>go.weekly.2011-06-03</code>.
|
||||
If the specific <code>go.X</code> tag or branch is not found, it chooses the
|
||||
closest earlier version. If an appropriate tag or branch is found, goinstall
|
||||
uses that version of the code. Otherwise it uses the default version selected
|
||||
by the version control system. Library authors are encouraged to use the
|
||||
appropriate tag or branch names in their repositories to make their libraries
|
||||
more accessible.
|
||||
</p>
|
||||
|
||||
<h3 id="r60.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
r60.1 includes a
|
||||
<a href="//golang.org/change/1824581bf62d">linker
|
||||
fix</a>, a pair of
|
||||
<a href="//golang.org/change/9ef4429c2c64">goplay</a>
|
||||
<a href="//golang.org/change/d42ed8c3098e">fixes</a>,
|
||||
and a <code>json</code> package
|
||||
<a href="//golang.org/change/d5e97874fe84">fix</a> and
|
||||
a new
|
||||
<a href="//golang.org/change/4f0e6269213f">struct tag
|
||||
option</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
r60.2
|
||||
<a href="//golang.org/change/ff19536042ac">fixes</a>
|
||||
a memory leak involving maps.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
r60.3 fixes a
|
||||
<a href="//golang.org/change/01fa62f5e4e5">reflect bug</a>.
|
||||
</p>
|
||||
|
||||
<h2 id="r59">r59 (released 2011/08/01)</h2>
|
||||
|
||||
<p>
|
||||
The r59 release corresponds to
|
||||
<code><a href="weekly.html#2011-07-07">weekly.2011-07-07</a></code>.
|
||||
This section highlights the most significant changes in this release.
|
||||
For a more detailed summary, see the
|
||||
<a href="weekly.html#2011-07-07">weekly release notes</a>.
|
||||
For complete information, see the
|
||||
<a href="//code.google.com/p/go/source/list?r=release-branch.r59">Mercurial change list</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="r59.lang">Language</h3>
|
||||
|
||||
<p>
|
||||
This release includes a language change that restricts the use of
|
||||
<code>goto</code>. In essence, a <code>goto</code> statement outside a block
|
||||
cannot jump to a label inside that block. Your code may require changes if it
|
||||
uses <code>goto</code>.
|
||||
See <a href="//golang.org/change/dc6d3cf9279d">this
|
||||
changeset</a> for how the new rule affected the Go tree.
|
||||
</p>
|
||||
|
||||
<h3 id="r59.pkg">Packages</h3>
|
||||
|
||||
<p>
|
||||
As usual, <a href="/cmd/gofix/">gofix</a> will handle the bulk of the rewrites
|
||||
necessary for these changes to package APIs.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/http">Package http</a> has a new
|
||||
<a href="/pkg/http/#FileSystem">FileSystem</a> interface that provides access
|
||||
to files. The <a href="/pkg/http/#FileServer">FileServer</a> helper now takes a
|
||||
<code>FileSystem</code> argument instead of an explicit file system root. By
|
||||
implementing your own <code>FileSystem</code> you can use the
|
||||
<code>FileServer</code> to serve arbitrary data.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/os/">Package os</a>'s <code>ErrorString</code> type has been
|
||||
hidden. Most uses of <code>os.ErrorString</code> can be replaced with
|
||||
<a href="/pkg/os/#NewError">os.NewError</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/reflect/">Package reflect</a> supports a new struct tag scheme
|
||||
that enables sharing of struct tags between multiple packages.
|
||||
In this scheme, the tags must be of the form:
|
||||
</p>
|
||||
<pre>
|
||||
`key:"value" key2:"value2"`
|
||||
</pre>
|
||||
<p>
|
||||
The <a href="/pkg/reflect/#StructField">StructField</a> type's Tag field now
|
||||
has type <a href="/pkg/reflect/#StructTag">StructTag</a>, which has a
|
||||
<code>Get</code> method. Clients of <a href="/pkg/json">json</a> and
|
||||
<a href="/pkg/xml">xml</a> will need to be updated. Code that says
|
||||
</p>
|
||||
<pre>
|
||||
type T struct {
|
||||
X int "name"
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
should become
|
||||
</p>
|
||||
<pre>
|
||||
type T struct {
|
||||
X int `json:"name"` // or `xml:"name"`
|
||||
}
|
||||
</pre>
|
||||
<p>
|
||||
Use <a href="/cmd/govet/">govet</a> to identify struct tags that need to be
|
||||
changed to use the new syntax.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/sort/">Package sort</a>'s <code>IntArray</code> type has been
|
||||
renamed to <a href="/pkg/sort/#IntSlice">IntSlice</a>, and similarly for
|
||||
<a href="/pkg/sort/#Float64Slice">Float64Slice</a> and
|
||||
<a href="/pkg/sort/#StringSlice">StringSlice</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/strings/">Package strings</a>'s <code>Split</code> function has
|
||||
itself been split into <a href="/pkg/strings/#Split">Split</a> and
|
||||
<a href="/pkg/strings/#SplitN">SplitN</a>.
|
||||
<code>SplitN</code> is the same as the old <code>Split</code>.
|
||||
The new <code>Split</code> is equivalent to <code>SplitN</code> with a final
|
||||
argument of -1.
|
||||
</p>
|
||||
|
||||
<a href="/pkg/image/draw/">Package image/draw</a>'s
|
||||
<a href="/pkg/image/draw/#Draw">Draw</a> function now takes an additional
|
||||
argument, a compositing operator.
|
||||
If in doubt, use <a href="/pkg/image/draw/#Op">draw.Over</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="r59.cmd">Tools</h3>
|
||||
|
||||
<p>
|
||||
<a href="/cmd/goinstall/">Goinstall</a> now installs packages and commands from
|
||||
arbitrary remote repositories (not just Google Code, Github, and so on).
|
||||
See the <a href="/cmd/goinstall/">goinstall documentation</a> for details.
|
||||
</p>
|
||||
|
||||
<h2 id="r58">r58 (released 2011/06/29)</h2>
|
||||
|
||||
<p>
|
||||
The r58 release corresponds to
|
||||
<code><a href="weekly.html#2011-06-09">weekly.2011-06-09</a></code>
|
||||
with additional bug fixes.
|
||||
This section highlights the most significant changes in this release.
|
||||
For a more detailed summary, see the
|
||||
<a href="weekly.html#2011-06-09">weekly release notes</a>.
|
||||
For complete information, see the
|
||||
<a href="//code.google.com/p/go/source/list?r=release-branch.r58">Mercurial change list</a>.
|
||||
</p>
|
||||
|
||||
<h3 id="r58.lang">Language</h3>
|
||||
|
||||
<p>
|
||||
This release fixes a <a href="//golang.org/change/b720749486e1">use of uninitialized memory in programs that misuse <code>goto</code></a>.
|
||||
</p>
|
||||
|
||||
<h3 id="r58.pkg">Packages</h3>
|
||||
|
||||
<p>
|
||||
As usual, <a href="/cmd/gofix/">gofix</a> will handle the bulk of the rewrites
|
||||
necessary for these changes to package APIs.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/http/">Package http</a> drops the <code>finalURL</code> return
|
||||
value from the <a href="/pkg/http/#Client.Get">Client.Get</a> method. The value
|
||||
is now available via the new <code>Request</code> field on <a
|
||||
href="/pkg/http/#Response">http.Response</a>.
|
||||
Most instances of the type map[string][]string in have been
|
||||
replaced with the new <a href="/pkg/http/#Values">Values</a> type.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/exec/">Package exec</a> has been redesigned with a more
|
||||
convenient and succinct API.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/strconv/">Package strconv</a>'s <a href="/pkg/strconv/#Quote">Quote</a>
|
||||
function now escapes only those Unicode code points not classified as printable
|
||||
by <a href="/pkg/unicode/#IsPrint">unicode.IsPrint</a>.
|
||||
Previously Quote would escape all non-ASCII characters.
|
||||
This also affects the <a href="/pkg/fmt/">fmt</a> package's <code>"%q"</code>
|
||||
formatting directive. The previous quoting behavior is still available via
|
||||
strconv's new <a href="/pkg/strconv/#QuoteToASCII">QuoteToASCII</a> function.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/os/signal/">Package os/signal</a>'s
|
||||
<a href="/pkg/os/#Signal">Signal</a> and
|
||||
<a href="/pkg/os/#UnixSignal">UnixSignal</a> types have been moved to the
|
||||
<a href="/pkg/os/">os</a> package.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/image/draw/">Package image/draw</a> is the new name for
|
||||
<code>exp/draw</code>. The GUI-related code from <code>exp/draw</code> is now
|
||||
located in the <a href="/pkg/exp/gui/">exp/gui</a> package.
|
||||
</p>
|
||||
|
||||
<h3 id="r58.cmd">Tools</h3>
|
||||
|
||||
<p>
|
||||
<a href="/cmd/goinstall/">Goinstall</a> now observes the GOPATH environment
|
||||
variable to build and install your own code and external libraries outside of
|
||||
the Go tree (and avoid writing Makefiles).
|
||||
</p>
|
||||
|
||||
|
||||
<h3 id="r58.minor">Minor revisions</h3>
|
||||
|
||||
<p>r58.1 adds
|
||||
<a href="//golang.org/change/293c25943586">build</a> and
|
||||
<a href="//golang.org/change/bf17e96b6582">runtime</a>
|
||||
changes to make Go run on OS X 10.7 Lion.
|
||||
</p>
|
||||
|
||||
<h2 id="r57">r57 (released 2011/05/03)</h2>
|
||||
|
||||
<p>
|
||||
The r57 release corresponds to
|
||||
<code><a href="weekly.html#2011-04-27">weekly.2011-04-27</a></code>
|
||||
with additional bug fixes.
|
||||
This section highlights the most significant changes in this release.
|
||||
For a more detailed summary, see the
|
||||
<a href="weekly.html#2011-04-27">weekly release notes</a>.
|
||||
For complete information, see the
|
||||
<a href="//code.google.com/p/go/source/list?r=release-branch.r57">Mercurial change list</a>.
|
||||
</p>
|
||||
|
||||
<p>The new <a href="/cmd/gofix">gofix</a> tool finds Go programs that use old APIs and rewrites them to use
|
||||
newer ones. After you update to a new Go release, gofix helps make the
|
||||
necessary changes to your programs. Gofix will handle the http, os, and syscall
|
||||
package changes described below, and we will update the program to keep up with
|
||||
future changes to the libraries.
|
||||
Gofix can’t
|
||||
handle all situations perfectly, so read and test the changes it makes before
|
||||
committing them.
|
||||
See <a href="//blog.golang.org/2011/04/introducing-gofix.html">the gofix blog post</a> for more
|
||||
information.</p>
|
||||
|
||||
<h3 id="r57.lang">Language</h3>
|
||||
|
||||
<p>
|
||||
<a href="/doc/go_spec.html#Receive_operator">Multiple assignment syntax</a> replaces the <code>closed</code> function.
|
||||
The syntax for channel
|
||||
receives allows an optional second assigned value, a boolean value
|
||||
indicating whether the channel is closed. This code:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
v := <-ch
|
||||
if closed(ch) {
|
||||
// channel is closed
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>should now be written as:</p>
|
||||
|
||||
<pre>
|
||||
v, ok := <-ch
|
||||
if !ok {
|
||||
// channel is closed
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p><a href="/doc/go_spec.html#Label_scopes">Unused labels are now illegal</a>, just as unused local variables are.</p>
|
||||
|
||||
<h3 id="r57.pkg">Packages</h3>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/gob/">Package gob</a> will now encode and decode values of types that implement the
|
||||
<a href="/pkg/gob/#GobEncoder">GobEncoder</a> and
|
||||
<a href="/pkg/gob/#GobDecoder">GobDecoder</a> interfaces. This allows types with unexported
|
||||
fields to transmit self-consistent descriptions; examples include
|
||||
<a href="/pkg/big/#Int.GobDecode">big.Int</a> and <a href="/pkg/big/#Rat.GobDecode">big.Rat</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/http/">Package http</a> has been redesigned.
|
||||
For clients, there are new
|
||||
<a href="/pkg/http/#Client">Client</a> and <a href="/pkg/http/#Transport">Transport</a>
|
||||
abstractions that give more control over HTTP details such as headers sent
|
||||
and redirections followed. These abstractions make it easy to implement
|
||||
custom clients that add functionality such as <a href="//code.google.com/p/goauth2/source/browse/oauth/oauth.go">OAuth2</a>.
|
||||
For servers, <a href="/pkg/http/#ResponseWriter">ResponseWriter</a>
|
||||
has dropped its non-essential methods.
|
||||
The Hijack and Flush methods are no longer required;
|
||||
code can test for them by checking whether a specific value implements
|
||||
<a href="/pkg/http/#Hijacker">Hijacker</a> or <a href="/pkg/http/#Flusher">Flusher</a>.
|
||||
The RemoteAddr and UsingTLS methods are replaced by <a href="/pkg/http/#Request">Request</a>'s
|
||||
RemoteAddr and TLS fields.
|
||||
The SetHeader method is replaced by a Header method;
|
||||
its result, of type <a href="/pkg/http/#Header">Header</a>,
|
||||
implements Set and other methods.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/net/">Package net</a>
|
||||
drops the <code>laddr</code> argument from <a href="/pkg/net/#Conn.Dial">Dial</a>
|
||||
and drops the <code>cname</code> return value
|
||||
from <a href="/pkg/net/#LookupHost">LookupHost</a>.
|
||||
The implementation now uses <a href="/cmd/cgo/">cgo</a> to implement
|
||||
network name lookups using the C library getaddrinfo(3)
|
||||
function when possible. This ensures that Go and C programs
|
||||
resolve names the same way and also avoids the OS X
|
||||
application-level firewall.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/os/">Package os</a>
|
||||
introduces simplified <a href="/pkg/os/#File.Open">Open</a>
|
||||
and <a href="/pkg/os/#File.Create">Create</a> functions.
|
||||
The original Open is now available as <a href="/pkg/os/#File.OpenFile">OpenFile</a>.
|
||||
The final three arguments to <a href="/pkg/os/#Process.StartProcess">StartProcess</a>
|
||||
have been replaced by a pointer to a <a href="/pkg/os/#ProcAttr">ProcAttr</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="/pkg/reflect/">Package reflect</a> has been redesigned.
|
||||
<a href="/pkg/reflect/#Type">Type</a> is now an interface that implements
|
||||
all the possible type methods.
|
||||
Instead of a type switch on a Type <code>t</code>, switch on <code>t.Kind()</code>.
|
||||
<a href="/pkg/reflect/#Value">Value</a> is now a struct value that
|
||||
implements all the possible value methods.
|
||||
Instead of a type switch on a Value <code>v</code>, switch on <code>v.Kind()</code>.
|
||||
Typeof and NewValue are now called <a href="/pkg/reflect/#Type.TypeOf">TypeOf</a> and <a href="/pkg/reflect/#Value.ValueOf">ValueOf</a>
|
||||
To create a writable Value, use <code>New(t).Elem()</code> instead of <code>Zero(t)</code>.
|
||||
See <a href="//golang.org/change/843855f3c026">the change description</a>
|
||||
for the full details.
|
||||
The new API allows a more efficient implementation of Value
|
||||
that avoids many of the allocations required by the previous API.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Remember that gofix will handle the bulk of the rewrites
|
||||
necessary for these changes to package APIs.
|
||||
</p>
|
||||
|
||||
<h3 id="r57.cmd">Tools</h3>
|
||||
|
||||
<p><a href="/cmd/gofix/">Gofix</a>, a new command, is described above.</p>
|
||||
|
||||
<p>
|
||||
<a href="/cmd/gotest/">Gotest</a> is now a Go program instead of a shell script.
|
||||
The new <code>-test.short</code> flag in combination with package testing's Short function
|
||||
allows you to write tests that can be run in normal or “short” mode;
|
||||
all.bash runs tests in short mode to reduce installation time.
|
||||
The Makefiles know about the flag: use <code>make testshort</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The run-time support now implements CPU and memory profiling.
|
||||
Gotest's new
|
||||
<a href="/cmd/gotest/"><code>-test.cpuprofile</code> and
|
||||
<code>-test.memprofile</code> flags</a> make it easy to
|
||||
profile tests.
|
||||
To add profiling to your web server, see the <a href="/pkg/http/pprof/">http/pprof</a>
|
||||
documentation.
|
||||
For other uses, see the <a href="/pkg/runtime/pprof/">runtime/pprof</a> documentation.
|
||||
</p>
|
||||
|
||||
<h3 id="r57.minor">Minor revisions</h3>
|
||||
|
||||
<p>r57.1 fixes a <a href="//golang.org/change/ff2bc62726e7145eb2ecc1e0f076998e4a8f86f0">nil pointer dereference in http.FormFile</a>.</p>
|
||||
<p>r57.2 fixes a <a href="//golang.org/change/063b0ff67d8277df03c956208abc068076818dae">use of uninitialized memory in programs that misuse <code>goto</code></a>.</p>
|
||||
|
||||
<h2 id="r56">r56 (released 2011/03/16)</h2>
|
||||
|
||||
<p>
|
||||
The r56 release was the first stable release and corresponds to
|
||||
<code><a href="weekly.html#2011-03-07">weekly.2011-03-07.1</a></code>.
|
||||
The numbering starts at 56 because before this release,
|
||||
what we now consider weekly snapshots were called releases.
|
||||
</p>
|
||||
604
doc/devel/release.html
Normal file
604
doc/devel/release.html
Normal file
@@ -0,0 +1,604 @@
|
||||
<!--{
|
||||
"Title": "Release History"
|
||||
}-->
|
||||
|
||||
<p>This page summarizes the changes between official stable releases of Go.
|
||||
The <a href="//golang.org/change">change log</a> has the full details.</p>
|
||||
|
||||
<p>To update to a specific release, use:</p>
|
||||
|
||||
<pre>
|
||||
git pull
|
||||
git checkout <i>release-branch</i>
|
||||
</pre>
|
||||
|
||||
<h2 id="policy">Release Policy</h2>
|
||||
|
||||
<p>
|
||||
Each major Go release is supported until there are two newer major releases.
|
||||
For example, Go 1.5 was supported until the Go 1.7 release, and Go 1.6 was
|
||||
supported until the Go 1.8 release.
|
||||
We fix critical problems, including <a href="/security">critical security problems</a>,
|
||||
in supported releases as needed by issuing minor revisions
|
||||
(for example, Go 1.6.1, Go 1.6.2, and so on).
|
||||
</p>
|
||||
|
||||
<h2 id="go1.12">go1.12 (released 2019/02/25)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.12 is a major release of Go.
|
||||
Read the <a href="/doc/go1.12">Go 1.12 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.12.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.12.1 (released 2019/03/14) includes fixes to cgo, the compiler, the go
|
||||
command, and the <code>fmt</code>, <code>net/smtp</code>, <code>os</code>,
|
||||
<code>path/filepath</code>, <code>sync</code>, and <code>text/template</code>
|
||||
packages. See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.12.1">Go
|
||||
1.12.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.12.2 (released 2019/04/05) includes fixes to the compiler, the go
|
||||
command, the runtime, and the <code>doc</code>, <code>net</code>,
|
||||
<code>net/http/httputil</code>, and <code>os</code> packages. See the
|
||||
<a href="https://github.com/golang/go/issues?q=milestone%3AGo1.12.2">Go
|
||||
1.12.2 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.12.3 (released 2019/04/08) fixes an issue where using the prebuilt binary
|
||||
releases on older versions of GNU/Linux
|
||||
<a href="https://golang.org/issues/31293">led to failures</a>
|
||||
when linking programs that used cgo.
|
||||
Only Linux users who hit this issue need to update.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.11">go1.11 (released 2018/08/24)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.11 is a major release of Go.
|
||||
Read the <a href="/doc/go1.11">Go 1.11 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.11.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.11.1 (released 2018/10/01) includes fixes to the compiler, documentation, go
|
||||
command, runtime, and the <code>crypto/x509</code>, <code>encoding/json</code>,
|
||||
<code>go/types</code>, <code>net</code>, <code>net/http</code>, and
|
||||
<code>reflect</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.11.1">Go
|
||||
1.11.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.11.2 (released 2018/11/02) includes fixes to the compiler, linker,
|
||||
documentation, go command, and the <code>database/sql</code> and
|
||||
<code>go/types</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.11.2">Go
|
||||
1.11.2 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.11.3 (released 2018/12/12) includes three security fixes to "go get" and
|
||||
the <code>crypto/x509</code> package.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.11.3">Go
|
||||
1.11.3 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.11.4 (released 2018/12/14) includes fixes to cgo, the compiler, linker,
|
||||
runtime, documentation, go command, and the <code>net/http</code> and
|
||||
<code>go/types</code> packages.
|
||||
It includes a fix to a bug introduced in Go 1.11.3 that broke <code>go</code>
|
||||
<code>get</code> for import path patterns containing "<code>...</code>".
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.11.4+label%3ACherryPickApproved">Go
|
||||
1.11.4 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.11.5 (released 2019/01/23) includes a security fix to the
|
||||
<code>crypto/elliptic</code> package. See
|
||||
the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.11.5">Go
|
||||
1.11.5 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.11.6 (released 2019/03/14) includes fixes to cgo, the compiler, linker,
|
||||
runtime, go command, and the <code>crypto/x509</code>, <code>encoding/json</code>,
|
||||
<code>net</code>, and <code>net/url</code> packages. See the
|
||||
<a href="https://github.com/golang/go/issues?q=milestone%3AGo1.11.6">Go
|
||||
1.11.6 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.11.7 (released 2019/04/05) includes fixes to the runtime and the
|
||||
<code>net</code> packages. See the
|
||||
<a href="https://github.com/golang/go/issues?q=milestone%3AGo1.11.7">Go
|
||||
1.11.7 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.11.8 (released 2019/04/08) fixes an issue where using the prebuilt binary
|
||||
releases on older versions of GNU/Linux
|
||||
<a href="https://golang.org/issues/31293">led to failures</a>
|
||||
when linking programs that used cgo.
|
||||
Only Linux users who hit this issue need to update.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.10">go1.10 (released 2018/02/16)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.10 is a major release of Go.
|
||||
Read the <a href="/doc/go1.10">Go 1.10 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.10.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.10.1 (released 2018/03/28) includes fixes to the compiler, runtime, and the
|
||||
<code>archive/zip</code>, <code>crypto/tls</code>, <code>crypto/x509</code>,
|
||||
<code>encoding/json</code>, <code>net</code>, <code>net/http</code>, and
|
||||
<code>net/http/pprof</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.10.1">Go
|
||||
1.10.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.10.2 (released 2018/05/01) includes fixes to the compiler, linker, and go
|
||||
command.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.10.2">Go
|
||||
1.10.2 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.10.3 (released 2018/06/05) includes fixes to the go command, and the
|
||||
<code>crypto/tls</code>, <code>crypto/x509</code>, and <code>strings</code> packages.
|
||||
In particular, it adds <a href="https://go.googlesource.com/go/+/d4e21288e444d3ffd30d1a0737f15ea3fc3b8ad9">
|
||||
minimal support to the go command for the vgo transition</a>.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.10.3">Go
|
||||
1.10.3 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.10.4 (released 2018/08/24) includes fixes to the go command, linker, and the
|
||||
<code>net/http</code>, <code>mime/multipart</code>, <code>ld/macho</code>,
|
||||
<code>bytes</code>, and <code>strings</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.10.4">Go
|
||||
1.10.4 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.10.5 (released 2018/11/02) includes fixes to the go command, linker, runtime
|
||||
and the <code>database/sql</code> package.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.10.5">Go
|
||||
1.10.5 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.10.6 (released 2018/12/12) includes three security fixes to "go get" and
|
||||
the <code>crypto/x509</code> package.
|
||||
It contains the same fixes as Go 1.11.3 and was released at the same time.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.10.6">Go
|
||||
1.10.6 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.10.7 (released 2018/12/14) includes a fix to a bug introduced in Go 1.10.6
|
||||
that broke <code>go</code> <code>get</code> for import path patterns containing
|
||||
"<code>...</code>".
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.10.7+label%3ACherryPickApproved">
|
||||
Go 1.10.7 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.10.8 (released 2019/01/23) includes a security fix to the
|
||||
<code>crypto/elliptic</code> package. See
|
||||
the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.10.8">Go
|
||||
1.10.8 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.9">go1.9 (released 2017/08/24)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.9 is a major release of Go.
|
||||
Read the <a href="/doc/go1.9">Go 1.9 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.9.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.9.1 (released 2017/10/04) includes two security fixes.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.9.1">Go
|
||||
1.9.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.9.2 (released 2017/10/25) includes fixes to the compiler, linker, runtime,
|
||||
documentation, <code>go</code> command,
|
||||
and the <code>crypto/x509</code>, <code>database/sql</code>, <code>log</code>,
|
||||
and <code>net/smtp</code> packages.
|
||||
It includes a fix to a bug introduced in Go 1.9.1 that broke <code>go</code> <code>get</code>
|
||||
of non-Git repositories under certain conditions.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.9.2">Go
|
||||
1.9.2 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.9.3 (released 2018/01/22) includes fixes to the compiler, runtime,
|
||||
and the <code>database/sql</code>, <code>math/big</code>, <code>net/http</code>,
|
||||
and <code>net/url</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.9.3">Go
|
||||
1.9.3 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.9.4 (released 2018/02/07) includes a security fix to “go get”.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.9.4">Go
|
||||
1.9.4</a> milestone on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.9.5 (released 2018/03/28) includes fixes to the compiler, go command, and
|
||||
<code>net/http/pprof</code> package.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.9.5">Go
|
||||
1.9.5 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.9.6 (released 2018/05/01) includes fixes to the compiler and go command.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.9.6">Go
|
||||
1.9.6 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.9.7 (released 2018/06/05) includes fixes to the go command, and the
|
||||
<code>crypto/x509</code>, and <code>strings</code> packages.
|
||||
In particular, it adds <a href="https://go.googlesource.com/go/+/d4e21288e444d3ffd30d1a0737f15ea3fc3b8ad9">
|
||||
minimal support to the go command for the vgo transition</a>.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.9.7">Go
|
||||
1.9.7 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="go1.8">go1.8 (released 2017/02/16)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.8 is a major release of Go.
|
||||
Read the <a href="/doc/go1.8">Go 1.8 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.8.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.8.1 (released 2017/04/07) includes fixes to the compiler, linker, runtime,
|
||||
documentation, <code>go</code> command and the <code>crypto/tls</code>,
|
||||
<code>encoding/xml</code>, <code>image/png</code>, <code>net</code>,
|
||||
<code>net/http</code>, <code>reflect</code>, <code>text/template</code>,
|
||||
and <code>time</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.8.1">Go
|
||||
1.8.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.8.2 (released 2017/05/23) includes a security fix to the
|
||||
<code>crypto/elliptic</code> package.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.8.2">Go
|
||||
1.8.2 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.8.3 (released 2017/05/24) includes fixes to the compiler, runtime,
|
||||
documentation, and the <code>database/sql</code> package.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.8.3">Go
|
||||
1.8.3 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.8.4 (released 2017/10/04) includes two security fixes.
|
||||
It contains the same fixes as Go 1.9.1 and was released at the same time.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.8.4">Go
|
||||
1.8.4 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.8.5 (released 2017/10/25) includes fixes to the compiler, linker, runtime,
|
||||
documentation, <code>go</code> command,
|
||||
and the <code>crypto/x509</code> and <code>net/smtp</code> packages.
|
||||
It includes a fix to a bug introduced in Go 1.8.4 that broke <code>go</code> <code>get</code>
|
||||
of non-Git repositories under certain conditions.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.8.5">Go
|
||||
1.8.5 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.8.6 (released 2018/01/22) includes the same fix in <code>math/big</code>
|
||||
as Go 1.9.3 and was released at the same time.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.8.6">Go
|
||||
1.8.6 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.8.7 (released 2018/02/07) includes a security fix to “go get”.
|
||||
It contains the same fix as Go 1.9.4 and was released at the same time.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.8.7">Go
|
||||
1.8.7</a> milestone on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.7">go1.7 (released 2016/08/15)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.7 is a major release of Go.
|
||||
Read the <a href="/doc/go1.7">Go 1.7 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.7.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.7.1 (released 2016/09/07) includes fixes to the compiler, runtime,
|
||||
documentation, and the <code>compress/flate</code>, <code>hash/crc32</code>,
|
||||
<code>io</code>, <code>net</code>, <code>net/http</code>,
|
||||
<code>path/filepath</code>, <code>reflect</code>, and <code>syscall</code>
|
||||
packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.1">Go
|
||||
1.7.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.7.2 should not be used. It was tagged but not fully released.
|
||||
The release was deferred due to a last minute bug report.
|
||||
Use go1.7.3 instead, and refer to the summary of changes below.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.7.3 (released 2016/10/19) includes fixes to the compiler, runtime,
|
||||
and the <code>crypto/cipher</code>, <code>crypto/tls</code>,
|
||||
<code>net/http</code>, and <code>strings</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.3">Go
|
||||
1.7.3 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.7.4 (released 2016/12/01) includes two security fixes.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.4">Go
|
||||
1.7.4 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.7.5 (released 2017/01/26) includes fixes to the compiler, runtime,
|
||||
and the <code>crypto/x509</code> and <code>time</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.5">Go
|
||||
1.7.5 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.7.6 (released 2017/05/23) includes the same security fix as Go 1.8.2 and
|
||||
was released at the same time.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.8.2">Go
|
||||
1.8.2 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.6">go1.6 (released 2016/02/17)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.6 is a major release of Go.
|
||||
Read the <a href="/doc/go1.6">Go 1.6 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.6.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.6.1 (released 2016/04/12) includes two security fixes.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.6.1">Go
|
||||
1.6.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.6.2 (released 2016/04/20) includes fixes to the compiler, runtime, tools,
|
||||
documentation, and the <code>mime/multipart</code>, <code>net/http</code>, and
|
||||
<code>sort</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.6.2">Go
|
||||
1.6.2 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.6.3 (released 2016/07/17) includes security fixes to the
|
||||
<code>net/http/cgi</code> package and <code>net/http</code> package when used in
|
||||
a CGI environment.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.6.3">Go
|
||||
1.6.3 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.6.4 (released 2016/12/01) includes two security fixes.
|
||||
It contains the same fixes as Go 1.7.4 and was released at the same time.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.4">Go
|
||||
1.7.4 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.5">go1.5 (released 2015/08/19)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.5 is a major release of Go.
|
||||
Read the <a href="/doc/go1.5">Go 1.5 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.5.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.5.1 (released 2015/09/08) includes bug fixes to the compiler, assembler, and
|
||||
the <code>fmt</code>, <code>net/textproto</code>, <code>net/http</code>, and
|
||||
<code>runtime</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.5.1">Go
|
||||
1.5.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.5.2 (released 2015/12/02) includes bug fixes to the compiler, linker, and
|
||||
the <code>mime/multipart</code>, <code>net</code>, and <code>runtime</code>
|
||||
packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.5.2">Go
|
||||
1.5.2 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.5.3 (released 2016/01/13) includes a security fix to the <code>math/big</code> package
|
||||
affecting the <code>crypto/tls</code> package.
|
||||
See the <a href="https://golang.org/s/go153announce">release announcement</a> for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.5.4 (released 2016/04/12) includes two security fixes.
|
||||
It contains the same fixes as Go 1.6.1 and was released at the same time.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.6.1">Go
|
||||
1.6.1 milestone</a> on our issue tracker for details.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.4">go1.4 (released 2014/12/10)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.4 is a major release of Go.
|
||||
Read the <a href="/doc/go1.4">Go 1.4 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.4.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.4.1 (released 2015/01/15) includes bug fixes to the linker and the <code>log</code>, <code>syscall</code>, and <code>runtime</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.4.1">Go 1.4.1 milestone on our issue tracker</a> for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.4.2 (released 2015/02/17) includes bug fixes to the <code>go</code> command, the compiler and linker, and the <code>runtime</code>, <code>syscall</code>, <code>reflect</code>, and <code>math/big</code> packages.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.4.2">Go 1.4.2 milestone on our issue tracker</a> for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.4.3 (released 2015/09/22) includes security fixes to the <code>net/http</code> package and bug fixes to the <code>runtime</code> package.
|
||||
See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.4.3">Go 1.4.3 milestone on our issue tracker</a> for details.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.3">go1.3 (released 2014/06/18)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.3 is a major release of Go.
|
||||
Read the <a href="/doc/go1.3">Go 1.3 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.3.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.3.1 (released 2014/08/13) includes bug fixes to the compiler and the <code>runtime</code>, <code>net</code>, and <code>crypto/rsa</code> packages.
|
||||
See the <a href="https://github.com/golang/go/commits/go1.3.1">change history</a> for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.3.2 (released 2014/09/25) includes bug fixes to cgo and the crypto/tls packages.
|
||||
See the <a href="https://github.com/golang/go/commits/go1.3.2">change history</a> for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.3.3 (released 2014/09/30) includes further bug fixes to cgo, the runtime package, and the nacl port.
|
||||
See the <a href="https://github.com/golang/go/commits/go1.3.3">change history</a> for details.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.2">go1.2 (released 2013/12/01)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.2 is a major release of Go.
|
||||
Read the <a href="/doc/go1.2">Go 1.2 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.2.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.2.1 (released 2014/03/02) includes bug fixes to the <code>runtime</code>, <code>net</code>, and <code>database/sql</code> packages.
|
||||
See the <a href="https://github.com/golang/go/commits/go1.2.1">change history</a> for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.2.2 (released 2014/05/05) includes a
|
||||
<a href="https://github.com/golang/go/commits/go1.2.2">security fix</a>
|
||||
that affects the tour binary included in the binary distributions (thanks to Guillaume T).
|
||||
</p>
|
||||
|
||||
<h2 id="go1.1">go1.1 (released 2013/05/13)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.1 is a major release of Go.
|
||||
Read the <a href="/doc/go1.1">Go 1.1 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.1.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.1.1 (released 2013/06/13) includes several compiler and runtime bug fixes.
|
||||
See the <a href="https://github.com/golang/go/commits/go1.1.1">change history</a> for details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.1.2 (released 2013/08/13) includes fixes to the <code>gc</code> compiler
|
||||
and <code>cgo</code>, and the <code>bufio</code>, <code>runtime</code>,
|
||||
<code>syscall</code>, and <code>time</code> packages.
|
||||
See the <a href="https://github.com/golang/go/commits/go1.1.2">change history</a> for details.
|
||||
If you use package syscall's <code>Getrlimit</code> and <code>Setrlimit</code>
|
||||
functions under Linux on the ARM or 386 architectures, please note change
|
||||
<a href="//golang.org/cl/11803043">11803043</a>
|
||||
that fixes <a href="//golang.org/issue/5949">issue 5949</a>.
|
||||
</p>
|
||||
|
||||
<h2 id="go1">go1 (released 2012/03/28)</h2>
|
||||
|
||||
<p>
|
||||
Go 1 is a major release of Go that will be stable in the long term.
|
||||
Read the <a href="/doc/go1.html">Go 1 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
It is intended that programs written for Go 1 will continue to compile and run
|
||||
correctly, unchanged, under future versions of Go 1.
|
||||
Read the <a href="/doc/go1compat.html">Go 1 compatibility document</a> for more
|
||||
about the future of Go 1.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The go1 release corresponds to
|
||||
<code><a href="weekly.html#2012-03-27">weekly.2012-03-27</a></code>.
|
||||
</p>
|
||||
|
||||
<h3 id="go1.minor">Minor revisions</h3>
|
||||
|
||||
<p>
|
||||
go1.0.1 (released 2012/04/25) was issued to
|
||||
<a href="//golang.org/cl/6061043">fix</a> an
|
||||
<a href="//golang.org/issue/3545">escape analysis bug</a>
|
||||
that can lead to memory corruption.
|
||||
It also includes several minor code and documentation fixes.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.0.2 (released 2012/06/13) was issued to fix two bugs in the implementation
|
||||
of maps using struct or array keys:
|
||||
<a href="//golang.org/issue/3695">issue 3695</a> and
|
||||
<a href="//golang.org/issue/3573">issue 3573</a>.
|
||||
It also includes many minor code and documentation fixes.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
go1.0.3 (released 2012/09/21) includes minor code and documentation fixes.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
See the <a href="https://github.com/golang/go/commits/release-branch.go1">go1 release branch history</a> for the complete list of changes.
|
||||
</p>
|
||||
|
||||
<h2 id="pre.go1">Older releases</h2>
|
||||
|
||||
<p>
|
||||
See the <a href="pre_go1.html">Pre-Go 1 Release History</a> page for notes
|
||||
on earlier releases.
|
||||
</p>
|
||||
|
||||
6200
doc/devel/weekly.html
Normal file
6200
doc/devel/weekly.html
Normal file
File diff suppressed because it is too large
Load Diff
232
doc/docs.html
Normal file
232
doc/docs.html
Normal file
@@ -0,0 +1,232 @@
|
||||
<!--{
|
||||
"Title": "Documentation",
|
||||
"Path": "/doc/",
|
||||
"Template": true
|
||||
}-->
|
||||
|
||||
<p>
|
||||
The Go programming language is an open source project to make programmers more
|
||||
productive.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Go is expressive, concise, clean, and efficient. Its concurrency
|
||||
mechanisms make it easy to write programs that get the most out of multicore
|
||||
and networked machines, while its novel type system enables flexible and
|
||||
modular program construction. Go compiles quickly to machine code yet has the
|
||||
convenience of garbage collection and the power of run-time reflection. It's a
|
||||
fast, statically typed, compiled language that feels like a dynamically typed,
|
||||
interpreted language.
|
||||
</p>
|
||||
|
||||
<div id="manual-nav"></div>
|
||||
|
||||
<h2>Installing Go</h2>
|
||||
|
||||
<h3><a href="/doc/install">Getting Started</a></h3>
|
||||
<p>
|
||||
Instructions for downloading and installing the Go compilers, tools, and
|
||||
libraries.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="learning">Learning Go</h2>
|
||||
|
||||
<img class="gopher" src="/doc/gopher/doc.png"/>
|
||||
|
||||
<h3 id="go_tour">
|
||||
{{if $.GoogleCN}}
|
||||
A Tour of Go
|
||||
{{else}}
|
||||
<a href="//tour.golang.org/">A Tour of Go</a>
|
||||
{{end}}
|
||||
</h3>
|
||||
<p>
|
||||
An interactive introduction to Go in three sections.
|
||||
The first section covers basic syntax and data structures; the second discusses
|
||||
methods and interfaces; and the third introduces Go's concurrency primitives.
|
||||
Each section concludes with a few exercises so you can practice what you've
|
||||
learned. You can {{if not $.GoogleCN}}<a href="//tour.golang.org/">take the tour
|
||||
online</a> or{{end}} install it locally with:
|
||||
</p>
|
||||
<pre>
|
||||
$ go get golang.org/x/tour
|
||||
</pre>
|
||||
<p>
|
||||
This will place the <code>tour</code> binary in your workspace's <code>bin</code> directory.
|
||||
</p>
|
||||
|
||||
<h3 id="code"><a href="code.html">How to write Go code</a></h3>
|
||||
<p>
|
||||
{{if not $.GoogleCN}}
|
||||
Also available as a <a href="//www.youtube.com/watch?v=XCsL89YtqCs">screencast</a>, this
|
||||
{{else}}
|
||||
This
|
||||
{{end}}
|
||||
doc explains how to use the <a href="/cmd/go/">go command</a>
|
||||
to fetch, build, and install packages, commands, and run tests.
|
||||
</p>
|
||||
|
||||
<h3 id="editors"><a href="editors.html">Editor plugins and IDEs</a></h3>
|
||||
<p>
|
||||
A document that summarizes commonly used editor plugins and IDEs with
|
||||
Go support.
|
||||
</p>
|
||||
|
||||
<h3 id="effective_go"><a href="effective_go.html">Effective Go</a></h3>
|
||||
<p>
|
||||
A document that gives tips for writing clear, idiomatic Go code.
|
||||
A must read for any new Go programmer. It augments the tour and
|
||||
the language specification, both of which should be read first.
|
||||
</p>
|
||||
|
||||
<h3 id="diagnostics"><a href="/doc/diagnostics.html">Diagnostics</a></h3>
|
||||
<p>
|
||||
Summarizes tools and methodologies to diagnose problems in Go programs.
|
||||
</p>
|
||||
|
||||
<h3 id="faq"><a href="/doc/faq">Frequently Asked Questions (FAQ)</a></h3>
|
||||
<p>
|
||||
Answers to common questions about Go.
|
||||
</p>
|
||||
|
||||
<h3 id="wiki"><a href="/wiki">The Go Wiki</a></h3>
|
||||
<p>A wiki maintained by the Go community.</p>
|
||||
|
||||
<h4 id="learn_more">More</h4>
|
||||
<p>
|
||||
See the <a href="/wiki/Learn">Learn</a> page at the <a href="/wiki">Wiki</a>
|
||||
for more Go learning resources.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="references">References</h2>
|
||||
|
||||
<h3 id="pkg"><a href="/pkg/">Package Documentation</a></h3>
|
||||
<p>
|
||||
The documentation for the Go standard library.
|
||||
</p>
|
||||
|
||||
<h3 id="cmd"><a href="/doc/cmd">Command Documentation</a></h3>
|
||||
<p>
|
||||
The documentation for the Go tools.
|
||||
</p>
|
||||
|
||||
<h3 id="spec"><a href="/ref/spec">Language Specification</a></h3>
|
||||
<p>
|
||||
The official Go Language specification.
|
||||
</p>
|
||||
|
||||
<h3 id="go_mem"><a href="/ref/mem">The Go Memory Model</a></h3>
|
||||
<p>
|
||||
A document that specifies the conditions under which reads of a variable in
|
||||
one goroutine can be guaranteed to observe values produced by writes to the
|
||||
same variable in a different goroutine.
|
||||
</p>
|
||||
|
||||
<h3 id="release"><a href="/doc/devel/release.html">Release History</a></h3>
|
||||
<p>A summary of the changes between Go releases.</p>
|
||||
|
||||
|
||||
<h2 id="articles">Articles</h2>
|
||||
|
||||
{{if not $.GoogleCN}}
|
||||
<h3 id="blog"><a href="//blog.golang.org/">The Go Blog</a></h3>
|
||||
<p>The official blog of the Go project, featuring news and in-depth articles by
|
||||
the Go team and guests.</p>
|
||||
{{end}}
|
||||
|
||||
<h4>Codewalks</h4>
|
||||
<p>
|
||||
Guided tours of Go programs.
|
||||
</p>
|
||||
<ul>
|
||||
<li><a href="/doc/codewalk/functions">First-Class Functions in Go</a></li>
|
||||
<li><a href="/doc/codewalk/markov">Generating arbitrary text: a Markov chain algorithm</a></li>
|
||||
<li><a href="/doc/codewalk/sharemem">Share Memory by Communicating</a></li>
|
||||
<li><a href="/doc/articles/wiki/">Writing Web Applications</a> - building a simple web application.</li>
|
||||
</ul>
|
||||
|
||||
{{if not $.GoogleCN}}
|
||||
<h4>Language</h4>
|
||||
<ul>
|
||||
<li><a href="/blog/json-rpc-tale-of-interfaces">JSON-RPC: a tale of interfaces</a></li>
|
||||
<li><a href="/blog/gos-declaration-syntax">Go's Declaration Syntax</a></li>
|
||||
<li><a href="/blog/defer-panic-and-recover">Defer, Panic, and Recover</a></li>
|
||||
<li><a href="/blog/go-concurrency-patterns-timing-out-and">Go Concurrency Patterns: Timing out, moving on</a></li>
|
||||
<li><a href="/blog/go-slices-usage-and-internals">Go Slices: usage and internals</a></li>
|
||||
<li><a href="/blog/gif-decoder-exercise-in-go-interfaces">A GIF decoder: an exercise in Go interfaces</a></li>
|
||||
<li><a href="/blog/error-handling-and-go">Error Handling and Go</a></li>
|
||||
<li><a href="/blog/organizing-go-code">Organizing Go code</a></li>
|
||||
</ul>
|
||||
|
||||
<h4>Packages</h4>
|
||||
<ul>
|
||||
<li><a href="/blog/json-and-go">JSON and Go</a> - using the <a href="/pkg/encoding/json/">json</a> package.</li>
|
||||
<li><a href="/blog/gobs-of-data">Gobs of data</a> - the design and use of the <a href="/pkg/encoding/gob/">gob</a> package.</li>
|
||||
<li><a href="/blog/laws-of-reflection">The Laws of Reflection</a> - the fundamentals of the <a href="/pkg/reflect/">reflect</a> package.</li>
|
||||
<li><a href="/blog/go-image-package">The Go image package</a> - the fundamentals of the <a href="/pkg/image/">image</a> package.</li>
|
||||
<li><a href="/blog/go-imagedraw-package">The Go image/draw package</a> - the fundamentals of the <a href="/pkg/image/draw/">image/draw</a> package.</li>
|
||||
</ul>
|
||||
{{end}}
|
||||
|
||||
<h4>Tools</h4>
|
||||
<ul>
|
||||
<li><a href="/doc/articles/go_command.html">About the Go command</a> - why we wrote it, what it is, what it's not, and how to use it.</li>
|
||||
<li><a href="/doc/gdb">Debugging Go Code with GDB</a></li>
|
||||
<li><a href="/doc/articles/race_detector.html">Data Race Detector</a> - a manual for the data race detector.</li>
|
||||
<li><a href="/doc/asm">A Quick Guide to Go's Assembler</a> - an introduction to the assembler used by Go.</li>
|
||||
{{if not $.GoogleCN}}
|
||||
<li><a href="/blog/c-go-cgo">C? Go? Cgo!</a> - linking against C code with <a href="/cmd/cgo/">cgo</a>.</li>
|
||||
<li><a href="/blog/godoc-documenting-go-code">Godoc: documenting Go code</a> - writing good documentation for <a href="/cmd/godoc/">godoc</a>.</li>
|
||||
<li><a href="/blog/profiling-go-programs">Profiling Go Programs</a></li>
|
||||
<li><a href="/blog/race-detector">Introducing the Go Race Detector</a> - an introduction to the race detector.</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
||||
<h4 id="articles_more">More</h4>
|
||||
<p>
|
||||
See the <a href="/wiki/Articles">Articles page</a> at the
|
||||
<a href="/wiki">Wiki</a> for more Go articles.
|
||||
</p>
|
||||
|
||||
{{if not $.GoogleCN}}
|
||||
<h2 id="talks">Talks</h2>
|
||||
|
||||
<img class="gopher" src="/doc/gopher/talks.png"/>
|
||||
|
||||
<h3 id="video_tour_of_go"><a href="https://research.swtch.com/gotour">A Video Tour of Go</a></h3>
|
||||
<p>
|
||||
Three things that make Go fast, fun, and productive:
|
||||
interfaces, reflection, and concurrency. Builds a toy web crawler to
|
||||
demonstrate these.
|
||||
</p>
|
||||
|
||||
<h3 id="go_code_that_grows"><a href="//vimeo.com/53221560">Code that grows with grace</a></h3>
|
||||
<p>
|
||||
One of Go's key design goals is code adaptability; that it should be easy to take a simple design and build upon it in a clean and natural way. In this talk Andrew Gerrand describes a simple "chat roulette" server that matches pairs of incoming TCP connections, and then use Go's concurrency mechanisms, interfaces, and standard library to extend it with a web interface and other features. While the function of the program changes dramatically, Go's flexibility preserves the original design as it grows.
|
||||
</p>
|
||||
|
||||
<h3 id="go_concurrency_patterns"><a href="//www.youtube.com/watch?v=f6kdp27TYZs">Go Concurrency Patterns</a></h3>
|
||||
<p>
|
||||
Concurrency is the key to designing high performance network services. Go's concurrency primitives (goroutines and channels) provide a simple and efficient means of expressing concurrent execution. In this talk we see how tricky concurrency problems can be solved gracefully with simple Go code.
|
||||
</p>
|
||||
|
||||
<h3 id="advanced_go_concurrency_patterns"><a href="//www.youtube.com/watch?v=QDDwwePbDtw">Advanced Go Concurrency Patterns</a></h3>
|
||||
<p>
|
||||
This talk expands on the <i>Go Concurrency Patterns</i> talk to dive deeper into Go's concurrency primitives.
|
||||
</p>
|
||||
|
||||
<h4 id="talks_more">More</h4>
|
||||
<p>
|
||||
See the <a href="/talks">Go Talks site</a> and <a href="/wiki/GoTalks">wiki page</a> for more Go talks.
|
||||
</p>
|
||||
{{end}}
|
||||
|
||||
<h2 id="nonenglish">Non-English Documentation</h2>
|
||||
|
||||
<p>
|
||||
See the <a href="/wiki/NonEnglish">NonEnglish</a> page
|
||||
at the <a href="/wiki">Wiki</a> for localized
|
||||
documentation.
|
||||
</p>
|
||||
@@ -20,7 +20,7 @@ editing, navigation, testing, and debugging experience.
|
||||
|
||||
<ul>
|
||||
<li><a href="https://github.com/fatih/vim-go">vim</a>: vim-go plugin provides Go programming language support</li>
|
||||
<li><a href="https://marketplace.visualstudio.com/items?itemName=golang.go">Visual Studio Code</a>:
|
||||
<li><a href="https://marketplace.visualstudio.com/items?itemName=lukehoban.Go">Visual Studio Code</a>:
|
||||
Go extension provides support for the Go programming language</li>
|
||||
<li><a href="https://www.jetbrains.com/go">GoLand</a>: GoLand is distributed either as a standalone IDE
|
||||
or as a plugin for IntelliJ IDEA Ultimate</li>
|
||||
|
||||
@@ -624,7 +624,7 @@ if it has already been declared, provided:
|
||||
<li>this declaration is in the same scope as the existing declaration of <code>v</code>
|
||||
(if <code>v</code> is already declared in an outer scope, the declaration will create a new variable §),</li>
|
||||
<li>the corresponding value in the initialization is assignable to <code>v</code>, and</li>
|
||||
<li>there is at least one other variable that is created by the declaration.</li>
|
||||
<li>there is at least one other variable in the declaration that is being declared anew.</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
@@ -1680,15 +1680,13 @@ maps. Here is a print statement for the time zone map defined in the previous s
|
||||
fmt.Printf("%v\n", timeZone) // or just fmt.Println(timeZone)
|
||||
</pre>
|
||||
<p>
|
||||
which gives output:
|
||||
which gives output
|
||||
</p>
|
||||
<pre>
|
||||
map[CST:-21600 EST:-18000 MST:-25200 PST:-28800 UTC:0]
|
||||
map[CST:-21600 PST:-28800 EST:-18000 UTC:0 MST:-25200]
|
||||
</pre>
|
||||
<p>
|
||||
For maps, <code>Printf</code> and friends sort the output lexicographically by key.
|
||||
</p>
|
||||
<p>
|
||||
For maps the keys may be output in any order, of course.
|
||||
When printing a struct, the modified format <code>%+v</code> annotates the
|
||||
fields of the structure with their names, and for any value the alternate
|
||||
format <code>%#v</code> prints the value in full Go syntax.
|
||||
@@ -1712,7 +1710,7 @@ prints
|
||||
&{7 -2.35 abc def}
|
||||
&{a:7 b:-2.35 c:abc def}
|
||||
&main.T{a:7, b:-2.35, c:"abc\tdef"}
|
||||
map[string]int{"CST":-21600, "EST":-18000, "MST":-25200, "PST":-28800, "UTC":0}
|
||||
map[string]int{"CST":-21600, "PST":-28800, "EST":-18000, "UTC":0, "MST":-25200}
|
||||
</pre>
|
||||
<p>
|
||||
(Note the ampersands.)
|
||||
@@ -2282,8 +2280,8 @@ The <code>crypto/cipher</code> interfaces look like this:
|
||||
<pre>
|
||||
type Block interface {
|
||||
BlockSize() int
|
||||
Encrypt(dst, src []byte)
|
||||
Decrypt(dst, src []byte)
|
||||
Encrypt(src, dst []byte)
|
||||
Decrypt(src, dst []byte)
|
||||
}
|
||||
|
||||
type Stream interface {
|
||||
@@ -2336,9 +2334,10 @@ of the request from the client.
|
||||
</p>
|
||||
<p>
|
||||
For brevity, let's ignore POSTs and assume HTTP requests are always
|
||||
GETs; that simplification does not affect the way the handlers are set up.
|
||||
Here's a trivial implementation of a handler to count the number of times
|
||||
the page is visited.
|
||||
GETs; that simplification does not affect the way the handlers are
|
||||
set up. Here's a trivial but complete implementation of a handler to
|
||||
count the number of times the
|
||||
page is visited.
|
||||
</p>
|
||||
<pre>
|
||||
// Simple counter server.
|
||||
@@ -2354,11 +2353,6 @@ func (ctr *Counter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
<p>
|
||||
(Keeping with our theme, note how <code>Fprintf</code> can print to an
|
||||
<code>http.ResponseWriter</code>.)
|
||||
In a real server, access to <code>ctr.n</code> would need protection from
|
||||
concurrent access.
|
||||
See the <code>sync</code> and <code>atomic</code> packages for suggestions.
|
||||
</p>
|
||||
<p>
|
||||
For reference, here's how to attach such a server to a node on the URL tree.
|
||||
</p>
|
||||
<pre>
|
||||
@@ -2699,7 +2693,8 @@ type ReadWriter interface {
|
||||
<p>
|
||||
This says just what it looks like: A <code>ReadWriter</code> can do
|
||||
what a <code>Reader</code> does <em>and</em> what a <code>Writer</code>
|
||||
does; it is a union of the embedded interfaces.
|
||||
does; it is a union of the embedded interfaces (which must be disjoint
|
||||
sets of methods).
|
||||
Only interfaces can be embedded within interfaces.
|
||||
</p>
|
||||
<p>
|
||||
|
||||
@@ -105,7 +105,7 @@ or <code>gcc/testsuite/go.dg</code> directories in the GCC repository.
|
||||
<p>
|
||||
Changes to the Go frontend should follow the same process as for the
|
||||
main Go repository, only for the <code>gofrontend</code> project and
|
||||
the <code>gofrontend-dev@googlegroups.com</code> mailing list
|
||||
the <code>gofrontend-dev@googlegroups.com</code> mailing list
|
||||
rather than the <code>go</code> project and the
|
||||
<code>golang-dev@googlegroups.com</code> mailing list. Those changes
|
||||
will then be merged into the GCC sources.
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
<p>
|
||||
This document explains how to use gccgo, a compiler for
|
||||
the Go language. The gccgo compiler is a new frontend
|
||||
for GCC, the widely used GNU compiler. Although the
|
||||
the Go language. The gccgo compiler is a new frontend
|
||||
for GCC, the widely used GNU compiler. Although the
|
||||
frontend itself is under a BSD-style license, gccgo is
|
||||
normally used as part of GCC and is then covered by
|
||||
the <a href="https://www.gnu.org/licenses/gpl.html">GNU General Public
|
||||
@@ -24,10 +24,10 @@ compiler.
|
||||
|
||||
<p>
|
||||
The simplest way to install gccgo is to install a GCC binary release
|
||||
built to include Go support. GCC binary releases are available from
|
||||
built to include Go support. GCC binary releases are available from
|
||||
<a href="https://gcc.gnu.org/install/binaries.html">various
|
||||
websites</a> and are typically included as part of GNU/Linux
|
||||
distributions. We expect that most people who build these binaries
|
||||
distributions. We expect that most people who build these binaries
|
||||
will include Go support.
|
||||
</p>
|
||||
|
||||
@@ -38,7 +38,7 @@ The GCC 4.7.1 release and all later 4.7 releases include a complete
|
||||
|
||||
<p>
|
||||
Due to timing, the GCC 4.8.0 and 4.8.1 releases are close to but not
|
||||
identical to Go 1.1. The GCC 4.8.2 release includes a complete Go
|
||||
identical to Go 1.1. The GCC 4.8.2 release includes a complete Go
|
||||
1.1.2 implementation.
|
||||
</p>
|
||||
|
||||
@@ -48,51 +48,49 @@ The GCC 4.9 releases include a complete Go 1.2 implementation.
|
||||
|
||||
<p>
|
||||
The GCC 5 releases include a complete implementation of the Go 1.4
|
||||
user libraries. The Go 1.4 runtime is not fully merged, but that
|
||||
user libraries. The Go 1.4 runtime is not fully merged, but that
|
||||
should not be visible to Go programs.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The GCC 6 releases include a complete implementation of the Go 1.6.1
|
||||
user libraries. The Go 1.6 runtime is not fully merged, but that
|
||||
user libraries. The Go 1.6 runtime is not fully merged, but that
|
||||
should not be visible to Go programs.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The GCC 7 releases include a complete implementation of the Go 1.8.1
|
||||
user libraries. As with earlier releases, the Go 1.8 runtime is not
|
||||
user libraries. As with earlier releases, the Go 1.8 runtime is not
|
||||
fully merged, but that should not be visible to Go programs.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The GCC 8 releases include a complete implementation of the Go 1.10.1
|
||||
release. The Go 1.10 runtime has now been fully merged into the GCC
|
||||
development sources, and concurrent garbage collection is fully
|
||||
supported.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The GCC 9 releases include a complete implementation of the Go 1.12.2
|
||||
release.
|
||||
The GCC 8 releases are expected to include a complete implementation
|
||||
of the Go 1.10 release, depending on release timing. The Go 1.10
|
||||
runtime has now been fully merged into the GCC development sources,
|
||||
and concurrent garbage collection is expected to be fully supported in
|
||||
GCC 8.
|
||||
</p>
|
||||
|
||||
<h2 id="Source_code">Source code</h2>
|
||||
|
||||
<p>
|
||||
If you cannot use a release, or prefer to build gccgo for yourself, the
|
||||
gccgo source code is accessible via Git. The GCC web site has
|
||||
<a href="https://gcc.gnu.org/git.html">instructions for getting the GCC
|
||||
source code</a>. The gccgo source code is included. As a convenience, a
|
||||
stable version of the Go support is available in the
|
||||
<code>devel/gccgo</code> branch of the main GCC code repository:
|
||||
<code>git://gcc.gnu.org/git/gcc.git</code>.
|
||||
If you cannot use a release, or prefer to build gccgo for
|
||||
yourself,
|
||||
the gccgo source code is accessible via Subversion. The
|
||||
GCC web site
|
||||
has <a href="https://gcc.gnu.org/svn.html">instructions for getting the
|
||||
GCC source code</a>. The gccgo source code is included. As a
|
||||
convenience, a stable version of the Go support is available in
|
||||
a branch of the main GCC code
|
||||
repository: <code>svn://gcc.gnu.org/svn/gcc/branches/gccgo</code>.
|
||||
This branch is periodically updated with stable Go compiler sources.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Note that although <code>gcc.gnu.org</code> is the most convenient way
|
||||
to get the source code for the Go frontend, it is not where the master
|
||||
sources live. If you want to contribute changes to the Go frontend
|
||||
sources live. If you want to contribute changes to the Go frontend
|
||||
compiler, see <a href="/doc/gccgo_contribute.html">Contributing to
|
||||
gccgo</a>.
|
||||
</p>
|
||||
@@ -102,16 +100,16 @@ gccgo</a>.
|
||||
|
||||
<p>
|
||||
Building gccgo is just like building GCC
|
||||
with one or two additional options. See
|
||||
with one or two additional options. See
|
||||
the <a href="https://gcc.gnu.org/install/">instructions on the gcc web
|
||||
site</a>. When you run <code>configure</code>, add the
|
||||
site</a>. When you run <code>configure</code>, add the
|
||||
option <code>--enable-languages=c,c++,go</code> (along with other
|
||||
languages you may want to build). If you are targeting a 32-bit x86,
|
||||
languages you may want to build). If you are targeting a 32-bit x86,
|
||||
then you will want to build gccgo to default to
|
||||
supporting locked compare and exchange instructions; do this by also
|
||||
using the <code>configure</code> option <code>--with-arch=i586</code>
|
||||
(or a newer architecture, depending on where you need your programs to
|
||||
run). If you are targeting a 64-bit x86, but sometimes want to use
|
||||
run). If you are targeting a 64-bit x86, but sometimes want to use
|
||||
the <code>-m32</code> option, then use the <code>configure</code>
|
||||
option <code>--with-arch-32=i586</code>.
|
||||
</p>
|
||||
@@ -120,27 +118,30 @@ option <code>--with-arch-32=i586</code>.
|
||||
|
||||
<p>
|
||||
On x86 GNU/Linux systems the gccgo compiler is able to
|
||||
use a small discontiguous stack for goroutines. This permits programs
|
||||
use a small discontiguous stack for goroutines. This permits programs
|
||||
to run many more goroutines, since each goroutine can use a relatively
|
||||
small stack. Doing this requires using the gold linker version 2.22
|
||||
or later. You can either install GNU binutils 2.22 or later, or you
|
||||
small stack. Doing this requires using the gold linker version 2.22
|
||||
or later. You can either install GNU binutils 2.22 or later, or you
|
||||
can build gold yourself.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To build gold yourself, build the GNU binutils,
|
||||
using <code>--enable-gold=default</code> when you run
|
||||
the <code>configure</code> script. Before building, you must install
|
||||
the flex and bison packages. A typical sequence would look like
|
||||
the <code>configure</code> script. Before building, you must install
|
||||
the flex and bison packages. A typical sequence would look like
|
||||
this (you can replace <code>/opt/gold</code> with any directory to
|
||||
which you have write access):
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
git clone git://sourceware.org/git/binutils-gdb.git
|
||||
cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src login
|
||||
[password is "anoncvs"]
|
||||
[The next command will create a directory named src, not binutils]
|
||||
cvs -z 9 -d :pserver:anoncvs@sourceware.org:/cvs/src co binutils
|
||||
mkdir binutils-objdir
|
||||
cd binutils-objdir
|
||||
../binutils-gdb/configure --enable-gold=default --prefix=/opt/gold
|
||||
../src/configure --enable-gold=default --prefix=/opt/gold
|
||||
make
|
||||
make install
|
||||
</pre>
|
||||
@@ -156,7 +157,7 @@ option <code>--with-ld=<var>GOLD_BINARY</var></code>.
|
||||
A number of prerequisites are required to build GCC, as
|
||||
described on
|
||||
the <a href="https://gcc.gnu.org/install/prerequisites.html">gcc web
|
||||
site</a>. It is important to install all the prerequisites before
|
||||
site</a>. It is important to install all the prerequisites before
|
||||
running the gcc <code>configure</code> script.
|
||||
The prerequisite libraries can be conveniently downloaded using the
|
||||
script <code>contrib/download_prerequisites</code> in the GCC sources.
|
||||
@@ -171,7 +172,7 @@ described above):
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
git clone --branch devel/gccgo git://gcc.gnu.org/git/gcc.git gccgo
|
||||
svn checkout svn://gcc.gnu.org/svn/gcc/branches/gccgo gccgo
|
||||
mkdir objdir
|
||||
cd objdir
|
||||
../gccgo/configure --prefix=/opt/gccgo --enable-languages=c,c++,go --with-ld=/opt/gold/bin/ld
|
||||
@@ -182,7 +183,7 @@ make install
|
||||
<h2 id="Using_gccgo">Using gccgo</h2>
|
||||
|
||||
<p>
|
||||
The gccgo compiler works like other gcc frontends. As of GCC 5 the gccgo
|
||||
The gccgo compiler works like other gcc frontends. As of GCC 5 the gccgo
|
||||
installation also includes a version of the <code>go</code> command,
|
||||
which may be used to build Go programs as described at
|
||||
<a href="https://golang.org/cmd/go">https://golang.org/cmd/go</a>.
|
||||
@@ -207,7 +208,7 @@ gccgo -o file file.o
|
||||
|
||||
<p>
|
||||
To run the resulting file, you will need to tell the program where to
|
||||
find the compiled Go packages. There are a few ways to do this:
|
||||
find the compiled Go packages. There are a few ways to do this:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
@@ -225,11 +226,11 @@ export LD_LIBRARY_PATH
|
||||
|
||||
<p>
|
||||
Here <code>${prefix}</code> is the <code>--prefix</code> option used
|
||||
when building gccgo. For a binary install this is
|
||||
normally <code>/usr</code>. Whether to use <code>lib</code>
|
||||
when building gccgo. For a binary install this is
|
||||
normally <code>/usr</code>. Whether to use <code>lib</code>
|
||||
or <code>lib64</code> depends on the target.
|
||||
Typically <code>lib64</code> is correct for x86_64 systems,
|
||||
and <code>lib</code> is correct for other systems. The idea is to
|
||||
and <code>lib</code> is correct for other systems. The idea is to
|
||||
name the directory where <code>libgo.so</code> is found.
|
||||
</p>
|
||||
|
||||
@@ -324,9 +325,9 @@ objcopy -j .go_export FILE.o FILE.gox
|
||||
|
||||
<p>
|
||||
The gccgo compiler will look in the current
|
||||
directory for import files. In more complex scenarios you
|
||||
directory for import files. In more complex scenarios you
|
||||
may pass the <code>-I</code> or <code>-L</code> option to
|
||||
gccgo. Both options take directories to search. The
|
||||
gccgo. Both options take directories to search. The
|
||||
<code>-L</code> option is also passed to the linker.
|
||||
</p>
|
||||
|
||||
@@ -347,11 +348,11 @@ gccgo -o main main.o mypackage.o # Explicitly links with mypackage.o
|
||||
|
||||
<p>
|
||||
If you use the <code>-g</code> option when you compile, you can run
|
||||
<code>gdb</code> on your executable. The debugger has only limited
|
||||
knowledge about Go. You can set breakpoints, single-step,
|
||||
etc. You can print variables, but they will be printed as though they
|
||||
had C/C++ types. For numeric types this doesn't matter. Go strings
|
||||
and interfaces will show up as two-element structures. Go
|
||||
<code>gdb</code> on your executable. The debugger has only limited
|
||||
knowledge about Go. You can set breakpoints, single-step,
|
||||
etc. You can print variables, but they will be printed as though they
|
||||
had C/C++ types. For numeric types this doesn't matter. Go strings
|
||||
and interfaces will show up as two-element structures. Go
|
||||
maps and channels are always represented as C pointers to run-time
|
||||
structures.
|
||||
</p>
|
||||
@@ -398,7 +399,7 @@ assuming that the C pointer does point to 10 elements.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A slice in Go is a structure. The current definition is
|
||||
A slice in Go is a structure. The current definition is
|
||||
(this is <b style="color: red;">subject to change</b>):
|
||||
</p>
|
||||
|
||||
@@ -412,15 +413,15 @@ struct __go_slice {
|
||||
|
||||
<p>
|
||||
The type of a Go function is a pointer to a struct (this is
|
||||
<b style="color: red;">subject to change</b>). The first field in the
|
||||
<b style="color: red;">subject to change</b>). The first field in the
|
||||
struct points to the code of the function, which will be equivalent to
|
||||
a pointer to a C function whose parameter types are equivalent, with
|
||||
an additional trailing parameter. The trailing parameter is the
|
||||
an additional trailing parameter. The trailing parameter is the
|
||||
closure, and the argument to pass is a pointer to the Go function
|
||||
struct.
|
||||
|
||||
When a Go function returns more than one value, the C function returns
|
||||
a struct. For example, these functions are roughly equivalent:
|
||||
a struct. For example, these functions are roughly equivalent:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
@@ -457,7 +458,7 @@ pointer while the C function is still using it.
|
||||
<p>
|
||||
Go code can call C functions directly using a Go extension implemented
|
||||
in gccgo: a function declaration may be preceded by
|
||||
<code>//extern NAME</code>. For example, here is how the C function
|
||||
<code>//extern NAME</code>. For example, here is how the C function
|
||||
<code>open</code> can be declared in Go:
|
||||
</p>
|
||||
|
||||
@@ -517,11 +518,11 @@ the <code>-gccgo</code> option instead.
|
||||
|
||||
<p>
|
||||
Compile your C code as usual, and add the option
|
||||
<code>-fdump-go-spec=<var>FILENAME</var></code>. This will create the
|
||||
<code>-fdump-go-spec=<var>FILENAME</var></code>. This will create the
|
||||
file <code><var>FILENAME</var></code> as a side effect of the
|
||||
compilation. This file will contain Go declarations for the types,
|
||||
variables and functions declared in the C code. C types that can not
|
||||
be represented in Go will be recorded as comments in the Go code. The
|
||||
compilation. This file will contain Go declarations for the types,
|
||||
variables and functions declared in the C code. C types that can not
|
||||
be represented in Go will be recorded as comments in the Go code. The
|
||||
generated file will not have a <code>package</code> declaration, but
|
||||
can otherwise be compiled directly by gccgo.
|
||||
</p>
|
||||
|
||||
@@ -12,7 +12,7 @@ Do not send CLs removing the interior tags from such phrases.
|
||||
-->
|
||||
|
||||
<style>
|
||||
main ul li { margin: 0.5em 0; }
|
||||
ul li { margin: 0.5em 0; }
|
||||
</style>
|
||||
|
||||
<h2 id="introduction">Introduction to Go 1.10</h2>
|
||||
@@ -30,7 +30,7 @@ adds <a href="#test">caching of successful test results</a>,
|
||||
runs <a href="#test-vet">vet automatically during tests</a>,
|
||||
and
|
||||
permits <a href="#cgo">passing string values directly between Go and C using cgo</a>.
|
||||
A new <a href="#cgo">hard-coded set of safe compiler options</a> may cause
|
||||
A new <a href="#cgo">compiler option whitelist</a> may cause
|
||||
unexpected <a href="https://golang.org/s/invalidflag"><code>invalid
|
||||
flag</code></a> errors in code that built successfully with older
|
||||
releases.
|
||||
@@ -267,7 +267,7 @@ and the <a href="/cmd/test2json/">test2json documentation</a>.
|
||||
|
||||
<p>
|
||||
Options specified by cgo using <code>#cgo CFLAGS</code> and the like
|
||||
are now checked against a list of permitted options.
|
||||
are now checked against a whitelist of permitted options.
|
||||
This closes a security hole in which a downloaded package uses
|
||||
compiler options like
|
||||
<span style="white-space: nowrap"><code>-fplugin</code></span>
|
||||
|
||||
@@ -12,7 +12,7 @@ Do not send CLs removing the interior tags from such phrases.
|
||||
-->
|
||||
|
||||
<style>
|
||||
main ul li { margin: 0.5em 0; }
|
||||
ul li { margin: 0.5em 0; }
|
||||
</style>
|
||||
|
||||
<h2 id="introduction">Introduction to Go 1.11</h2>
|
||||
@@ -826,7 +826,7 @@ for k := range m {
|
||||
|
||||
<!-- CL 101715 was reverted -->
|
||||
|
||||
<dl id="pkg-runtime"><dt id="runtime-again"><a href="/pkg/runtime/">runtime</a></dt>
|
||||
<dl id="runtime-again"><dt><a href="/pkg/runtime/">runtime</a></dt>
|
||||
<dd>
|
||||
|
||||
<p><!-- CL 70993 -->
|
||||
|
||||
@@ -12,7 +12,7 @@ Do not send CLs removing the interior tags from such phrases.
|
||||
-->
|
||||
|
||||
<style>
|
||||
main ul li { margin: 0.5em 0; }
|
||||
ul li { margin: 0.5em 0; }
|
||||
</style>
|
||||
|
||||
<h2 id="introduction">Introduction to Go 1.12</h2>
|
||||
@@ -80,10 +80,6 @@ Do not send CLs removing the interior tags from such phrases.
|
||||
checks for private API usage. Since it is considered private,
|
||||
<code>syscall.Getdirentries</code> now always fails with
|
||||
<code>ENOSYS</code> on iOS.
|
||||
Additionally, <a href="/pkg/syscall/#Setrlimit"><code>syscall.Setrlimit</code></a>
|
||||
reports <code>invalid</code> <code>argument</code> in places where it historically
|
||||
succeeded. These consequences are not specific to Go and users should expect
|
||||
behavioral parity with <code>libSystem</code>'s implementation going forward.
|
||||
</p>
|
||||
|
||||
<h2 id="tools">Tools</h2>
|
||||
@@ -795,7 +791,7 @@ for {
|
||||
A new <a href="/pkg/runtime/debug/#BuildInfo"><code>BuildInfo</code></a> type
|
||||
exposes the build information read from the running binary, available only in
|
||||
binaries built with module support. This includes the main package path, main
|
||||
module information, and the module dependencies. This type is given through the
|
||||
module information, and the module dependencies. This type is given though the
|
||||
<a href="/pkg/runtime/debug/#ReadBuildInfo"><code>ReadBuildInfo</code></a> function
|
||||
on <a href="/pkg/runtime/debug/#BuildInfo"><code>BuildInfo</code></a>.
|
||||
</p>
|
||||
|
||||
1066
doc/go1.13.html
1066
doc/go1.13.html
File diff suppressed because it is too large
Load Diff
924
doc/go1.14.html
924
doc/go1.14.html
@@ -1,924 +0,0 @@
|
||||
<!--{
|
||||
"Title": "Go 1.14 Release Notes",
|
||||
"Path": "/doc/go1.14"
|
||||
}-->
|
||||
|
||||
<!--
|
||||
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.14</h2>
|
||||
|
||||
<p>
|
||||
The latest Go release, version 1.14, arrives six months after <a href="go1.13">Go 1.13</a>.
|
||||
Most of its changes are in the implementation of the toolchain, runtime, and libraries.
|
||||
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>
|
||||
Module support in the <code>go</code> command is now ready for production use,
|
||||
and we encourage all users to <a href="https://blog.golang.org/migrating-to-go-modules">migrate to Go
|
||||
modules for dependency management</a>. If you are unable to migrate due to a problem in the Go
|
||||
toolchain, please ensure that the problem has an
|
||||
<a href="https://golang.org/issue?q=is%3Aissue+is%3Aopen+label%3Amodules">open issue</a>
|
||||
filed. (If the issue is not on the <code>Go1.15</code> milestone, please let us
|
||||
know why it prevents you from migrating so that we can prioritize it
|
||||
appropriately.)
|
||||
</p>
|
||||
|
||||
<h2 id="language">Changes to the language</h2>
|
||||
|
||||
<p>
|
||||
Per the <a href="https://github.com/golang/proposal/blob/master/design/6977-overlapping-interfaces.md">overlapping interfaces proposal</a>,
|
||||
Go 1.14 now permits embedding of interfaces with overlapping method sets:
|
||||
methods from an embedded interface may have the same names and identical signatures
|
||||
as methods already present in the (embedding) interface. This solves problems that typically
|
||||
(but not exclusively) occur with diamond-shaped embedding graphs.
|
||||
Explicitly declared methods in an interface must remain
|
||||
<a href="https://tip.golang.org/ref/spec#Uniqueness_of_identifiers">unique</a>, as before.
|
||||
</p>
|
||||
|
||||
<h2 id="ports">Ports</h2>
|
||||
|
||||
<h3 id="darwin">Darwin</h3>
|
||||
|
||||
<p>
|
||||
Go 1.14 is the last release that will run on macOS 10.11 El Capitan.
|
||||
Go 1.15 will require macOS 10.12 Sierra or later.
|
||||
</p>
|
||||
|
||||
<p><!-- golang.org/issue/34749 -->
|
||||
Go 1.14 is the last Go release to support 32-bit binaries on
|
||||
macOS (the <code>darwin/386</code> port). They are no longer
|
||||
supported by macOS, starting with macOS 10.15 (Catalina).
|
||||
Go continues to support the 64-bit <code>darwin/amd64</code> port.
|
||||
</p>
|
||||
|
||||
<p><!-- golang.org/issue/34751 -->
|
||||
Go 1.14 will likely be the last Go release to support 32-bit
|
||||
binaries on iOS, iPadOS, watchOS, and tvOS
|
||||
(the <code>darwin/arm</code> port). Go continues to support the
|
||||
64-bit <code>darwin/arm64</code> port.
|
||||
</p>
|
||||
|
||||
<h3 id="windows">Windows</h3>
|
||||
|
||||
<p><!-- CL 203601 -->
|
||||
Go binaries on Windows now
|
||||
have <a href="https://docs.microsoft.com/en-us/windows/win32/memory/data-execution-prevention">DEP
|
||||
(Data Execution Prevention)</a> enabled.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 202439 -->
|
||||
On Windows, creating a file
|
||||
via <a href="/pkg/os#CreateFile"><code>os.OpenFile</code></a> with
|
||||
the <a href="/pkg/os/#O_CREATE"><code>os.O_CREATE</code></a> flag, or
|
||||
via <a href="/pkg/syscall#Open"><code>syscall.Open</code></a> with
|
||||
the <a href="/pkg/syscall#O_CREAT"><code>syscall.O_CREAT</code></a>
|
||||
flag, will now create the file as read-only if the
|
||||
bit <code>0o200</code> (owner write permission) is not set in the
|
||||
permission argument. This makes the behavior on Windows more like
|
||||
that on Unix systems.
|
||||
</p>
|
||||
|
||||
<h3 id="wasm">WebAssembly</h3>
|
||||
|
||||
<p><!-- CL 203600 -->
|
||||
JavaScript values referenced from Go via <code>js.Value</code>
|
||||
objects can now be garbage collected.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 203600 -->
|
||||
<code>js.Value</code> values can no longer be compared using
|
||||
the <code>==</code> operator, and instead must be compared using
|
||||
their <code>Equal</code> method.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 203600 -->
|
||||
<code>js.Value</code> now
|
||||
has <code>IsUndefined</code>, <code>IsNull</code>,
|
||||
and <code>IsNaN</code> methods.
|
||||
</p>
|
||||
|
||||
<h3 id="riscv">RISC-V</h3>
|
||||
|
||||
<p><!-- Issue 27532 -->
|
||||
Go 1.14 contains experimental support for 64-bit RISC-V on Linux
|
||||
(<code>GOOS=linux</code>, <code>GOARCH=riscv64</code>). Be aware
|
||||
that performance, assembly syntax stability, and possibly
|
||||
correctness are a work in progress.
|
||||
</p>
|
||||
|
||||
<h3 id="freebsd">FreeBSD</h3>
|
||||
|
||||
<p><!-- CL 199919 -->
|
||||
Go now supports the 64-bit ARM architecture on FreeBSD 12.0 or later (the
|
||||
<code>freebsd/arm64</code> port).
|
||||
</p>
|
||||
|
||||
<h3 id="nacl">Native Client (NaCl)</h3>
|
||||
|
||||
<p><!-- golang.org/issue/30439 -->
|
||||
As <a href="go1.13#ports">announced</a> in the Go 1.13 release notes,
|
||||
Go 1.14 drops support for the Native Client platform (<code>GOOS=nacl</code>).
|
||||
</p>
|
||||
|
||||
<h3 id="illumos">Illumos</h3>
|
||||
|
||||
<p><!-- CL 203758 -->
|
||||
The runtime now respects zone CPU caps
|
||||
(the <code>zone.cpu-cap</code> resource control)
|
||||
for <code>runtime.NumCPU</code> and the default value
|
||||
of <code>GOMAXPROCS</code>.
|
||||
</p>
|
||||
|
||||
<h2 id="tools">Tools</h2>
|
||||
|
||||
<h3 id="go-command">Go command</h3>
|
||||
|
||||
<h4 id="vendor">Vendoring</h4>
|
||||
<!-- golang.org/issue/33848 -->
|
||||
|
||||
<p>
|
||||
When the main module contains a top-level <code>vendor</code> directory and
|
||||
its <code>go.mod</code> file specifies <code>go</code> <code>1.14</code> or
|
||||
higher, the <code>go</code> command now defaults to <code>-mod=vendor</code>
|
||||
for operations that accept that flag. A new value for that flag,
|
||||
<code>-mod=mod</code>, causes the <code>go</code> command to instead load
|
||||
modules from the module cache (as when no <code>vendor</code> directory is
|
||||
present).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
When <code>-mod=vendor</code> is set (explicitly or by default), the
|
||||
<code>go</code> command now verifies that the main module's
|
||||
<code>vendor/modules.txt</code> file is consistent with its
|
||||
<code>go.mod</code> file.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<code>go</code> <code>list</code> <code>-m</code> no longer silently omits
|
||||
transitive dependencies that do not provide packages in
|
||||
the <code>vendor</code> directory. It now fails explicitly if
|
||||
<code>-mod=vendor</code> is set and information is requested for a module not
|
||||
mentioned in <code>vendor/modules.txt</code>.
|
||||
</p>
|
||||
|
||||
<h4 id="go-flags">Flags</h4>
|
||||
|
||||
<p><!-- golang.org/issue/32502, golang.org/issue/30345 -->
|
||||
The <code>go</code> <code>get</code> command no longer accepts
|
||||
the <code>-mod</code> flag. Previously, the flag's setting either
|
||||
<a href="https://golang.org/issue/30345">was ignored</a> or
|
||||
<a href="https://golang.org/issue/32502">caused the build to fail</a>.
|
||||
</p>
|
||||
|
||||
<p><!-- golang.org/issue/33326 -->
|
||||
<code>-mod=readonly</code> is now set by default when the <code>go.mod</code>
|
||||
file is read-only and no top-level <code>vendor</code> directory is present.
|
||||
</p>
|
||||
|
||||
<p><!-- golang.org/issue/31481 -->
|
||||
<code>-modcacherw</code> is a new flag that instructs the <code>go</code>
|
||||
command to leave newly-created directories in the module cache at their
|
||||
default permissions rather than making them read-only.
|
||||
The use of this flag makes it more likely that tests or other tools will
|
||||
accidentally add files not included in the module's verified checksum.
|
||||
However, it allows the use of <code>rm</code> <code>-rf</code>
|
||||
(instead of <code>go</code> <code>clean</code> <code>-modcache</code>)
|
||||
to remove the module cache.
|
||||
</p>
|
||||
|
||||
<p><!-- golang.org/issue/34506 -->
|
||||
<code>-modfile=file</code> is a new flag that instructs the <code>go</code>
|
||||
command to read (and possibly write) an alternate <code>go.mod</code> file
|
||||
instead of the one in the module root directory. A file
|
||||
named <code>go.mod</code> must still be present in order to determine the
|
||||
module root directory, but it is not accessed. When <code>-modfile</code> is
|
||||
specified, an alternate <code>go.sum</code> file is also used: its path is
|
||||
derived from the <code>-modfile</code> flag by trimming the <code>.mod</code>
|
||||
extension and appending <code>.sum</code>.
|
||||
</p>
|
||||
|
||||
<h4 id="go-env-vars">Environment variables</h4>
|
||||
|
||||
<p><!-- golang.org/issue/32966 -->
|
||||
<code>GOINSECURE</code> is a new environment variable that instructs
|
||||
the <code>go</code> command to not require an HTTPS connection, and to skip
|
||||
certificate validation, when fetching certain modules directly from their
|
||||
origins. Like the existing <code>GOPRIVATE</code> variable, the value
|
||||
of <code>GOINSECURE</code> is a comma-separated list of glob patterns.
|
||||
</p>
|
||||
|
||||
<h4 id="commands-outside-modules">Commands outside modules</h4>
|
||||
|
||||
<p><!-- golang.org/issue/32027 -->
|
||||
When module-aware mode is enabled explicitly (by setting
|
||||
<code>GO111MODULE=on</code>), most module commands have more
|
||||
limited functionality if no <code>go.mod</code> file is present. For
|
||||
example, <code>go</code> <code>build</code>,
|
||||
<code>go</code> <code>run</code>, and other build commands can only build
|
||||
packages in the standard library and packages specified as <code>.go</code>
|
||||
files on the command line.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Previously, the <code>go</code> command would resolve each package path
|
||||
to the latest version of a module but would not record the module path
|
||||
or version. This resulted in <a href="https://golang.org/issue/32027">slow,
|
||||
non-reproducible builds</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<code>go</code> <code>get</code> continues to work as before, as do
|
||||
<code>go</code> <code>mod</code> <code>download</code> and
|
||||
<code>go</code> <code>list</code> <code>-m</code> with explicit versions.
|
||||
</p>
|
||||
|
||||
<h4 id="incompatible-versions"><code>+incompatible</code> versions</h4>
|
||||
<!-- golang.org/issue/34165 -->
|
||||
|
||||
<p>
|
||||
If the latest version of a module contains a <code>go.mod</code> file,
|
||||
<code>go</code> <code>get</code> will no longer upgrade to an
|
||||
<a href="/cmd/go/#hdr-Module_compatibility_and_semantic_versioning">incompatible</a>
|
||||
major version of that module unless such a version is requested explicitly
|
||||
or is already required.
|
||||
<code>go</code> <code>list</code> also omits incompatible major versions
|
||||
for such a module when fetching directly from version control, but may
|
||||
include them if reported by a proxy.
|
||||
</p>
|
||||
|
||||
|
||||
<h4 id="go.mod"><code>go.mod</code> file maintenance</h4>
|
||||
<!-- golang.org/issue/34822 -->
|
||||
|
||||
<p>
|
||||
<code>go</code> commands other than
|
||||
<code>go</code> <code>mod</code> <code>tidy</code> no longer
|
||||
remove a <code>require</code> directive that specifies a version of an indirect dependency
|
||||
that is already implied by other (transitive) dependencies of the main
|
||||
module.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<code>go</code> commands other than
|
||||
<code>go</code> <code>mod</code> <code>tidy</code> no longer
|
||||
edit the <code>go.mod</code> file if the changes are only cosmetic.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
When <code>-mod=readonly</code> is set, <code>go</code> commands will no
|
||||
longer fail due to a missing <code>go</code> directive or an erroneous
|
||||
<code>// indirect</code> comment.
|
||||
</p>
|
||||
|
||||
<h4 id="module-downloading">Module downloading</h4>
|
||||
|
||||
<p><!-- golang.org/issue/26092 -->
|
||||
The <code>go</code> command now supports Subversion repositories in module mode.
|
||||
</p>
|
||||
|
||||
<p><!-- golang.org/issue/30748 -->
|
||||
The <code>go</code> command now includes snippets of plain-text error messages
|
||||
from module proxies and other HTTP servers.
|
||||
An error message will only be shown if it is valid UTF-8 and consists of only
|
||||
graphic characters and spaces.
|
||||
</p>
|
||||
|
||||
<h4 id="go-test">Testing</h4>
|
||||
|
||||
<p><!-- golang.org/issue/24929 -->
|
||||
<code>go test -v</code> now streams <code>t.Log</code> output as it happens,
|
||||
rather than at the end of all tests.
|
||||
</p>
|
||||
|
||||
<h2 id="runtime">Runtime</h2>
|
||||
|
||||
<p><!-- CL 190098 -->
|
||||
This release improves the performance of most uses
|
||||
of <code>defer</code> to incur almost zero overhead compared to
|
||||
calling the deferred function directly.
|
||||
As a result, <code>defer</code> can now be used in
|
||||
performance-critical code without overhead concerns.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 201760, CL 201762 and many others -->
|
||||
Goroutines are now asynchronously preemptible.
|
||||
As a result, loops without function calls no longer potentially
|
||||
deadlock the scheduler or significantly delay garbage collection.
|
||||
This is supported on all platforms except <code>windows/arm</code>,
|
||||
<code>darwin/arm</code>, <code>js/wasm</code>, and
|
||||
<code>plan9/*</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A consequence of the implementation of preemption is that on Unix
|
||||
systems, including Linux and macOS systems, programs built with Go
|
||||
1.14 will receive more signals than programs built with earlier
|
||||
releases.
|
||||
This means that programs that use packages
|
||||
like <a href="/pkg/syscall/"><code>syscall</code></a>
|
||||
or <a href="https://godoc.org/golang.org/x/sys/unix"><code>golang.org/x/sys/unix</code></a>
|
||||
will see more slow system calls fail with <code>EINTR</code> errors.
|
||||
Those programs will have to handle those errors in some way, most
|
||||
likely looping to try the system call again. For more
|
||||
information about this
|
||||
see <a href="http://man7.org/linux/man-pages/man7/signal.7.html"><code>man
|
||||
7 signal</code></a> for Linux systems or similar documentation for
|
||||
other systems.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 201765, CL 195701 and many others -->
|
||||
The page allocator is more efficient and incurs significantly less
|
||||
lock contention at high values of <code>GOMAXPROCS</code>.
|
||||
This is most noticeable as lower latency and higher throughput for
|
||||
large allocations being done in parallel and at a high rate.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 171844 and many others -->
|
||||
Internal timers, used by
|
||||
<a href="/pkg/time/#After"><code>time.After</code></a>,
|
||||
<a href="/pkg/time/#Tick"><code>time.Tick</code></a>,
|
||||
<a href="/pkg/net/#Conn"><code>net.Conn.SetDeadline</code></a>,
|
||||
and friends, are more efficient, with less lock contention and fewer
|
||||
context switches.
|
||||
This is a performance improvement that should not cause any user
|
||||
visible changes.
|
||||
</p>
|
||||
|
||||
<h2 id="compiler">Compiler</h2>
|
||||
|
||||
<p><!-- CL 162237 -->
|
||||
This release adds <code>-d=checkptr</code> as a compile-time option
|
||||
for adding instrumentation to check that Go code is following
|
||||
<code>unsafe.Pointer</code> safety rules dynamically.
|
||||
This option is enabled by default (except on Windows) with
|
||||
the <code>-race</code> or <code>-msan</code> flags, and can be
|
||||
disabled with <code>-gcflags=all=-d=checkptr=0</code>.
|
||||
Specifically, <code>-d=checkptr</code> checks the following:
|
||||
</p>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
When converting <code>unsafe.Pointer</code> to <code>*T</code>,
|
||||
the resulting pointer must be aligned appropriately
|
||||
for <code>T</code>.
|
||||
</li>
|
||||
<li>
|
||||
If the result of pointer arithmetic points into a Go heap object,
|
||||
one of the <code>unsafe.Pointer</code>-typed operands must point
|
||||
into the same object.
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<p>
|
||||
Using <code>-d=checkptr</code> is not currently recommended on
|
||||
Windows because it causes false alerts in the standard library.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 204338 -->
|
||||
The compiler can now emit machine-readable logs of key optimizations
|
||||
using the <code>-json</code> flag, including inlining, escape
|
||||
analysis, bounds-check elimination, and nil-check elimination.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 196959 -->
|
||||
Detailed escape analysis diagnostics (<code>-m=2</code>) now work again.
|
||||
This had been dropped from the new escape analysis implementation in
|
||||
the previous release.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 196217 -->
|
||||
All Go symbols in macOS binaries now begin with an underscore,
|
||||
following platform conventions.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 202117 -->
|
||||
This release includes experimental support for compiler-inserted
|
||||
coverage instrumentation for fuzzing.
|
||||
See <a href="https://golang.org/issue/14565">issue 14565</a> for more
|
||||
details.
|
||||
This API may change in future releases.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 174704 --><!-- CL 196784 -->
|
||||
Bounds check elimination now uses information from slice creation and can
|
||||
eliminate checks for indexes with types smaller than <code>int</code>.
|
||||
</p>
|
||||
|
||||
<h2 id="library">Core library</h2>
|
||||
|
||||
<h3 id="hash/maphash">New byte sequence hashing package</h3>
|
||||
|
||||
<p> <!-- golang.org/issue/28322, CL 186877 -->
|
||||
Go 1.14 includes a new package,
|
||||
<a href="/pkg/hash/maphash/"><code>hash/maphash</code></a>,
|
||||
which provides hash functions on byte sequences.
|
||||
These hash functions are intended to be used to implement hash tables or
|
||||
other data structures that need to map arbitrary strings or byte
|
||||
sequences to a uniform distribution on unsigned 64-bit integers.
|
||||
</p>
|
||||
<p>
|
||||
The hash functions are collision-resistant but not cryptographically secure.
|
||||
</p>
|
||||
<p>
|
||||
The hash value of a given byte sequence is consistent within a
|
||||
single process, but will be different in different processes.
|
||||
</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="crypto/tls"><dt><a href="/pkg/crypto/tls/">crypto/tls</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 191976 -->
|
||||
Support for SSL version 3.0 (SSLv3) has been removed. Note that SSLv3 is the
|
||||
<a href="https://tools.ietf.org/html/rfc7568">cryptographically broken</a>
|
||||
protocol predating TLS.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 191999 -->
|
||||
TLS 1.3 can't be disabled via the <code>GODEBUG</code> environment
|
||||
variable anymore. Use the
|
||||
<a href="/pkg/crypto/tls/#Config.MaxVersion"><code>Config.MaxVersion</code></a>
|
||||
field to configure TLS versions.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 205059 -->
|
||||
When multiple certificate chains are provided through the
|
||||
<a href="/pkg/crypto/tls/#Config.Certificates"><code>Config.Certificates</code></a>
|
||||
field, the first one compatible with the peer is now automatically
|
||||
selected. This allows for example providing an ECDSA and an RSA
|
||||
certificate, and letting the package automatically select the best one.
|
||||
Note that the performance of this selection is going to be poor unless the
|
||||
<a href="/pkg/crypto/tls/#Certificate.Leaf"><code>Certificate.Leaf</code></a>
|
||||
field is set. The
|
||||
<a href="/pkg/crypto/tls/#Config.NameToCertificate"><code>Config.NameToCertificate</code></a>
|
||||
field, which only supports associating a single certificate with
|
||||
a give name, is now deprecated and should be left as <code>nil</code>.
|
||||
Similarly the
|
||||
<a href="/pkg/crypto/tls/#Config.BuildNameToCertificate"><code>Config.BuildNameToCertificate</code></a>
|
||||
method, which builds the <code>NameToCertificate</code> field
|
||||
from the leaf certificates, is now deprecated and should not be
|
||||
called.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 175517 -->
|
||||
The new <a href="/pkg/crypto/tls/#CipherSuites"><code>CipherSuites</code></a>
|
||||
and <a href="/pkg/crypto/tls/#InsecureCipherSuites"><code>InsecureCipherSuites</code></a>
|
||||
functions return a list of currently implemented cipher suites.
|
||||
The new <a href="/pkg/crypto/tls/#CipherSuiteName"><code>CipherSuiteName</code></a>
|
||||
function returns a name for a cipher suite ID.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 205058, 205057 -->
|
||||
The new <a href="/pkg/crypto/tls/#ClientHelloInfo.SupportsCertificate">
|
||||
<code>(*ClientHelloInfo).SupportsCertificate</code></a> and
|
||||
<a href="/pkg/crypto/tls/#CertificateRequestInfo.SupportsCertificate">
|
||||
<code>(*CertificateRequestInfo).SupportsCertificate</code></a>
|
||||
methods expose whether a peer supports a certain certificate.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 174329 -->
|
||||
The <code>tls</code> package no longer supports the legacy Next Protocol
|
||||
Negotiation (NPN) extension and now only supports ALPN. In previous
|
||||
releases it supported both. There are no API changes and applications
|
||||
should function identically as before. Most other clients and servers have
|
||||
already removed NPN support in favor of the standardized ALPN.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 205063, 205062 -->
|
||||
RSA-PSS signatures are now used when supported in TLS 1.2 handshakes. This
|
||||
won't affect most applications, but custom
|
||||
<a href="/pkg/crypto/tls/#Certificate.PrivateKey"><code>Certificate.PrivateKey</code></a>
|
||||
implementations that don't support RSA-PSS signatures will need to use the new
|
||||
<a href="/pkg/crypto/tls/#Certificate.SupportedSignatureAlgorithms">
|
||||
<code>Certificate.SupportedSignatureAlgorithms</code></a>
|
||||
field to disable them.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 205059, 205059 -->
|
||||
<a href="/pkg/crypto/tls/#Config.Certificates"><code>Config.Certificates</code></a> and
|
||||
<a href="/pkg/crypto/tls/#Config.GetCertificate"><code>Config.GetCertificate</code></a>
|
||||
can now both be nil if
|
||||
<a href="/pkg/crypto/tls/#Config.GetConfigForClient"><code>Config.GetConfigForClient</code></a>
|
||||
is set. If the callbacks return neither certificates nor an error, the
|
||||
<code>unrecognized_name</code> is now sent.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 205058 -->
|
||||
The new <a href="/pkg/crypto/tls/#CertificateRequestInfo.Version"><code>CertificateRequestInfo.Version</code></a>
|
||||
field provides the TLS version to client certificates callbacks.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 205068 -->
|
||||
The new <code>TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256</code> and
|
||||
<code>TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256</code> constants use
|
||||
the final names for the cipher suites previously referred to as
|
||||
<code>TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305</code> and
|
||||
<code>TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305</code>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- crypto/tls -->
|
||||
|
||||
<dl id="crypto/x509"><dt><a href="/pkg/crypto/x509/">crypto/x509</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 204046 -->
|
||||
<a href="/pkg/crypto/x509/#Certificate.CreateCRL"><code>Certificate.CreateCRL</code></a>
|
||||
now supports Ed25519 issuers.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl id="debug/dwarf"><dt><a href="/pkg/debug/dwarf/">debug/dwarf</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 175138 -->
|
||||
The <code>debug/dwarf</code> package now supports reading DWARF
|
||||
version 5.
|
||||
</p>
|
||||
<p>
|
||||
The new
|
||||
method <a href="/pkg/debug/dwarf/#Data.AddSection"><code>(*Data).AddSection</code></a>
|
||||
supports adding arbitrary new DWARF sections from the input file
|
||||
to the DWARF <code>Data</code>.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 192698 -->
|
||||
The new
|
||||
method <a href="/pkg/debug/dwarf/#Reader.ByteOrder"><code>(*Reader).ByteOrder</code></a>
|
||||
returns the byte order of the current compilation unit.
|
||||
This may be used to interpret attributes that are encoded in the
|
||||
native ordering, such as location descriptions.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 192699 -->
|
||||
The new
|
||||
method <a href="/pkg/debug/dwarf/#LineReader.Files"><code>(*LineReader).Files</code></a>
|
||||
returns the file name table from a line reader.
|
||||
This may be used to interpret the value of DWARF attributes such
|
||||
as <code>AttrDeclFile</code>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- debug/dwarf -->
|
||||
|
||||
<dl id="encoding/asn1"><dt><a href="/pkg/encoding/asn1/">encoding/asn1</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 126624 -->
|
||||
<a href="/pkg/encoding/asn1/#Unmarshal"><code>Unmarshal</code></a>
|
||||
now supports ASN.1 string type BMPString, represented by the new
|
||||
<a href="/pkg/encoding/asn1/#TagBMPString"><code>TagBMPString</code></a>
|
||||
constant.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- encoding/asn1 -->
|
||||
|
||||
<dl id="encoding/json"><dt><a href="/pkg/encoding/json/">encoding/json</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 200677 -->
|
||||
The <a href="/pkg/encoding/json/#Decoder"><code>Decoder</code></a>
|
||||
type supports a new
|
||||
method <a href="/pkg/encoding/json/#Decoder.InputOffset"><code>InputOffset</code></a>
|
||||
that returns the input stream byte offset of the current
|
||||
decoder position.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 200217 -->
|
||||
<a href="/pkg/encoding/json/#Compact"><code>Compact</code></a> no longer
|
||||
escapes the <code>U+2028</code> and <code>U+2029</code> characters, which
|
||||
was never a documented feature. For proper escaping, see <a
|
||||
href="/pkg/encoding/json/#HTMLEscape"><code>HTMLEscape</code></a>.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 195045 -->
|
||||
<a href="/pkg/encoding/json/#Number"><code>Number</code></a> no longer
|
||||
accepts invalid numbers, to follow the documented behavior more closely.
|
||||
If a program needs to accept invalid numbers like the empty string,
|
||||
consider wrapping the type with <a href="/pkg/encoding/json/#Unmarshaler"><code>Unmarshaler</code></a>.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 200237 -->
|
||||
<a href="/pkg/encoding/json/#Unmarshal"><code>Unmarshal</code></a>
|
||||
can now support map keys with string underlying type which implement
|
||||
<a href="/pkg/encoding/#TextUnmarshaler"><code>encoding.TextUnmarshaler</code></a>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- encoding/json -->
|
||||
|
||||
<dl id="go/build"><dt><a href="/pkg/go/build/">go/build</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 203820, 211657 -->
|
||||
The <a href="/pkg/go/build/#Context"><code>Context</code></a>
|
||||
type has a new field <code>Dir</code> which may be used to set
|
||||
the working directory for the build.
|
||||
The default is the current directory of the running process.
|
||||
In module mode, this is used to locate the main module.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- go/build -->
|
||||
|
||||
<dl id="go/doc"><dt><a href="/pkg/go/doc/">go/doc</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 204830 -->
|
||||
The new
|
||||
function <a href="/pkg/go/doc/#NewFromFiles"><code>NewFromFiles</code></a>
|
||||
computes package documentation from a list
|
||||
of <code>*ast.File</code>'s and associates examples with the
|
||||
appropriate package elements.
|
||||
The new information is available in a new <code>Examples</code>
|
||||
field
|
||||
in the <a href="/pkg/go/doc/#Package"><code>Package</code></a>, <a href="/pkg/go/doc/#Type"><code>Type</code></a>,
|
||||
and <a href="/pkg/go/doc/#Func"><code>Func</code></a> types, and a
|
||||
new <a href="/pkg/go/doc/#Example.Suffix"><code>Suffix</code></a>
|
||||
field in
|
||||
the <a href="/pkg/go/doc/#Example"><code>Example</code></a>
|
||||
type.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- go/doc -->
|
||||
|
||||
<dl id="io/ioutil"><dt><a href="/pkg/io/ioutil/">io/ioutil</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 198488 -->
|
||||
<a href="/pkg/io/ioutil/#TempDir"><code>TempDir</code></a> can now create directories
|
||||
whose names have predictable prefixes and suffixes.
|
||||
As with <a href="/pkg/io/ioutil/#TempFile"><code>TempFile</code></a>, if the pattern
|
||||
contains a '*', the random string replaces the last '*'.
|
||||
</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl id="log"><dt><a href="/pkg/log/">log</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 186182 -->
|
||||
The
|
||||
new <a href="https://tip.golang.org/pkg/log/#pkg-constants"><code>Lmsgprefix</code></a>
|
||||
flag may be used to tell the logging functions to emit the
|
||||
optional output prefix immediately before the log message rather
|
||||
than at the start of the line.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- log -->
|
||||
|
||||
<dl id="math"><dt><a href="/pkg/math/">math</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 127458 -->
|
||||
The new <a href="/pkg/math/#FMA"><code>FMA</code></a> function
|
||||
computes <code>x*y+z</code> in floating point with no
|
||||
intermediate rounding of the <code>x*y</code>
|
||||
computation. Several architectures implement this computation
|
||||
using dedicated hardware instructions for additional performance.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- math -->
|
||||
|
||||
<dl id="math/big"><dt><a href="/pkg/math/big/">math/big</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 164972 -->
|
||||
The <a href="/pkg/math/big/#Int.GCD"><code>GCD</code></a> method
|
||||
now allows the inputs <code>a</code> and <code>b</code> to be
|
||||
zero or negative.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- math/big -->
|
||||
|
||||
<dl id="math/bits"><dt><a href="/pkg/math/bits/">math/bits</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 197838 -->
|
||||
The new functions
|
||||
<a href="/pkg/math/bits/#Rem"><code>Rem</code></a>,
|
||||
<a href="/pkg/math/bits/#Rem32"><code>Rem32</code></a>, and
|
||||
<a href="/pkg/math/bits/#Rem64"><code>Rem64</code></a>
|
||||
support computing a remainder even when the quotient overflows.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- math/bits -->
|
||||
|
||||
<dl id="mime"><dt><a href="/pkg/mime/">mime</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 186927 -->
|
||||
The default type of <code>.js</code> and <code>.mjs</code> files
|
||||
is now <code>text/javascript</code> rather
|
||||
than <code>application/javascript</code>.
|
||||
This is in accordance
|
||||
with <a href="https://datatracker.ietf.org/doc/draft-ietf-dispatch-javascript-mjs/">an
|
||||
IETF draft</a> that treats <code>application/javascript</code> as obsolete.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- mime -->
|
||||
|
||||
<dl id="mime/multipart"><dt><a href="/pkg/mime/multipart/">mime/multipart</a></dt>
|
||||
<dd>
|
||||
<p>
|
||||
The
|
||||
new <a href="/pkg/mime/multipart/#Reader"><code>Reader</code></a>
|
||||
method <a href="/pkg/mime/multipart/#Reader.NextRawPart"><code>NextRawPart</code></a>
|
||||
supports fetching the next MIME part without transparently
|
||||
decoding <code>quoted-printable</code> data.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- mime/multipart -->
|
||||
|
||||
<dl id="net/http"><dt><a href="/pkg/net/http/">net/http</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 200760 -->
|
||||
The new <a href="/pkg/net/http/#Header"><code>Header</code></a>
|
||||
method <a href="/pkg/net/http/#Header.Values"><code>Values</code></a>
|
||||
can be used to fetch all values associated with a
|
||||
canonicalized key.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 61291 -->
|
||||
The
|
||||
new <a href="/pkg/net/http/#Transport"><code>Transport</code></a>
|
||||
field <a href="/pkg/net/http/#Transport.DialTLSContext"><code>DialTLSContext</code></a>
|
||||
can be used to specify an optional dial function for creating
|
||||
TLS connections for non-proxied HTTPS requests.
|
||||
This new field can be used instead
|
||||
of <a href="/pkg/net/http/#Transport.DialTLS"><code>DialTLS</code></a>,
|
||||
which is now considered deprecated; <code>DialTLS</code> will
|
||||
continue to work, but new code should
|
||||
use <code>DialTLSContext</code>, which allows the transport to
|
||||
cancel dials as soon as they are no longer needed.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 192518, CL 194218 -->
|
||||
On Windows, <a href="/pkg/net/http/#ServeFile"><code>ServeFile</code></a> now correctly
|
||||
serves files larger than 2GB.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- net/http -->
|
||||
|
||||
<dl id="net/http/httptest"><dt><a href="/pkg/net/http/httptest/">net/http/httptest</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 201557 -->
|
||||
The
|
||||
new <a href="/pkg/net/http/httptest/#Server"><code>Server</code></a>
|
||||
field <a href="/pkg/net/http/httptest/#Server.EnableHTTP2"><code>EnableHTTP2</code></a>
|
||||
supports enabling HTTP/2 on the test server.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- net/http/httptest -->
|
||||
|
||||
<dl id="net/textproto"><dt><a href="/pkg/net/textproto/">net/textproto</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 200760 -->
|
||||
The
|
||||
new <a href="/pkg/net/textproto/#MIMEHeader"><code>MIMEHeader</code></a>
|
||||
method <a href="/pkg/net/textproto/#MIMEHeader.Values"><code>Values</code></a>
|
||||
can be used to fetch all values associated with a canonicalized
|
||||
key.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- net/textproto -->
|
||||
|
||||
<dl id="net/url"><dt><a href="/pkg/net/url/">net/url</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 185117 -->
|
||||
When parsing of a URL fails
|
||||
(for example by <a href="/pkg/net/url/#Parse"><code>Parse</code></a>
|
||||
or <a href="/pkg/net/url/#ParseRequestURI"><code>ParseRequestURI</code></a>),
|
||||
the resulting <a href="/pkg/net/url/#Error.Error"><code>Error</code></a> message
|
||||
will now quote the unparsable URL.
|
||||
This provides clearer structure and consistency with other parsing errors.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- net/url -->
|
||||
|
||||
<dl id="os/signal"><dt><a href="/pkg/os/signal/">os/signal</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 187739 -->
|
||||
On Windows,
|
||||
the <code>CTRL_CLOSE_EVENT</code>, <code>CTRL_LOGOFF_EVENT</code>,
|
||||
and <code>CTRL_SHUTDOWN_EVENT</code> events now generate
|
||||
a <code>syscall.SIGTERM</code> signal, similar to how Control-C
|
||||
and Control-Break generate a <code>syscall.SIGINT</code> signal.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- os/signal -->
|
||||
|
||||
<dl id="plugin"><dt><a href="/pkg/plugin/">plugin</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 191617 -->
|
||||
The <code>plugin</code> package now supports <code>freebsd/amd64</code>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- plugin -->
|
||||
|
||||
<dl id="reflect"><dt><a href="/pkg/reflect/">reflect</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 85661 -->
|
||||
<a href="/pkg/reflect#StructOf"><code>StructOf</code></a> now
|
||||
supports creating struct types with unexported fields, by
|
||||
setting the <code>PkgPath</code> field in
|
||||
a <code>StructField</code> element.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- reflect -->
|
||||
|
||||
<dl id="pkg-runtime"><dt><a href="/pkg/runtime/">runtime</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 200081 -->
|
||||
<code>runtime.Goexit</code> can no longer be aborted by a
|
||||
recursive <code>panic</code>/<code>recover</code>.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 188297, CL 191785 -->
|
||||
On macOS, <code>SIGPIPE</code> is no longer forwarded to signal
|
||||
handlers installed before the Go runtime is initialized.
|
||||
This is necessary because macOS delivers <code>SIGPIPE</code>
|
||||
<a href="https://golang.org/issue/33384">to the main thread</a>
|
||||
rather than the thread writing to the closed pipe.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- runtime -->
|
||||
|
||||
<dl id="runtime/pprof"><dt><a href="/pkg/runtime/pprof/">runtime/pprof</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 204636, 205097 -->
|
||||
The generated profile no longer includes the pseudo-PCs used for inline
|
||||
marks. Symbol information of inlined functions is encoded in
|
||||
<a href="https://github.com/google/pprof/blob/5e96527/proto/profile.proto#L177-L184">the format</a>
|
||||
the pprof tool expects. This is a fix for the regression introduced
|
||||
during recent releases.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- runtime/pprof -->
|
||||
|
||||
<dl id="strconv"><dt><a href="/pkg/strconv/">strconv</a></dt>
|
||||
<dd>
|
||||
<p>
|
||||
The <a href="/pkg/strconv/#NumError"><code>NumError</code></a>
|
||||
type now has
|
||||
an <a href="/pkg/strconv/#NumError.Unwrap"><code>Unwrap</code></a>
|
||||
method that may be used to retrieve the reason that a conversion
|
||||
failed.
|
||||
This supports using <code>NumError</code> values
|
||||
with <a href="/pkg/errors/#Is"><code>errors.Is</code></a> to see
|
||||
if the underlying error
|
||||
is <a href="/pkg/strconv/#pkg-variables"><code>strconv.ErrRange</code></a>
|
||||
or <a href="/pkg/strconv/#pkg-variables"><code>strconv.ErrSyntax</code></a>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- strconv -->
|
||||
|
||||
<dl id="sync"><dt><a href="/pkg/sync/">sync</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 200577 -->
|
||||
Unlocking a highly contended <code>Mutex</code> now directly
|
||||
yields the CPU to the next goroutine waiting for
|
||||
that <code>Mutex</code>. This significantly improves the
|
||||
performance of highly contended mutexes on high CPU count
|
||||
machines.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- sync -->
|
||||
|
||||
<dl id="testing"><dt><a href="/pkg/testing/">testing</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 201359 -->
|
||||
The testing package now supports cleanup functions, called after
|
||||
a test or benchmark has finished, by calling
|
||||
<a href="/pkg/testing#T.Cleanup"><code>T.Cleanup</code></a> or
|
||||
<a href="/pkg/testing#B.Cleanup"><code>B.Cleanup</code></a> respectively.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- testing -->
|
||||
|
||||
<dl id="text/template"><dt><a href="/pkg/text/template/">text/template</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 206124 -->
|
||||
The text/template package now correctly reports errors when a
|
||||
parenthesized argument is used as a function.
|
||||
This most commonly shows up in erroneous cases like
|
||||
<code>{{if (eq .F "a") or (eq .F "b")}}</code>.
|
||||
This should be written as <code>{{if or (eq .F "a") (eq .F "b")}}</code>.
|
||||
The erroneous case never worked as expected, and will now be
|
||||
reported with an error <code>can't give argument to non-function</code>.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- text/template -->
|
||||
|
||||
<dl id="unicode"><dt><a href="/pkg/unicode/">unicode</a></dt>
|
||||
<dd>
|
||||
<p>
|
||||
The <a href="/pkg/unicode/"><code>unicode</code></a> package and associated
|
||||
support throughout the system has been upgraded from Unicode 11.0 to
|
||||
<a href="https://www.unicode.org/versions/Unicode12.0.0/">Unicode 12.0</a>,
|
||||
which adds 554 new characters, including four new scripts, and 61 new emoji.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- unicode -->
|
||||
1051
doc/go1.15.html
1051
doc/go1.15.html
File diff suppressed because it is too large
Load Diff
191
doc/go1.16.html
191
doc/go1.16.html
@@ -1,191 +0,0 @@
|
||||
<!--{
|
||||
"Title": "Go 1.16 Release Notes",
|
||||
"Path": "/doc/go1.16"
|
||||
}-->
|
||||
|
||||
<!--
|
||||
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">DRAFT RELEASE NOTES — Introduction to Go 1.16</h2>
|
||||
|
||||
<p>
|
||||
<strong>
|
||||
Go 1.16 is not yet released. These are work-in-progress
|
||||
release notes. Go 1.16 is expected to be released in February 2021.
|
||||
</strong>
|
||||
</p>
|
||||
|
||||
<h2 id="language">Changes to the language</h2>
|
||||
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
|
||||
<h2 id="ports">Ports</h2>
|
||||
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
|
||||
<h2 id="tools">Tools</h2>
|
||||
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
|
||||
<h3 id="go-command">Go command</h3>
|
||||
|
||||
<p><!-- golang.org/issue/24031 -->
|
||||
<code>retract</code> directives may now be used in a <code>go.mod</code> file
|
||||
to indicate that certain published versions of the module should not be used
|
||||
by other modules. A module author may retract a version after a severe problem
|
||||
is discovered or if the version was published unintentionally.<br>
|
||||
TODO: write and link to section in golang.org/ref/mod<br>
|
||||
TODO: write and link to tutorial or blog post
|
||||
</p>
|
||||
|
||||
<p><!-- golang.org/issue/29062 -->
|
||||
When using <code>go test</code>, a test that
|
||||
calls <code>os.Exit(0)</code> during execution of a test function
|
||||
will now be considered to fail.
|
||||
This will help catch cases in which a test calls code that calls
|
||||
os.Exit(0) and thereby stops running all future tests.
|
||||
If a <code>TestMain</code> function calls <code>os.Exit(0)</code>
|
||||
that is still considered to be a passing test.
|
||||
</p>
|
||||
|
||||
<h4 id="all-pattern">The <code>all</code> pattern</h4>
|
||||
|
||||
<p><!-- golang.org/cl/240623 -->
|
||||
When the main module's <code>go.mod</code> file
|
||||
declares <code>go</code> <code>1.16</code> or higher, the <code>all</code>
|
||||
package pattern now matches only those packages that are transitively imported
|
||||
by a package or test found in the main module. (Packages imported by <em>tests
|
||||
of</em> packages imported by the main module are no longer included.) This is
|
||||
the same set of packages retained
|
||||
by <code>go</code> <code>mod</code> <code>vendor</code> since Go 1.11.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
|
||||
<h2 id="runtime">Runtime</h2>
|
||||
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
|
||||
<h2 id="compiler">Compiler</h2>
|
||||
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
|
||||
<h2 id="linker">Linker</h2>
|
||||
|
||||
<p>
|
||||
This release includes additional improvements to the Go linker,
|
||||
reducing linker resource usage (both time and memory) and improving
|
||||
code robustness/maintainability. These changes form the second half
|
||||
of a two-release project to
|
||||
<a href="https://golang.org/s/better-linker">modernize the Go
|
||||
linker</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The linker changes in 1.16 extend the 1.15 improvements to all
|
||||
supported architecture/OS combinations (the 1.15 performance improvements
|
||||
were primarily focused on <code>ELF</code>-based OSes and
|
||||
<code>amd64</code> architectures). For a representative set of
|
||||
large Go programs, linking is 20-35% faster than 1.15 and requires
|
||||
5-15% less memory on average for <code>linux/amd64</code>, with larger
|
||||
improvements for other architectures and OSes.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
TODO: update with final numbers later in the release.
|
||||
</p>
|
||||
|
||||
<h2 id="library">Core library</h2>
|
||||
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
|
||||
<h3 id="net"><a href="/pkg/net/">net</a></h3>
|
||||
|
||||
<p><!-- CL 250357 -->
|
||||
The case of I/O on a closed network connection, or I/O on a network
|
||||
connection that is closed before any of the I/O completes, can now
|
||||
be detected using the new <a href="/pkg/net/#ErrClosed">ErrClosed</a> error.
|
||||
A typical use would be <code>errors.Is(err, net.ErrClosed)</code>.
|
||||
In earlier releases the only way to reliably detect this case was to
|
||||
match the string returned by the <code>Error</code> method
|
||||
with <code>"use of closed network connection"</code>.
|
||||
</p>
|
||||
|
||||
|
||||
<h3 id="text/template/parse"><a href="/pkg/text/template/parse/">text/template/parse</a></h3>
|
||||
|
||||
<p><!-- CL 229398, golang.org/issue/34652 -->
|
||||
A new <a href="/pkg/text/template/parse/#CommentNode"><code>CommentNode</code></a>
|
||||
was added to the parse tree. The <a href="/pkg/text/template/parse/#Mode"><code>Mode</code></a>
|
||||
field in the <code>parse.Tree</code> enables access to it.
|
||||
</p>
|
||||
<!-- text/template/parse -->
|
||||
|
||||
<h3 id="unicode"><a href="/pkg/unicode/">unicode</a></h3>
|
||||
|
||||
<p><!-- CL 248765 -->
|
||||
The <a href="/pkg/unicode/"><code>unicode</code></a> package and associated
|
||||
support throughout the system has been upgraded from Unicode 12.0.0 to
|
||||
<a href="https://www.unicode.org/versions/Unicode13.0.0/">Unicode 13.0.0</a>,
|
||||
which adds 5,930 new characters, including four new scripts, and 55 new emoji.
|
||||
Unicode 13.0.0 also designates plane 3 (U+30000-U+3FFFF) as the tertiary
|
||||
ideographic plane.
|
||||
</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>
|
||||
|
||||
<p>
|
||||
TODO
|
||||
</p>
|
||||
|
||||
<dl id="net/http"><dt><a href="/pkg/net/http/">net/http</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 233637 -->
|
||||
In the <a href="/pkg/net/http/"><code>net/http</code></a> package, the
|
||||
behavior of <a href="/pkg/net/http/#StripPrefix"><code>StripPrefix</code></a>
|
||||
has been changed to strip the prefix from the request URL's
|
||||
<code>RawPath</code> field in addition to its <code>Path</code> field.
|
||||
In past releases, only the <code>Path</code> field was trimmed, and so if the
|
||||
request URL contained any escaped characters the URL would be modified to
|
||||
have mismatched <code>Path</code> and <code>RawPath</code> fields.
|
||||
In Go 1.16, <code>StripPrefix</code> trims both fields.
|
||||
If there are escaped characters in the prefix part of the request URL the
|
||||
handler serves a 404 instead of its previous behavior of invoking the
|
||||
underlying handler with a mismatched <code>Path</code>/<code>RawPath</code> pair.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 252497 -->
|
||||
The <a href="/pkg/net/http/"><code>net/http</code></a> package now rejects HTTP range requests
|
||||
of the form <code>"Range": "bytes=--N"</code> where <code>"-N"</code> is a negative suffix length, for
|
||||
example <code>"Range": "bytes=--2"</code>. It now replies with a <code>416 "Range Not Satisfiable"</code> response.
|
||||
</p>
|
||||
</dd>
|
||||
</dl><!-- net/http -->
|
||||
@@ -373,7 +373,7 @@ which can be useful information when debugging deadlocks or performance issues.
|
||||
|
||||
<p>
|
||||
A new package <a href="/pkg/debug/plan9obj/"><code>debug/plan9obj</code></a> was added to the standard library.
|
||||
It implements access to Plan 9 <a href="https://9p.io/magic/man2html/6/a.out">a.out</a> object files.
|
||||
It implements access to Plan 9 <a href="http://plan9.bell-labs.com/magic/man2html/6/a.out">a.out</a> object files.
|
||||
</p>
|
||||
|
||||
<h3 id="major_library_changes">Major changes to the library</h3>
|
||||
|
||||
@@ -10,7 +10,7 @@ Edit .,s;^([a-z][A-Za-z0-9_/]+)\.([A-Z][A-Za-z0-9_]+\.)?([A-Z][A-Za-z0-9_]+)([ .
|
||||
-->
|
||||
|
||||
<style>
|
||||
main ul li { margin: 0.5em 0; }
|
||||
ul li { margin: 0.5em 0; }
|
||||
</style>
|
||||
|
||||
<h2 id="introduction">Introduction to Go 1.6</h2>
|
||||
|
||||
@@ -22,7 +22,7 @@ Do not send CLs removing the interior tags from such phrases.
|
||||
-->
|
||||
|
||||
<style>
|
||||
main ul li { margin: 0.5em 0; }
|
||||
ul li { margin: 0.5em 0; }
|
||||
</style>
|
||||
|
||||
<h2 id="introduction">Introduction to Go 1.7</h2>
|
||||
|
||||
@@ -12,7 +12,7 @@ Do not send CLs removing the interior tags from such phrases.
|
||||
-->
|
||||
|
||||
<style>
|
||||
main ul li { margin: 0.5em 0; }
|
||||
ul li { margin: 0.5em 0; }
|
||||
</style>
|
||||
|
||||
<h2 id="introduction">Introduction to Go 1.8</h2>
|
||||
|
||||
@@ -12,7 +12,7 @@ Do not send CLs removing the interior tags from such phrases.
|
||||
-->
|
||||
|
||||
<style>
|
||||
main ul li { margin: 0.5em 0; }
|
||||
ul li { margin: 0.5em 0; }
|
||||
</style>
|
||||
|
||||
<h2 id="introduction">Introduction to Go 1.9</h2>
|
||||
@@ -862,7 +862,7 @@ version of gccgo.
|
||||
|
||||
</dl><!-- reflect -->
|
||||
|
||||
<dl id="pkg-runtime"><dt><a href="/pkg/runtime/">runtime</a></dt>
|
||||
<dl id="runtime"><dt><a href="/pkg/runtime/">runtime</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 37233, CL 37726 -->
|
||||
Tracebacks generated by the runtime and recorded in profiles are
|
||||
|
||||
@@ -39,7 +39,7 @@ garbage collection, or at least some sort of safe automatic memory management wa
|
||||
|
||||
<p>
|
||||
These considerations led to
|
||||
<a href="https://commandcenter.blogspot.com/2017/09/go-ten-years-and-climbing.html">a
|
||||
<a href="https://commandcenter.blogspot.com/2017/09/go-ten-years-and-climbing.html">a
|
||||
series of discussions</a> from which Go arose, first as a set of ideas and
|
||||
desiderata, then as a language.
|
||||
An overarching goal was that Go do more to help the working programmer
|
||||
@@ -515,7 +515,7 @@ when used well, can result in clean error-handling code.
|
||||
See the <a href="/doc/articles/defer_panic_recover.html">Defer, Panic, and Recover</a> article for details.
|
||||
Also, the <a href="https://blog.golang.org/errors-are-values">Errors are values</a> blog post
|
||||
describes one approach to handling errors cleanly in Go by demonstrating that,
|
||||
since errors are just values, the full power of Go can be deployed in error handling.
|
||||
since errors are just values, the full power of Go can deployed in error handling.
|
||||
</p>
|
||||
|
||||
<h3 id="assertions">
|
||||
@@ -1282,7 +1282,7 @@ Why does "go get" use HTTPS when cloning a repository?</h3>
|
||||
|
||||
<p>
|
||||
Companies often permit outgoing traffic only on the standard TCP ports 80 (HTTP)
|
||||
and 443 (HTTPS), blocking outgoing traffic on other ports, including TCP port 9418
|
||||
and 443 (HTTPS), blocking outgoing traffic on other ports, including TCP port 9418
|
||||
(git) and TCP port 22 (SSH).
|
||||
When using HTTPS instead of HTTP, <code>git</code> enforces certificate validation by
|
||||
default, providing protection against man-in-the-middle, eavesdropping and tampering attacks.
|
||||
@@ -2082,8 +2082,8 @@ At the beginning of the project we considered using LLVM for
|
||||
our performance goals.
|
||||
More important in retrospect, starting with LLVM would have made it
|
||||
harder to introduce some of the ABI and related changes, such as
|
||||
stack management, that Go requires but are not part of the standard
|
||||
C setup.
|
||||
stack management, that Go requires but not are not part of the
|
||||
standard C setup.
|
||||
A new <a href="https://go.googlesource.com/gollvm/">LLVM implementation</a>
|
||||
is starting to come together now, however.
|
||||
</p>
|
||||
|
||||
@@ -273,7 +273,9 @@ func f() {
|
||||
a = "hello, world"
|
||||
<-c
|
||||
}
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
func main() {
|
||||
go f()
|
||||
c <- 0
|
||||
|
||||
346
doc/go_spec.html
346
doc/go_spec.html
@@ -1,6 +1,6 @@
|
||||
<!--{
|
||||
"Title": "The Go Programming Language Specification",
|
||||
"Subtitle": "Version of Jan 14, 2020",
|
||||
"Subtitle": "Version of November 16, 2018",
|
||||
"Path": "/ref/spec"
|
||||
}-->
|
||||
|
||||
@@ -20,8 +20,8 @@ dependencies.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The grammar is compact and simple to parse, allowing for easy analysis
|
||||
by automatic tools such as integrated development environments.
|
||||
The grammar is compact and regular, allowing for easy analysis by
|
||||
automatic tools such as integrated development environments.
|
||||
</p>
|
||||
|
||||
<h2 id="Notation">Notation</h2>
|
||||
@@ -118,7 +118,6 @@ The underscore character <code>_</code> (U+005F) is considered a letter.
|
||||
<pre class="ebnf">
|
||||
letter = unicode_letter | "_" .
|
||||
decimal_digit = "0" … "9" .
|
||||
binary_digit = "0" | "1" .
|
||||
octal_digit = "0" … "7" .
|
||||
hex_digit = "0" … "9" | "A" … "F" | "a" … "f" .
|
||||
</pre>
|
||||
@@ -274,156 +273,71 @@ The following character sequences represent <a href="#Operators">operators</a>
|
||||
<p>
|
||||
An integer literal is a sequence of digits representing an
|
||||
<a href="#Constants">integer constant</a>.
|
||||
An optional prefix sets a non-decimal base: <code>0b</code> or <code>0B</code>
|
||||
for binary, <code>0</code>, <code>0o</code>, or <code>0O</code> for octal,
|
||||
and <code>0x</code> or <code>0X</code> for hexadecimal.
|
||||
A single <code>0</code> is considered a decimal zero.
|
||||
In hexadecimal literals, letters <code>a</code> through <code>f</code>
|
||||
and <code>A</code> through <code>F</code> represent values 10 through 15.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For readability, an underscore character <code>_</code> may appear after
|
||||
a base prefix or between successive digits; such underscores do not change
|
||||
the literal's value.
|
||||
An optional prefix sets a non-decimal base: <code>0</code> for octal, <code>0x</code> or
|
||||
<code>0X</code> for hexadecimal. In hexadecimal literals, letters
|
||||
<code>a-f</code> and <code>A-F</code> represent values 10 through 15.
|
||||
</p>
|
||||
<pre class="ebnf">
|
||||
int_lit = decimal_lit | binary_lit | octal_lit | hex_lit .
|
||||
decimal_lit = "0" | ( "1" … "9" ) [ [ "_" ] decimal_digits ] .
|
||||
binary_lit = "0" ( "b" | "B" ) [ "_" ] binary_digits .
|
||||
octal_lit = "0" [ "o" | "O" ] [ "_" ] octal_digits .
|
||||
hex_lit = "0" ( "x" | "X" ) [ "_" ] hex_digits .
|
||||
|
||||
decimal_digits = decimal_digit { [ "_" ] decimal_digit } .
|
||||
binary_digits = binary_digit { [ "_" ] binary_digit } .
|
||||
octal_digits = octal_digit { [ "_" ] octal_digit } .
|
||||
hex_digits = hex_digit { [ "_" ] hex_digit } .
|
||||
int_lit = decimal_lit | octal_lit | hex_lit .
|
||||
decimal_lit = ( "1" … "9" ) { decimal_digit } .
|
||||
octal_lit = "0" { octal_digit } .
|
||||
hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } .
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
42
|
||||
4_2
|
||||
0600
|
||||
0_600
|
||||
0o600
|
||||
0O600 // second character is capital letter 'O'
|
||||
0xBadFace
|
||||
0xBad_Face
|
||||
0x_67_7a_2f_cc_40_c6
|
||||
170141183460469231731687303715884105727
|
||||
170_141183_460469_231731_687303_715884_105727
|
||||
|
||||
_42 // an identifier, not an integer literal
|
||||
42_ // invalid: _ must separate successive digits
|
||||
4__2 // invalid: only one _ at a time
|
||||
0_xBadFace // invalid: _ must separate successive digits
|
||||
</pre>
|
||||
|
||||
|
||||
<h3 id="Floating-point_literals">Floating-point literals</h3>
|
||||
|
||||
<p>
|
||||
A floating-point literal is a decimal or hexadecimal representation of a
|
||||
A floating-point literal is a decimal representation of a
|
||||
<a href="#Constants">floating-point constant</a>.
|
||||
It has an integer part, a decimal point, a fractional part,
|
||||
and an exponent part. The integer and fractional part comprise
|
||||
decimal digits; the exponent part is an <code>e</code> or <code>E</code>
|
||||
followed by an optionally signed decimal exponent. One of the
|
||||
integer part or the fractional part may be elided; one of the decimal
|
||||
point or the exponent may be elided.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A decimal floating-point literal consists of an integer part (decimal digits),
|
||||
a decimal point, a fractional part (decimal digits), and an exponent part
|
||||
(<code>e</code> or <code>E</code> followed by an optional sign and decimal digits).
|
||||
One of the integer part or the fractional part may be elided; one of the decimal point
|
||||
or the exponent part may be elided.
|
||||
An exponent value exp scales the mantissa (integer and fractional part) by 10<sup>exp</sup>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A hexadecimal floating-point literal consists of a <code>0x</code> or <code>0X</code>
|
||||
prefix, an integer part (hexadecimal digits), a radix point, a fractional part (hexadecimal digits),
|
||||
and an exponent part (<code>p</code> or <code>P</code> followed by an optional sign and decimal digits).
|
||||
One of the integer part or the fractional part may be elided; the radix point may be elided as well,
|
||||
but the exponent part is required. (This syntax matches the one given in IEEE 754-2008 §5.12.3.)
|
||||
An exponent value exp scales the mantissa (integer and fractional part) by 2<sup>exp</sup>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For readability, an underscore character <code>_</code> may appear after
|
||||
a base prefix or between successive digits; such underscores do not change
|
||||
the literal value.
|
||||
</p>
|
||||
|
||||
<pre class="ebnf">
|
||||
float_lit = decimal_float_lit | hex_float_lit .
|
||||
|
||||
decimal_float_lit = decimal_digits "." [ decimal_digits ] [ decimal_exponent ] |
|
||||
decimal_digits decimal_exponent |
|
||||
"." decimal_digits [ decimal_exponent ] .
|
||||
decimal_exponent = ( "e" | "E" ) [ "+" | "-" ] decimal_digits .
|
||||
|
||||
hex_float_lit = "0" ( "x" | "X" ) hex_mantissa hex_exponent .
|
||||
hex_mantissa = [ "_" ] hex_digits "." [ hex_digits ] |
|
||||
[ "_" ] hex_digits |
|
||||
"." hex_digits .
|
||||
hex_exponent = ( "p" | "P" ) [ "+" | "-" ] decimal_digits .
|
||||
float_lit = decimals "." [ decimals ] [ exponent ] |
|
||||
decimals exponent |
|
||||
"." decimals [ exponent ] .
|
||||
decimals = decimal_digit { decimal_digit } .
|
||||
exponent = ( "e" | "E" ) [ "+" | "-" ] decimals .
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
0.
|
||||
72.40
|
||||
072.40 // == 72.40
|
||||
072.40 // == 72.40
|
||||
2.71828
|
||||
1.e+0
|
||||
6.67428e-11
|
||||
1E6
|
||||
.25
|
||||
.12345E+5
|
||||
1_5. // == 15.0
|
||||
0.15e+0_2 // == 15.0
|
||||
|
||||
0x1p-2 // == 0.25
|
||||
0x2.p10 // == 2048.0
|
||||
0x1.Fp+0 // == 1.9375
|
||||
0X.8p-0 // == 0.5
|
||||
0X_1FFFP-16 // == 0.1249847412109375
|
||||
0x15e-2 // == 0x15e - 2 (integer subtraction)
|
||||
|
||||
0x.p1 // invalid: mantissa has no digits
|
||||
1p-2 // invalid: p exponent requires hexadecimal mantissa
|
||||
0x1.5e-2 // invalid: hexadecimal mantissa requires p exponent
|
||||
1_.5 // invalid: _ must separate successive digits
|
||||
1._5 // invalid: _ must separate successive digits
|
||||
1.5_e1 // invalid: _ must separate successive digits
|
||||
1.5e_1 // invalid: _ must separate successive digits
|
||||
1.5e1_ // invalid: _ must separate successive digits
|
||||
</pre>
|
||||
|
||||
|
||||
<h3 id="Imaginary_literals">Imaginary literals</h3>
|
||||
|
||||
<p>
|
||||
An imaginary literal represents the imaginary part of a
|
||||
An imaginary literal is a decimal representation of the imaginary part of a
|
||||
<a href="#Constants">complex constant</a>.
|
||||
It consists of an <a href="#Integer_literals">integer</a> or
|
||||
<a href="#Floating-point_literals">floating-point</a> literal
|
||||
followed by the lower-case letter <code>i</code>.
|
||||
The value of an imaginary literal is the value of the respective
|
||||
integer or floating-point literal multiplied by the imaginary unit <i>i</i>.
|
||||
It consists of a
|
||||
<a href="#Floating-point_literals">floating-point literal</a>
|
||||
or decimal integer followed
|
||||
by the lower-case letter <code>i</code>.
|
||||
</p>
|
||||
|
||||
<pre class="ebnf">
|
||||
imaginary_lit = (decimal_digits | int_lit | float_lit) "i" .
|
||||
imaginary_lit = (decimals | float_lit) "i" .
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
For backward compatibility, an imaginary literal's integer part consisting
|
||||
entirely of decimal digits (and possibly underscores) is considered a decimal
|
||||
integer, even if it starts with a leading <code>0</code>.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
0i
|
||||
0123i // == 123i for backward-compatibility
|
||||
0o123i // == 0o123 * 1i == 83i
|
||||
0xabci // == 0xabc * 1i == 2748i
|
||||
011i // == 11i
|
||||
0.i
|
||||
2.71828i
|
||||
1.e+0i
|
||||
@@ -431,7 +345,6 @@ integer, even if it starts with a leading <code>0</code>.
|
||||
1E6i
|
||||
.25i
|
||||
.12345E+5i
|
||||
0x1p-2i // == 0x1p-2 * 1i == 0.25i
|
||||
</pre>
|
||||
|
||||
|
||||
@@ -448,7 +361,6 @@ of the character itself,
|
||||
while multi-character sequences beginning with a backslash encode
|
||||
values in various formats.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The simplest form represents the single character within the quotes;
|
||||
since Go source text is Unicode characters encoded in UTF-8, multiple
|
||||
@@ -458,7 +370,6 @@ a literal <code>a</code>, Unicode U+0061, value <code>0x61</code>, while
|
||||
<code>'ä'</code> holds two bytes (<code>0xc3</code> <code>0xa4</code>) representing
|
||||
a literal <code>a</code>-dieresis, U+00E4, value <code>0xe4</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Several backslash escapes allow arbitrary values to be encoded as
|
||||
ASCII text. There are four ways to represent the integer value
|
||||
@@ -469,7 +380,6 @@ plain backslash <code>\</code> followed by exactly three octal digits.
|
||||
In each case the value of the literal is the value represented by
|
||||
the digits in the corresponding base.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Although these representations all result in an integer, they have
|
||||
different valid ranges. Octal escapes must represent a value between
|
||||
@@ -478,11 +388,9 @@ by construction. The escapes <code>\u</code> and <code>\U</code>
|
||||
represent Unicode code points so within them some values are illegal,
|
||||
in particular those above <code>0x10FFFF</code> and surrogate halves.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
After a backslash, certain single-character escapes represent special values:
|
||||
</p>
|
||||
|
||||
<pre class="grammar">
|
||||
\a U+0007 alert or bell
|
||||
\b U+0008 backspace
|
||||
@@ -495,7 +403,6 @@ After a backslash, certain single-character escapes represent special values:
|
||||
\' U+0027 single quote (valid escape only within rune literals)
|
||||
\" U+0022 double quote (valid escape only within string literals)
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
All other sequences starting with a backslash are illegal inside rune literals.
|
||||
</p>
|
||||
@@ -539,7 +446,6 @@ A string literal represents a <a href="#Constants">string constant</a>
|
||||
obtained from concatenating a sequence of characters. There are two forms:
|
||||
raw string literals and interpreted string literals.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Raw string literals are character sequences between back quotes, as in
|
||||
<code>`foo`</code>. Within the quotes, any character may appear except
|
||||
@@ -551,7 +457,6 @@ contain newlines.
|
||||
Carriage return characters ('\r') inside raw string literals
|
||||
are discarded from the raw string value.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Interpreted string literals are character sequences between double
|
||||
quotes, as in <code>"bar"</code>.
|
||||
@@ -691,7 +596,6 @@ precision in the language, a compiler may implement them using an
|
||||
internal representation with limited precision. That said, every
|
||||
implementation must:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li>Represent integer constants with at least 256 bits.</li>
|
||||
|
||||
@@ -709,14 +613,12 @@ implementation must:
|
||||
represent a floating-point or complex constant due to limits
|
||||
on precision.</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
These requirements apply both to literal constants and to the result
|
||||
of evaluating <a href="#Constant_expressions">constant
|
||||
expressions</a>.
|
||||
</p>
|
||||
|
||||
|
||||
<h2 id="Variables">Variables</h2>
|
||||
|
||||
<p>
|
||||
@@ -1244,36 +1146,24 @@ The value of an uninitialized variable of interface type is <code>nil</code>.
|
||||
</p>
|
||||
|
||||
<pre class="ebnf">
|
||||
InterfaceType = "interface" "{" { ( MethodSpec | InterfaceTypeName ) ";" } "}" .
|
||||
MethodSpec = MethodName Signature .
|
||||
InterfaceType = "interface" "{" { MethodSpec ";" } "}" .
|
||||
MethodSpec = MethodName Signature | InterfaceTypeName .
|
||||
MethodName = identifier .
|
||||
InterfaceTypeName = TypeName .
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
An interface type may specify methods <i>explicitly</i> through method specifications,
|
||||
or it may <i>embed</i> methods of other interfaces through interface type names.
|
||||
As with all method sets, in an interface type, each method must have a
|
||||
<a href="#Uniqueness_of_identifiers">unique</a>
|
||||
non-<a href="#Blank_identifier">blank</a> name.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
// A simple File interface.
|
||||
// A simple File interface
|
||||
interface {
|
||||
Read([]byte) (int, error)
|
||||
Write([]byte) (int, error)
|
||||
Close() error
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
The name of each explicitly specified method must be <a href="#Uniqueness_of_identifiers">unique</a>
|
||||
and not <a href="#Blank_identifier">blank</a>.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
interface {
|
||||
String() string
|
||||
String() string // illegal: String not unique
|
||||
_(x int) // illegal: method must have non-blank name
|
||||
Read(b Buffer) bool
|
||||
Write(b Buffer) bool
|
||||
Close()
|
||||
}
|
||||
</pre>
|
||||
|
||||
@@ -1284,9 +1174,9 @@ have the method set
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
func (p T) Read(p []byte) (n int, err error)
|
||||
func (p T) Write(p []byte) (n int, err error)
|
||||
func (p T) Close() error
|
||||
func (p T) Read(b Buffer) bool { return … }
|
||||
func (p T) Write(b Buffer) bool { return … }
|
||||
func (p T) Close() { … }
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@@ -1336,41 +1226,27 @@ as the <code>File</code> interface.
|
||||
<p>
|
||||
An interface <code>T</code> may use a (possibly qualified) interface type
|
||||
name <code>E</code> in place of a method specification. This is called
|
||||
<i>embedding</i> interface <code>E</code> in <code>T</code>.
|
||||
The <a href="#Method_sets">method set</a> of <code>T</code> is the <i>union</i>
|
||||
of the method sets of <code>T</code>’s explicitly declared methods and of
|
||||
<code>T</code>’s embedded interfaces.
|
||||
<i>embedding</i> interface <code>E</code> in <code>T</code>; it adds
|
||||
all (exported and non-exported) methods of <code>E</code> to the interface
|
||||
<code>T</code>.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
type Reader interface {
|
||||
Read(p []byte) (n int, err error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
type Writer interface {
|
||||
Write(p []byte) (n int, err error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
// ReadWriter's methods are Read, Write, and Close.
|
||||
type ReadWriter interface {
|
||||
Reader // includes methods of Reader in ReadWriter's method set
|
||||
Writer // includes methods of Writer in ReadWriter's method set
|
||||
Read(b Buffer) bool
|
||||
Write(b Buffer) bool
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
A <i>union</i> of method sets contains the (exported and non-exported)
|
||||
methods of each method set exactly once, and methods with the
|
||||
<a href="#Uniqueness_of_identifiers">same</a> names must
|
||||
have <a href="#Type_identity">identical</a> signatures.
|
||||
</p>
|
||||
type File interface {
|
||||
ReadWriter // same as adding the methods of ReadWriter
|
||||
Locker // same as adding the methods of Locker
|
||||
Close()
|
||||
}
|
||||
|
||||
<pre>
|
||||
type ReadCloser interface {
|
||||
Reader // includes methods of Reader in ReadCloser's method set
|
||||
Close() // illegal: signatures of Reader.Close and Close are different
|
||||
type LockedFile interface {
|
||||
Locker
|
||||
File // illegal: Lock, Unlock not unique
|
||||
Lock() // illegal: Lock not unique
|
||||
}
|
||||
</pre>
|
||||
|
||||
@@ -2042,7 +1918,7 @@ of the last non-empty expression list.
|
||||
<p>
|
||||
A type declaration binds an identifier, the <i>type name</i>, to a <a href="#Types">type</a>.
|
||||
Type declarations come in two forms: alias declarations and type definitions.
|
||||
</p>
|
||||
<p>
|
||||
|
||||
<pre class="ebnf">
|
||||
TypeDecl = "type" ( TypeSpec | "(" { TypeSpec ";" } ")" ) .
|
||||
@@ -2413,7 +2289,7 @@ operand only on the left-hand side of an <a href="#Assignments">assignment</a>.
|
||||
Operand = Literal | OperandName | "(" Expression ")" .
|
||||
Literal = BasicLit | CompositeLit | FunctionLit .
|
||||
BasicLit = int_lit | float_lit | imaginary_lit | rune_lit | string_lit .
|
||||
OperandName = identifier | QualifiedIdent .
|
||||
OperandName = identifier | QualifiedIdent.
|
||||
</pre>
|
||||
|
||||
<h3 id="Qualified_identifiers">Qualified identifiers</h3>
|
||||
@@ -2539,24 +2415,10 @@ For array and slice literals the following rules apply:
|
||||
generates a pointer to a unique <a href="#Variables">variable</a> initialized
|
||||
with the literal's value.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var pointer *Point3D = &Point3D{y: 1000}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Note that the <a href="#The_zero_value">zero value</a> for a slice or map
|
||||
type is not the same as an initialized but empty value of the same type.
|
||||
Consequently, taking the address of an empty slice or map composite literal
|
||||
does not have the same effect as allocating a new slice or map value with
|
||||
<a href="#Allocation">new</a>.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
p1 := &[]int{} // p1 points to an initialized, empty slice with value []int{} and length 0
|
||||
p2 := new([]int) // p2 points to an uninitialized slice with value nil and length 0
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
The length of an array literal is the length specified in the literal type.
|
||||
If fewer elements than the length are provided in the literal, the missing
|
||||
@@ -3288,14 +3150,6 @@ is a <code>nil</code> slice. Otherwise, if the result is a slice, it shares its
|
||||
array with the operand.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var a [10]int
|
||||
s1 := a[3:7] // underlying array of s1 is array a; &s1[2] == &a[5]
|
||||
s2 := s1[1:4] // underlying array of s2 is underlying array of s1 which is array a; &s2[1] == &a[5]
|
||||
s2[1] = 42 // s2[1] == s1[2] == a[5] == 42; they all refer to the same underlying array element
|
||||
</pre>
|
||||
|
||||
|
||||
<h4>Full slice expressions</h4>
|
||||
|
||||
<p>
|
||||
@@ -3532,7 +3386,7 @@ within <code>Greeting</code>, <code>who</code> will have the value
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If the final argument is assignable to a slice type <code>[]T</code>, it is
|
||||
If the final argument is assignable to a slice type <code>[]T</code>, it may be
|
||||
passed unchanged as the value for a <code>...T</code> parameter if the argument
|
||||
is followed by <code>...</code>. In this case no new slice is created.
|
||||
</p>
|
||||
@@ -3585,7 +3439,7 @@ to the type of the other operand.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The right operand in a shift expression must have integer type
|
||||
The right operand in a shift expression must have unsigned integer type
|
||||
or be an untyped constant <a href="#Representability">representable</a> by a
|
||||
value of type <code>uint</code>.
|
||||
If the left operand of a non-constant shift expression is an untyped constant,
|
||||
@@ -3732,9 +3586,7 @@ be replaced by a bitwise AND operation:
|
||||
|
||||
<p>
|
||||
The shift operators shift the left operand by the shift count specified by the
|
||||
right operand, which must be non-negative. If the shift count is negative at run time,
|
||||
a <a href="#Run_time_panics">run-time panic</a> occurs.
|
||||
The shift operators implement arithmetic shifts if the left operand is a signed
|
||||
right operand. They implement arithmetic shifts if the left operand is a signed
|
||||
integer and logical shifts if it is an unsigned integer.
|
||||
There is no upper limit on the shift count. Shifts behave
|
||||
as if the left operand is shifted <code>n</code> times by 1 for a shift
|
||||
@@ -5279,7 +5131,7 @@ for i, s := range a {
|
||||
}
|
||||
|
||||
var key string
|
||||
var val interface{} // element type of m is assignable to val
|
||||
var val interface {} // element type of m is assignable to val
|
||||
m := map[string]int{"mon":0, "tue":1, "wed":2, "thu":3, "fri":4, "sat":5, "sun":6}
|
||||
for key, val = range m {
|
||||
h(key, val)
|
||||
@@ -6069,7 +5921,7 @@ var a = complex(2, -2) // complex128
|
||||
const b = complex(1.0, -1.4) // untyped complex constant 1 - 1.4i
|
||||
x := float32(math.Cos(math.Pi/2)) // float32
|
||||
var c64 = complex(5, -x) // complex64
|
||||
var s int = complex(1, 0) // untyped complex constant 1 + 0i can be converted to int
|
||||
var s uint = complex(1, 0) // untyped complex constant 1 + 0i can be converted to uint
|
||||
_ = complex(1, 2<<s) // illegal: 2 assumes floating-point type, cannot shift
|
||||
var rl = real(c64) // float32
|
||||
var im = imag(a) // float64
|
||||
@@ -6410,16 +6262,16 @@ var t T
|
||||
<h3 id="Package_initialization">Package initialization</h3>
|
||||
|
||||
<p>
|
||||
Within a package, package-level variable initialization proceeds stepwise,
|
||||
with each step selecting the variable earliest in <i>declaration order</i>
|
||||
which has no dependencies on uninitialized variables.
|
||||
Within a package, package-level variables are initialized in
|
||||
<i>declaration order</i> but after any of the variables
|
||||
they <i>depend</i> on.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
More precisely, a package-level variable is considered <i>ready for
|
||||
initialization</i> if it is not yet initialized and either has
|
||||
no <a href="#Variable_declarations">initialization expression</a> or
|
||||
its initialization expression has no <i>dependencies</i> on uninitialized variables.
|
||||
its initialization expression has no dependencies on uninitialized variables.
|
||||
Initialization proceeds by repeatedly initializing the next package-level
|
||||
variable that is earliest in declaration order and ready for initialization,
|
||||
until there are no variables ready for initialization.
|
||||
@@ -6431,23 +6283,6 @@ process ends, those variables are part of one or more initialization cycles,
|
||||
and the program is not valid.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Multiple variables on the left-hand side of a variable declaration initialized
|
||||
by single (multi-valued) expression on the right-hand side are initialized
|
||||
together: If any of the variables on the left-hand side is initialized, all
|
||||
those variables are initialized in the same step.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var x = a
|
||||
var a, b = f() // a and b are initialized together, before x is initialized
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
For the purpose of package initialization, <a href="#Blank_identifier">blank</a>
|
||||
variables are treated like any other variables in declarations.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The declaration order of variables declared in multiple files is determined
|
||||
by the order in which the files are presented to the compiler: Variables
|
||||
@@ -6489,16 +6324,22 @@ or to a function or method that depends on <code>y</code>.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
Dependency analysis is performed per package; only references referring
|
||||
to variables, functions, and methods declared in the current package
|
||||
are considered.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For example, given the declarations
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var (
|
||||
a = c + b // == 9
|
||||
b = f() // == 4
|
||||
c = f() // == 5
|
||||
d = 3 // == 5 after initialization has finished
|
||||
a = c + b
|
||||
b = f()
|
||||
c = f()
|
||||
d = 3
|
||||
)
|
||||
|
||||
func f() int {
|
||||
@@ -6509,39 +6350,6 @@ func f() int {
|
||||
|
||||
<p>
|
||||
the initialization order is <code>d</code>, <code>b</code>, <code>c</code>, <code>a</code>.
|
||||
Note that the order of subexpressions in initialization expressions is irrelevant:
|
||||
<code>a = c + b</code> and <code>a = b + c</code> result in the same initialization
|
||||
order in this example.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Dependency analysis is performed per package; only references referring
|
||||
to variables, functions, and (non-interface) methods declared in the current
|
||||
package are considered. If other, hidden, data dependencies exists between
|
||||
variables, the initialization order between those variables is unspecified.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For instance, given the declarations
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var x = I(T{}).ab() // x has an undetected, hidden dependency on a and b
|
||||
var _ = sideEffect() // unrelated to x, a, or b
|
||||
var a = b
|
||||
var b = 42
|
||||
|
||||
type I interface { ab() []int }
|
||||
type T struct{}
|
||||
func (T) ab() []int { return []int{a, b} }
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
the variable <code>a</code> will be initialized after <code>b</code> but
|
||||
whether <code>x</code> is initialized before <code>b</code>, between
|
||||
<code>b</code> and <code>a</code>, or after <code>a</code>, and
|
||||
thus also the moment at which <code>sideEffect()</code> is called (before
|
||||
or after <code>x</code> is initialized) is not specified.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<h2 id="help">Get help</h2>
|
||||
|
||||
<img class="gopher" src="/doc/gopher/help.png" alt=""/>
|
||||
<img class="gopher" src="/doc/gopher/help.png"/>
|
||||
|
||||
{{if not $.GoogleCN}}
|
||||
<h3 id="mailinglist"><a href="https://groups.google.com/group/golang-nuts">Go Nuts Mailing List</a></h3>
|
||||
@@ -59,6 +59,9 @@ for important announcements, such as the availability of new Go releases.
|
||||
<h3 id="twitter"><a href="https://twitter.com/golang">@golang at Twitter</a></h3>
|
||||
<p>The Go project's official Twitter account.</p>
|
||||
|
||||
<h3 id="pluscom"><a href="https://plus.google.com/communities/114112804251407510571">Go+ community</a></h3>
|
||||
<p>A Google+ community for Go enthusiasts.</p>
|
||||
|
||||
<h3 id="reddit"><a href="https://reddit.com/r/golang">golang sub-Reddit</a></h3>
|
||||
<p>
|
||||
The <a href="https://reddit.com/r/golang">golang sub-Reddit</a> is a place
|
||||
|
||||
@@ -33,70 +33,74 @@ compiler using the GCC back end, see
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The Go compilers support the following instruction sets:
|
||||
The Go compilers support eight instruction sets.
|
||||
There are important differences in the quality of the compilers for the different
|
||||
architectures.
|
||||
</p>
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
<code>amd64</code>, <code>386</code>
|
||||
<code>amd64</code> (also known as <code>x86-64</code>)
|
||||
</dt>
|
||||
<dd>
|
||||
The <code>x86</code> instruction set, 64- and 32-bit.
|
||||
A mature implementation.
|
||||
</dd>
|
||||
<dt>
|
||||
<code>arm64</code>, <code>arm</code>
|
||||
<code>386</code> (<code>x86</code> or <code>x86-32</code>)
|
||||
</dt>
|
||||
<dd>
|
||||
The <code>ARM</code> instruction set, 64-bit (<code>AArch64</code>) and 32-bit.
|
||||
Comparable to the <code>amd64</code> port.
|
||||
</dd>
|
||||
<dt>
|
||||
<code>mips64</code>, <code>mips64le</code>, <code>mips</code>, <code>mipsle</code>
|
||||
<code>arm</code> (<code>ARM</code>)
|
||||
</dt>
|
||||
<dd>
|
||||
The <code>MIPS</code> instruction set, big- and little-endian, 64- and 32-bit.
|
||||
Supports Linux, FreeBSD, NetBSD, OpenBSD and Darwin binaries. Less widely used than the other ports.
|
||||
</dd>
|
||||
<dt>
|
||||
<code>ppc64</code>, <code>ppc64le</code>
|
||||
<code>arm64</code> (<code>AArch64</code>)
|
||||
</dt>
|
||||
<dd>
|
||||
The 64-bit PowerPC instruction set, big- and little-endian.
|
||||
Supports Linux and Darwin binaries. New in 1.5 and not as well exercised as other ports.
|
||||
</dd>
|
||||
<dt>
|
||||
<code>riscv64</code>
|
||||
<code>ppc64, ppc64le</code> (64-bit PowerPC big- and little-endian)
|
||||
</dt>
|
||||
<dd>
|
||||
The 64-bit RISC-V instruction set.
|
||||
Supports Linux binaries. New in 1.5 and not as well exercised as other ports.
|
||||
</dd>
|
||||
<dt>
|
||||
<code>s390x</code>
|
||||
<code>mips, mipsle</code> (32-bit MIPS big- and little-endian)
|
||||
</dt>
|
||||
<dd>
|
||||
The IBM z/Architecture.
|
||||
Supports Linux binaries. New in 1.8 and not as well exercised as other ports.
|
||||
</dd>
|
||||
<dt>
|
||||
<code>wasm</code>
|
||||
<code>mips64, mips64le</code> (64-bit MIPS big- and little-endian)
|
||||
</dt>
|
||||
<dd>
|
||||
<a href="https://webassembly.org">WebAssembly</a>.
|
||||
Supports Linux binaries. New in 1.6 and not as well exercised as other ports.
|
||||
</dd>
|
||||
<dt>
|
||||
<code>s390x</code> (IBM System z)
|
||||
</dt>
|
||||
<dd>
|
||||
Supports Linux binaries. New in 1.7 and not as well exercised as other ports.
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Except for things like low-level operating system interface code, the run-time
|
||||
support is the same in all ports and includes a mark-and-sweep garbage
|
||||
collector, efficient array and string slicing, and support for efficient
|
||||
goroutines, such as stacks that grow and shrink on demand.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The compilers can target the AIX, Android, DragonFly BSD, FreeBSD,
|
||||
Illumos, Linux, macOS/iOS (Darwin), NetBSD, OpenBSD, Plan 9, Solaris,
|
||||
and Windows operating systems (although not all operating systems
|
||||
support all architectures).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A list of ports which are considered "first class" is available at the
|
||||
<a href="/wiki/PortingPolicy#first-class-ports">first class ports</a>
|
||||
wiki page.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The full set of supported combinations is listed in the
|
||||
discussion of <a href="#environment">environment variables</a> below.
|
||||
The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD,
|
||||
macOS (Darwin), Plan 9, Solaris and Windows operating systems.
|
||||
The full set of supported combinations is listed in the discussion of
|
||||
<a href="#environment">environment variables</a> below.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@@ -112,19 +116,23 @@ Go does not support CentOS 6 on these systems.
|
||||
|
||||
</div>
|
||||
|
||||
<h2 id="go14">Install Go compiler binaries for bootstrap</h2>
|
||||
<h2 id="go14">Install Go compiler binaries</h2>
|
||||
|
||||
<p>
|
||||
The Go toolchain is written in Go. To build it, you need a Go compiler installed.
|
||||
The scripts that do the initial build of the tools look for a "go" command
|
||||
in <code>$PATH</code>, so as long as you have Go installed in your
|
||||
system and configured in your <code>$PATH</code>, you are ready to build Go
|
||||
from source.
|
||||
Or if you prefer you can set <code>$GOROOT_BOOTSTRAP</code> to the
|
||||
root of a Go installation to use to build the new Go toolchain;
|
||||
<code>$GOROOT_BOOTSTRAP/bin/go</code> should be the go command to use.</p>
|
||||
The scripts that do the initial build of the tools look for an existing Go tool
|
||||
chain in <code>$GOROOT_BOOTSTRAP</code>.
|
||||
If unset, the default value of <code>GOROOT_BOOTSTRAP</code>
|
||||
is <code>$HOME/go1.4</code>.
|
||||
</p>
|
||||
|
||||
<h3 id="bootstrapFromBinaryRelease">Bootstrap toolchain from binary release</h3>
|
||||
<p>
|
||||
There are many options for the bootstrap toolchain.
|
||||
After obtaining one, set <code>GOROOT_BOOTSTRAP</code> to the
|
||||
directory containing the unpacked tree.
|
||||
For example, <code>$GOROOT_BOOTSTRAP/bin/go</code> should be
|
||||
the <code>go</code> command binary for the bootstrap toolchain.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To use a binary release as a bootstrap toolchain, see
|
||||
@@ -132,8 +140,6 @@ To use a binary release as a bootstrap toolchain, see
|
||||
packaged Go distribution.
|
||||
</p>
|
||||
|
||||
<h3 id="bootstrapFromSource">Bootstrap toolchain from source</h3>
|
||||
|
||||
<p>
|
||||
To build a bootstrap toolchain from source, use
|
||||
either the git branch <code>release-branch.go1.4</code> or
|
||||
@@ -147,17 +153,6 @@ the environment, and run <code>make.bash</code> (or,
|
||||
on Windows, <code>make.bat</code>).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Once the Go 1.4 source has been unpacked into your GOROOT_BOOTSTRAP directory,
|
||||
you must keep this git clone instance checked out to branch
|
||||
<code>release-branch.go1.4</code>. Specifically, do not attempt to reuse
|
||||
this git clone in the later step named "Fetch the repository." The go1.4
|
||||
bootstrap toolchain <b>must be able</b> to properly traverse the go1.4 sources
|
||||
that it assumes are present under this repository root.
|
||||
</p>
|
||||
|
||||
<h3 id="bootstrapFromCrosscompiledSource">Bootstrap toolchain from cross-compiled source</h3>
|
||||
|
||||
<p>
|
||||
To cross-compile a bootstrap toolchain from source, which is
|
||||
necessary on systems Go 1.4 did not target (for
|
||||
@@ -180,8 +175,6 @@ That tree can be copied to a machine of the given target type
|
||||
and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build.
|
||||
</p>
|
||||
|
||||
<h3 id="bootstrapFromGccgo">Bootstrap toolchain using gccgo</h3>
|
||||
|
||||
<p>
|
||||
To use gccgo as the bootstrap toolchain, you need to arrange
|
||||
for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes
|
||||
@@ -225,14 +218,15 @@ To build without <code>cgo</code>, set the environment variable
|
||||
|
||||
<h2 id="fetch">Fetch the repository</h2>
|
||||
|
||||
<p>Change to the directory where you intend to install Go, and make sure
|
||||
the <code>goroot</code> directory does not exist. Then clone the repository
|
||||
and check out the latest release tag (<code class="versionTag">go1.12</code>,
|
||||
for example):</p>
|
||||
<p>Go will install to a directory named <code>go</code>.
|
||||
Change to the directory that will be its parent
|
||||
and make sure the <code>go</code> directory does not exist.
|
||||
Then clone the repository and check out the latest release tag
|
||||
(<code class="versionTag">go1.9</code>, for example):</p>
|
||||
|
||||
<pre>
|
||||
$ git clone https://go.googlesource.com/go goroot
|
||||
$ cd goroot
|
||||
$ git clone https://go.googlesource.com/go
|
||||
$ cd go
|
||||
$ git checkout <span class="versionTag"><i><tag></i></span>
|
||||
</pre>
|
||||
|
||||
@@ -240,20 +234,6 @@ $ git checkout <span class="versionTag"><i><tag></i></span>
|
||||
Where <code><tag></code> is the version string of the release.
|
||||
</p>
|
||||
|
||||
<p>Go will be installed in the directory where it is checked out. For example,
|
||||
if Go is checked out in <code>$HOME/goroot</code>, executables will be installed
|
||||
in <code>$HOME/goroot/bin</code>. The directory may have any name, but note
|
||||
that if Go is checked out in <code>$HOME/go</code>, it will conflict with
|
||||
the default location of <code>$GOPATH</code>.
|
||||
See <a href="#gopath"><code>GOPATH</code></a> below.</p>
|
||||
|
||||
<p>
|
||||
Reminder: If you opted to also compile the bootstrap binaries from source (in an
|
||||
earlier section), you still need to <code>git clone</code> again at this point
|
||||
(to checkout the latest <code><tag></code>), because you must keep your
|
||||
go1.4 repository distinct.
|
||||
</p>
|
||||
|
||||
<h2 id="head">(Optional) Switch to the master branch</h2>
|
||||
|
||||
<p>If you intend to modify the go source code, and
|
||||
@@ -461,43 +441,6 @@ but move it elsewhere after the build, set
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li id="gopath"><code>$GOPATH</code>
|
||||
<p>
|
||||
The directory where Go projects outside the Go distribution are typically
|
||||
checked out. For example, <code>golang.org/x/tools</code> might be checked out
|
||||
to <code>$GOPATH/src/golang.org/x/tools</code>. Executables outside the
|
||||
Go distribution are installed in <code>$GOPATH/bin</code> (or
|
||||
<code>$GOBIN</code>, if set). Modules are downloaded and cached in
|
||||
<code>$GOPATH/pkg/mod</code>.
|
||||
</p>
|
||||
|
||||
<p>The default location of <code>$GOPATH</code> is <code>$HOME/go</code>,
|
||||
and it's not usually necessary to set <code>GOPATH</code> explicitly. However,
|
||||
if you have checked out the Go distribution to <code>$HOME/go</code>,
|
||||
you must set <code>GOPATH</code> to another location to avoid conflicts.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>$GOBIN</code>
|
||||
<p>
|
||||
The directory where executables outside the Go distribution are installed
|
||||
using the <a href="/cmd/go">go command</a>. For example,
|
||||
<code>go get golang.org/x/tools/cmd/godoc</code> downloads, builds, and
|
||||
installs <code>$GOBIN/godoc</code>. By default, <code>$GOBIN</code> is
|
||||
<code>$GOPATH/bin</code> (or <code>$HOME/go/bin</code> if <code>GOPATH</code>
|
||||
is not set). After installing, you will want to add this directory to
|
||||
your <code>$PATH</code> so you can use installed tools.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Note that the Go distribution's executables are installed in
|
||||
<code>$GOROOT/bin</code> (for executables invoked by people) or
|
||||
<code>$GOTOOLDIR</code> (for executables invoked by the go command;
|
||||
defaults to <code>$GOROOT/pkg/$GOOS_GOARCH</code>) instead of
|
||||
<code>$GOBIN</code>.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>$GOOS</code> and <code>$GOARCH</code>
|
||||
<p>
|
||||
The name of the target operating system and compilation architecture.
|
||||
@@ -507,48 +450,34 @@ These default to the values of <code>$GOHOSTOS</code> and
|
||||
|
||||
<p>
|
||||
Choices for <code>$GOOS</code> are
|
||||
<code>android</code>, <code>darwin</code> (macOS/iOS),
|
||||
<code>dragonfly</code>, <code>freebsd</code>, <code>illumos</code>, <code>js</code>,
|
||||
<code>darwin</code> (macOS 10.10 and above and iOS), <code>dragonfly</code>, <code>freebsd</code>,
|
||||
<code>linux</code>, <code>netbsd</code>, <code>openbsd</code>,
|
||||
<code>plan9</code>, <code>solaris</code> and <code>windows</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Choices for <code>$GOARCH</code> are
|
||||
<code>amd64</code> (64-bit x86, the most mature port),
|
||||
<code>386</code> (32-bit x86), <code>arm</code> (32-bit ARM), <code>arm64</code> (64-bit ARM),
|
||||
<code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
|
||||
<code>mips64le</code> (MIPS 64-bit, little-endian), <code>mips64</code> (MIPS 64-bit, big-endian),
|
||||
<code>mipsle</code> (MIPS 32-bit, little-endian), <code>mips</code> (MIPS 32-bit, big-endian),
|
||||
<code>s390x</code> (IBM System z 64-bit, big-endian), and
|
||||
<code>wasm</code> (WebAssembly 32-bit).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<code>mipsle</code> (MIPS 32-bit, little-endian), <code>mips</code> (MIPS 32-bit, big-endian), and
|
||||
<code>s390x</code> (IBM System z 64-bit, big-endian).
|
||||
The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
|
||||
<table cellpadding="0">
|
||||
<tr>
|
||||
<th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>aix</code></td> <td><code>ppc64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>android</code></td> <td><code>386</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>android</code></td> <td><code>amd64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>android</code></td> <td><code>arm</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>android</code></td> <td><code>arm64</code></td>
|
||||
<td></td><td><code>darwin</code></td> <td><code>386</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>darwin</code></td> <td><code>amd64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>darwin</code></td> <td><code>arm</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>darwin</code></td> <td><code>arm64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -564,12 +493,6 @@ The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
|
||||
<td></td><td><code>freebsd</code></td> <td><code>arm</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>illumos</code></td> <td><code>amd64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>js</code></td> <td><code>wasm</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>linux</code></td> <td><code>386</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -600,9 +523,6 @@ The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
|
||||
<td></td><td><code>linux</code></td> <td><code>mips64le</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>linux</code></td> <td><code>riscv64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>linux</code></td> <td><code>s390x</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -624,18 +544,12 @@ The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
|
||||
<td></td><td><code>openbsd</code></td> <td><code>arm</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>openbsd</code></td> <td><code>arm64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>plan9</code></td> <td><code>386</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>plan9</code></td> <td><code>amd64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>plan9</code></td> <td><code>arm</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><code>solaris</code></td> <td><code>amd64</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -663,6 +577,17 @@ For example, you should not set <code>$GOHOSTARCH</code> to
|
||||
<code>arm</code> on an x86 system.
|
||||
</p>
|
||||
|
||||
<li><code>$GOBIN</code>
|
||||
<p>
|
||||
The location where Go binaries will be installed.
|
||||
The default is <code>$GOROOT/bin</code>.
|
||||
After installing, you will want to arrange to add this
|
||||
directory to your <code>$PATH</code>, so you can use the tools.
|
||||
If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a>
|
||||
installs all commands there.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>$GO386</code> (for <code>386</code> only, default is auto-detected
|
||||
if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise)
|
||||
<p>
|
||||
@@ -702,29 +627,6 @@ contains further details regarding Go's ARM support.
|
||||
</p>
|
||||
</li>
|
||||
|
||||
<li><code>$GOPPC64</code> (for <code>ppc64</code> and <code>ppc64le</code> only)
|
||||
<p>
|
||||
This variable sets the processor level (i.e. Instruction Set Architecture version)
|
||||
for which the compiler will target. The default is <code>power8</code>.
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>GOPPC64=power8</code>: generate ISA v2.07 instructions</li>
|
||||
<li><code>GOPPC64=power9</code>: generate ISA v3.00 instructions</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
<li><code>$GOWASM</code> (for <code>wasm</code> only)
|
||||
<p>
|
||||
This variable is a comma separated list of <a href="https://github.com/WebAssembly/proposals">experimental WebAssembly features</a> that the compiled WebAssembly binary is allowed to use.
|
||||
The default is to use no experimental features.
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>GOWASM=satconv</code>: generate <a href="https://github.com/WebAssembly/nontrapping-float-to-int-conversions/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md">saturating (non-trapping) float-to-int conversions</a></li>
|
||||
<li><code>GOWASM=signext</code>: generate <a href="https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md">sign-extension operators</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<p>
|
||||
<a href="/dl/" target="_blank">Official binary
|
||||
distributions</a> are available for the FreeBSD (release 10-STABLE and above),
|
||||
Linux, macOS (10.11 and above), and Windows operating systems and
|
||||
Linux, macOS (10.10 and above), and Windows operating systems and
|
||||
the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>) x86 processor
|
||||
architectures.
|
||||
</p>
|
||||
@@ -49,8 +49,8 @@ If your OS or architecture is not on the list, you may be able to
|
||||
<tr><td colspan="3"><hr></td></tr>
|
||||
<tr><td>FreeBSD 10.3 or later</td> <td>amd64, 386</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
|
||||
<tr valign='top'><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm, arm64,<br>s390x, ppc64le</td> <td>CentOS/RHEL 5.x not supported.<br>Install from source for other libc.</td></tr>
|
||||
<tr><td>macOS 10.11 or later</td> <td>amd64</td> <td>use the clang or gcc<sup>†</sup> that comes with Xcode<sup>‡</sup> for <code>cgo</code> support</td></tr>
|
||||
<tr valign='top'><td>Windows 7, Server 2008R2 or later</td> <td>amd64, 386</td> <td>use MinGW (<code>386</code>) or MinGW-W64 (<code>amd64</code>) gcc<sup>†</sup>.<br>No need for cygwin or msys.</td></tr>
|
||||
<tr><td>macOS 10.10 or later</td> <td>amd64</td> <td>use the clang or gcc<sup>†</sup> that comes with Xcode<sup>‡</sup> for <code>cgo</code> support</td></tr>
|
||||
<tr><td>Windows 7, Server 2008R2 or later</td> <td>amd64, 386</td> <td>use MinGW gcc<sup>†</sup>. No need for cygwin or msys.</td></tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
@@ -192,11 +192,20 @@ Settings" option inside the "System" control panel.
|
||||
<h2 id="testing">Test your installation</h2>
|
||||
|
||||
<p>
|
||||
Check that Go is installed correctly by building a simple program, as follows.
|
||||
Check that Go is installed correctly by setting up a workspace
|
||||
and building a simple program, as follows.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Create a file named <code>hello.go</code> that looks like:
|
||||
Create your <a href="code.html#Workspaces">workspace</a> directory,
|
||||
<code class="testUnix">$HOME/go</code><code class="testWindows">%USERPROFILE%\go</code>.
|
||||
(If you'd like to use a different directory,
|
||||
you will need to <a href="https://golang.org/wiki/SettingGOPATH">set the <code>GOPATH</code> environment variable</a>.)
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Next, make the directory <code>src/hello</code> inside your workspace,
|
||||
and in that directory create a file named <code>hello.go</code> that looks like:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
@@ -214,17 +223,19 @@ Then build it with the <code>go</code> tool:
|
||||
</p>
|
||||
|
||||
<pre class="testUnix">
|
||||
$ <b>go build hello.go</b>
|
||||
$ <b>cd $HOME/go/src/hello</b>
|
||||
$ <b>go build</b>
|
||||
</pre>
|
||||
|
||||
<pre class="testWindows">
|
||||
C:\Users\Gopher\go\src\hello> <b>go build hello.go</b>
|
||||
C:\> <b>cd %USERPROFILE%\go\src\hello</b>
|
||||
C:\Users\Gopher\go\src\hello> <b>go build</b>
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
The command above will build an executable named
|
||||
<code class="testUnix">hello</code><code class="testWindows">hello.exe</code>
|
||||
in the current directory alongside your source code.
|
||||
in the directory alongside your source code.
|
||||
Execute it to see the greeting:
|
||||
</p>
|
||||
|
||||
@@ -242,6 +253,12 @@ hello, world
|
||||
If you see the "hello, world" message then your Go installation is working.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You can run <code>go</code> <code>install</code> to install the binary into
|
||||
your workspace's <code>bin</code> directory
|
||||
or <code>go</code> <code>clean</code> <code>-i</code> to remove it.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Before rushing off to write Go code please read the
|
||||
<a href="/doc/code.html">How to Write Go Code</a> document,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// You can edit this code!
|
||||
// Click here and start typing.
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
@@ -41,9 +41,9 @@ const templateStr = `
|
||||
<br>
|
||||
<br>
|
||||
{{end}}
|
||||
<form action="/" name=f method="GET">
|
||||
<input maxLength=1024 size=70 name=s value="" title="Text to QR Encode">
|
||||
<input type=submit value="Show QR" name=qr>
|
||||
<form action="/" name=f method="GET"><input maxLength=1024 size=70
|
||||
name=s value="" title="Text to QR Encode"><input type=submit
|
||||
value="Show QR" name=qr>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const usage = `go run run.go [tests]
|
||||
@@ -27,8 +26,6 @@ Tests may be specified without their .go suffix.
|
||||
`
|
||||
|
||||
func main() {
|
||||
start := time.Now()
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, usage)
|
||||
flag.PrintDefaults()
|
||||
@@ -73,9 +70,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
os.Remove(tmpdir)
|
||||
if rc == 0 {
|
||||
fmt.Printf("ok\t%s\t%s\n", filepath.Base(os.Args[0]), time.Since(start).Round(time.Millisecond))
|
||||
}
|
||||
os.Exit(rc)
|
||||
}
|
||||
|
||||
@@ -84,7 +78,7 @@ func main() {
|
||||
// and checks that the output matches the regexp want.
|
||||
func test(tmpdir, file, want string) error {
|
||||
// Build the program.
|
||||
prog := filepath.Join(tmpdir, file+".exe")
|
||||
prog := filepath.Join(tmpdir, file)
|
||||
cmd := exec.Command("go", "build", "-o", prog, file+".go")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
@@ -105,7 +99,7 @@ func test(tmpdir, file, want string) error {
|
||||
|
||||
// Canonicalize output.
|
||||
out = bytes.TrimRight(out, "\n")
|
||||
out = bytes.ReplaceAll(out, []byte{'\n'}, []byte{' '})
|
||||
out = bytes.Replace(out, []byte{'\n'}, []byte{' '}, -1)
|
||||
|
||||
// Check the result.
|
||||
match, err := regexp.Match(want, out)
|
||||
|
||||
164
doc/root.html
Normal file
164
doc/root.html
Normal file
@@ -0,0 +1,164 @@
|
||||
<!--{
|
||||
"Path": "/",
|
||||
"Template": true
|
||||
}-->
|
||||
|
||||
<div class="left">
|
||||
|
||||
<div id="learn">
|
||||
{{if not $.GoogleCN}}
|
||||
<a class="popout share">Pop-out</a>
|
||||
{{end}}
|
||||
<div class="rootHeading">Try Go</div>
|
||||
<div class="input">
|
||||
<textarea spellcheck="false" class="code">// You can edit this code!
|
||||
// Click here and start typing.
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, 世界")
|
||||
}</textarea>
|
||||
</div>
|
||||
<div class="output">
|
||||
<pre>
|
||||
Hello, 世界
|
||||
</pre>
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<a class="run" href="#" title="Run this code [shift-enter]">Run</a>
|
||||
{{if not $.GoogleCN}}
|
||||
<a class="share" href="#" title="Share this code">Share</a>
|
||||
<a class="tour" href="//tour.golang.org/" title="Learn Go from your browser">Tour</a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="toys">
|
||||
<select>
|
||||
<option value="hello.go">Hello, World!</option>
|
||||
<option value="life.go">Conway's Game of Life</option>
|
||||
<option value="fib.go">Fibonacci Closure</option>
|
||||
<option value="peano.go">Peano Integers</option>
|
||||
<option value="pi.go">Concurrent pi</option>
|
||||
<option value="sieve.go">Concurrent Prime Sieve</option>
|
||||
<option value="solitaire.go">Peg Solitaire Solver</option>
|
||||
<option value="tree.go">Tree Comparison</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
|
||||
<div id="about">
|
||||
Go is an open source programming language that makes it easy to build
|
||||
simple, reliable, and efficient software.
|
||||
</div>
|
||||
|
||||
<div id="gopher"></div>
|
||||
|
||||
<a href="/dl/" id="start">
|
||||
<span class="big">Download Go</span>
|
||||
<span class="desc">
|
||||
Binary distributions available for<br>
|
||||
Linux, macOS, Windows, and more.
|
||||
</span>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
<div style="clear: both"></div>
|
||||
|
||||
{{if not $.GoogleCN}}
|
||||
<div class="left">
|
||||
<div id="video">
|
||||
<div class="rootHeading">Featured video</div>
|
||||
<div class="js-frontpage-video" style="--aspect-ratio-padding: 58.07%;"><iframe width="415" height="241" src="//www.youtube.com/embed/ytEkHepK08c" frameborder="0" allowfullscreen></iframe></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
<div id="blog">
|
||||
<div class="rootHeading">Featured articles</div>
|
||||
<div class="read"><a href="//blog.golang.org/">Read more</a></div>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<div style="clear: both;"></div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.initFuncs.push(function() {
|
||||
// Set up playground if enabled.
|
||||
if (window.playground) {
|
||||
window.playground({
|
||||
"codeEl": "#learn .code",
|
||||
"outputEl": "#learn .output",
|
||||
"runEl": "#learn .run",
|
||||
"shareEl": "#learn .share",
|
||||
"shareRedirect": "//play.golang.org/p/",
|
||||
"toysEl": "#learn .toys select"
|
||||
});
|
||||
} else {
|
||||
$('#learn').hide()
|
||||
}
|
||||
});
|
||||
|
||||
{{if not $.GoogleCN}}
|
||||
|
||||
function readableTime(t) {
|
||||
var m = ["January", "February", "March", "April", "May", "June", "July",
|
||||
"August", "September", "October", "November", "December"];
|
||||
var p = t.substring(0, t.indexOf("T")).split("-");
|
||||
var d = new Date(p[0], p[1]-1, p[2]);
|
||||
return d.getDate() + " " + m[d.getMonth()] + " " + d.getFullYear();
|
||||
}
|
||||
|
||||
window.feedLoaded = function(result) {
|
||||
var blog = document.getElementById("blog");
|
||||
var read = blog.getElementsByClassName("read")[0];
|
||||
for (var i = 0; i < result.length && i < 2; i++) {
|
||||
var entry = result[i];
|
||||
var title = document.createElement("a");
|
||||
title.className = "title";
|
||||
title.href = entry.Link;
|
||||
title.innerHTML = entry.Title;
|
||||
blog.insertBefore(title, read);
|
||||
var extract = document.createElement("div");
|
||||
extract.className = "extract";
|
||||
extract.innerHTML = entry.Summary;
|
||||
blog.insertBefore(extract, read);
|
||||
var when = document.createElement("div");
|
||||
when.className = "when";
|
||||
when.innerHTML = "Published " + readableTime(entry.Time);
|
||||
blog.insertBefore(when, read);
|
||||
}
|
||||
}
|
||||
|
||||
window.initFuncs.push(function() {
|
||||
// Load blog feed.
|
||||
$('<script/>').attr('text', 'text/javascript')
|
||||
.attr('src', '//blog.golang.org/.json?jsonp=feedLoaded')
|
||||
.appendTo('body');
|
||||
|
||||
// Set the video at random.
|
||||
var videos = [
|
||||
{h: 241, s: "//www.youtube.com/embed/ytEkHepK08c"}, // Tour of Go
|
||||
{h: 241, s: "//www.youtube.com/embed/f6kdp27TYZs"}, // Concurrency Patterns
|
||||
{h: 233, s: "//player.vimeo.com/video/69237265"} // Simple environment
|
||||
];
|
||||
var v = videos[Math.floor(Math.random()*videos.length)];
|
||||
$('#video iframe').attr('height', v.h).attr('src', v.s);
|
||||
// Compute the aspect ratio (as a percentage) of the video
|
||||
// using the fixed width 415 and the height of the current video, v.h.
|
||||
var ar = 100*v.h/415;
|
||||
$('.js-frontpage-video').attr('style', '--aspect-ratio-padding: ' + ar + '%;');
|
||||
});
|
||||
|
||||
{{end}}
|
||||
})();
|
||||
</script>
|
||||
180
doc/security.html
Normal file
180
doc/security.html
Normal file
@@ -0,0 +1,180 @@
|
||||
<!--{
|
||||
"Title": "Go Security Policy",
|
||||
"Path": "/security",
|
||||
"Template": true
|
||||
}-->
|
||||
|
||||
<h2>Implementation</h2>
|
||||
|
||||
<h3>Reporting a Security Bug</h3>
|
||||
|
||||
<p>
|
||||
Please report to us any issues you find.
|
||||
This document explains how to do that and what to expect in return.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
All security bugs in the Go distribution should be reported by email to
|
||||
<a href="mailto:security@golang.org">security@golang.org</a>.
|
||||
This mail is delivered to a small security team.
|
||||
Your email will be acknowledged within 24 hours, and you'll receive a more
|
||||
detailed response to your email within 72 hours indicating the next steps in
|
||||
handling your report.
|
||||
For critical problems, you can encrypt your report using our PGP key (listed below).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Please use a descriptive subject line for your report email.
|
||||
After the initial reply to your report, the security team will endeavor to keep
|
||||
you informed of the progress being made towards a fix and full announcement.
|
||||
These updates will be sent at least every five days.
|
||||
In reality, this is more likely to be every 24-48 hours.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you have not received a reply to your email within 48 hours or you have not
|
||||
heard from the security team for the past five days please contact the Go
|
||||
security team directly:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li>Primary security coordinator: <a href="mailto:filippo@golang.org">Filippo Valsorda</a> (<a href="https://keybase.io/filippo/pgp_keys.asc">public key</a>).</li>
|
||||
<li>Secondary coordinator: <a href="mailto:agl@golang.org">Adam Langley</a> (<a href="https://www.imperialviolet.org/key.asc">public key</a>).</li>
|
||||
<li>If you receive no response, mail <a href="mailto:golang-dev@googlegroups.com">golang-dev@googlegroups.com</a> or use the <a href="https://groups.google.com/forum/#!forum/golang-dev">golang-dev web interface</a>.</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
Please note that golang-dev is a public discussion forum.
|
||||
When escalating on this list, please do not disclose the details of the issue.
|
||||
Simply state that you're trying to reach a member of the security team.
|
||||
</p>
|
||||
|
||||
<h3>Flagging Existing Issues as Security-related</h3>
|
||||
|
||||
<p>
|
||||
If you believe that an <a href="https://golang.org/issue">existing issue</a>
|
||||
is security-related, we ask that you send an email to
|
||||
<a href="mailto:security@golang.org">security@golang.org</a>.
|
||||
The email should include the issue ID and a short description of why it should
|
||||
be handled according to this security policy.
|
||||
</p>
|
||||
|
||||
<h3>Disclosure Process</h3>
|
||||
|
||||
<p>The Go project uses the following disclosure process:</p>
|
||||
|
||||
<ol>
|
||||
<li>Once the security report is received it is assigned a primary handler.
|
||||
This person coordinates the fix and release process.</li>
|
||||
<li>The issue is confirmed and a list of affected software is determined.</li>
|
||||
<li>Code is audited to find any potential similar problems.</li>
|
||||
<li>If it is determined, in consultation with the submitter, that a CVE-ID is
|
||||
required, the primary handler obtains one via email to
|
||||
<a href="https://oss-security.openwall.org/wiki/mailing-lists/distros">oss-distros</a>.</li>
|
||||
<li>Fixes are prepared for the two most recent major releases and the head/master
|
||||
revision. These fixes are not yet committed to the public repository.</li>
|
||||
<li>A notification is sent to the
|
||||
<a href="https://groups.google.com/group/golang-announce">golang-announce</a>
|
||||
mailing list to give users time to prepare their systems for the update.</li>
|
||||
<li>Three working days following this notification, the fixes are applied to
|
||||
the <a href="https://go.googlesource.com/go">public repository</a> and a new
|
||||
Go release is issued.</li>
|
||||
<li>On the date that the fixes are applied, announcements are sent to
|
||||
<a href="https://groups.google.com/group/golang-announce">golang-announce</a>,
|
||||
<a href="https://groups.google.com/group/golang-dev">golang-dev</a>, and
|
||||
<a href="https://groups.google.com/group/golang-nuts">golang-nuts</a>.
|
||||
</ol>
|
||||
|
||||
<p>
|
||||
This process can take some time, especially when coordination is required with
|
||||
maintainers of other projects. Every effort will be made to handle the bug in
|
||||
as timely a manner as possible, however it's important that we follow the
|
||||
process described above to ensure that disclosures are handled consistently.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For security issues that include the assignment of a CVE-ID,
|
||||
the issue is listed publicly under the
|
||||
<a href="https://www.cvedetails.com/vulnerability-list/vendor_id-14185/Golang.html">"Golang" product on the CVEDetails website</a>
|
||||
as well as the
|
||||
<a href="https://web.nvd.nist.gov/view/vuln/search">National Vulnerability Disclosure site</a>.
|
||||
</p>
|
||||
|
||||
<h3>Receiving Security Updates</h3>
|
||||
|
||||
<p>
|
||||
The best way to receive security announcements is to subscribe to the
|
||||
<a href="https://groups.google.com/forum/#!forum/golang-announce">golang-announce</a>
|
||||
mailing list. Any messages pertaining to a security issue will be prefixed
|
||||
with <code>[security]</code>.
|
||||
</p>
|
||||
|
||||
<h3>Comments on This Policy</h3>
|
||||
|
||||
<p>
|
||||
If you have any suggestions to improve this policy, please send an email to
|
||||
<a href="mailto:golang-dev@golang.org">golang-dev@golang.org</a> for discussion.
|
||||
</p>
|
||||
|
||||
<h3>PGP Key for <a href="mailto:security@golang.org">security@golang.org</a></h3>
|
||||
|
||||
<p>
|
||||
We accept PGP-encrypted email, but the majority of the security team
|
||||
are not regular PGP users so it's somewhat inconvenient. Please only
|
||||
use PGP for critical security reports.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Comment: GPGTools - https://gpgtools.org
|
||||
|
||||
mQINBFXI1h0BEADZdm05GDFWvjmQKutUVb0cJKS+VR+6XU3g/YQZGC8tnIL6i7te
|
||||
+fPJHfQc2uIw0xeBgZX4Ni/S8yIqsbIjqYeaToX7QFUufJDQwrmlQRDVAvvT5HBT
|
||||
J80JEs7yHRreFoLzB6dnWehWXzWle4gFKeIy+hvLrYquZVvbeEYTnX7fNzZg0+5L
|
||||
ksvj7lnQlJIy1l3sL/7uPr9qsm45/hzd0WjTQS85Ry6Na3tMwRpqGENDh25Blz75
|
||||
8JgK9JmtTJa00my1zzeCXU04CKKEMRbkMLozzudOH4ZLiLWcFiKRpeCn860wC8l3
|
||||
oJcyyObuTSbr9o05ra3On+epjCEFkknGX1WxPv+TV34i0a23AtuVyTCloKb7RYXc
|
||||
7mUaskZpU2rFBqIkzZ4MQJ7RDtGlm5oBy36j2QL63jAZ1cKoT/yvjJNp2ObmWaVF
|
||||
X3tk/nYw2H0YDjTkTCgGtyAOj3Cfqrtsa5L0jG5K2p4RY8mtVgQ5EOh7QxuS+rmN
|
||||
JiA39SWh7O6uFCwkz/OCXzqeh6/nP10HAb9S9IC34QQxm7Fhd0ZXzEv9IlBTIRzk
|
||||
xddSdACPnLE1gJcFHxBd2LTqS/lmAFShCsf8S252kagKJfHRebQJZHCIs6kT9PfE
|
||||
0muq6KRKeDXv01afAUvoB4QW/3chUrtgL2HryyO8ugMu7leVGmoZhFkIrQARAQAB
|
||||
tCZHbyBTZWN1cml0eSBUZWFtIDxzZWN1cml0eUBnb2xhbmcub3JnPokCPQQTAQoA
|
||||
JwUCVcjWHQIbAwUJB4YfgAULCQgHAwUVCgkICwUWAgMBAAIeAQIXgAAKCRA6RtGR
|
||||
eVpYOLnDD/9YVTd6DTwdJq6irVfM/ICPlPTXB0JLERqCI1Veptcp56eQoJ0XWGQp
|
||||
tkGlgbvmCzFo0B+65Te7YA4R3oyBCXd6JgyWQQPy5p60FHyuuCPVAReclSWyt9f2
|
||||
Yj/u4DjghKhELOvPiI96egcU3g9jrEEcPjm7JYkc9M2gVSNOnnJvcD7wpQJNCzon
|
||||
51eMZ1ZyfA5UCBTa0SaT9eXg5zwNlYQnB6ZF6TjXezkhLqlTsBuHxoNVf+9vCC0o
|
||||
ZKIM2ovptMx9eEguTDKWaQ7tero7Zs/q5fwk/MDzM/LGJ9aXy2RCtqBxv46vDS7G
|
||||
fCNq+aPD/wyFd6hxQkvkua6hgZwYT+cJWHYA2Yv0LO3BYOJdjfc+j2hjv+mC9lF0
|
||||
UpWhCVJv3hHoFaxnz62GdROzf2wXz6aR9Saj1rYSvqT9jC20VInxqMufXNN2sbpo
|
||||
Kyk6MTbAeepphQpfAWQv+ltWgBiEjuFxYdwv/vmw20996JV7O8nqkeCUW84B6su+
|
||||
Y3bbdP9o3DBtOT0j9LTB/FucmdNCNHoO+EnNBKJd6FoYTGLWi3Rq9DLx2V9tdJHo
|
||||
Bn67dymcl+iyp337HJNY+qS+KCgoqAWlxkzXRiXKb/yluhXdIkqhg4kL8JPAJvfS
|
||||
cs7Zn67Mx04ixJnRMYCDmxtD4xPsFMzM7g8m3PQp+nE7WhujM/ImM7kCDQRVyNYd
|
||||
ARAAlw9H/1ybQs4K3XKA1joII16rta9KS7ew76+agXo0jeSRwMEQfItOxYvfhmo8
|
||||
+ydn5TWsTbifGU8L3+EBTMRRyzWhbaGO0Wizw7BTVJ7n5JW+ndPrcUpp/ilUk6AU
|
||||
VxaO/8/R+9+VJZpoeoLHXYloFGNuX58GLIy1jSBvLsLl/Ki5IOrHvD1GK6TftOl5
|
||||
j8IPC1LSBrwGJO803x7wUdQP/tsKN/QPR8pnBntrEgrQFSI+Q3qrCvVMmXnBlYum
|
||||
jfOBt8pKMgB9/ix+HWN8piQNQiJxD+XjEM6XwUmQqIR7y5GINKWgundCmtYIzVgY
|
||||
9p2Br6UPrTJi12LfKv5s2R6NnxFHv/ad29CpPTeLJRsSqFfqBL969BCpj/isXmQE
|
||||
m4FtziZidARXo12KiGAnPF9otirNHp4+8hwNB3scf7cI53y8nZivO9cwI7BoClY6
|
||||
ZIabjDcJxjK+24emoz3mJ5SHpZpQLSb9o8GbLLfXOq+4uzEX2A30fhrtsQb/x0GM
|
||||
4v3EU1aP2mjuksyYbgldtY64tD35wqAA9mVl5Ux+g1HoUBvLw0h+lzwh370NJw//
|
||||
ITvBQVUtDMB96rfIP4fL5pYl5pmRz+vsuJ0iXzm05qBgKfSqO7To9SWxQPdX89R4
|
||||
u0/XVAlw0Ak9Zceq3W96vseEUTR3aoZCMIPiwfcDaq60rWUAEQEAAYkCJQQYAQoA
|
||||
DwUCVcjWHQIbDAUJB4YfgAAKCRA6RtGReVpYOEg/EADZcIYw4q1jAbDkDy3LQG07
|
||||
AR8QmLp/RDp72RKbCSIYyvyXEnmrhUg98lUG676qTH+Y7dlEX107dLhFuKEYyV8D
|
||||
ZalrFQO/3WpLWdIAmWrj/wq14qii1rgmy96Nh3EqG3CS50HEMGkW1llRx2rgBvGl
|
||||
pgoTcwOfT+h8s0HlZdIS/cv2wXqwPgMWr1PIk3as1fu1OH8n/BjeGQQnNJEaoBV7
|
||||
El2C/hz3oqf2uYQ1QvpU23F1NrstekxukO8o2Y/fqsgMJqAiNJApUCl/dNhK+W57
|
||||
iicjvPirUQk8MUVEHXKhWIzYxon6aEUTx+xyNMBpRJIZlJ61FxtnZhoPiAFtXVPb
|
||||
+95BRJA9npidlVFjqz9QDK/4NSnJ3KaERR9tTDcvq4zqT22Z1Ai5gWQKqogTz5Mk
|
||||
F+nZwVizW0yi33id9qDpAuApp8o6AiyH5Ql1Bo23bvqS2lMrXPIS/QmPPsA76CBs
|
||||
lYjQwwz8abUD1pPdzyYtMKZUMwhicSFOHFDM4oQN16k2KJuntuih8BKVDCzIOq+E
|
||||
KHyeh1BqWplUtFh1ckxZlXW9p9F7TsWjtfcKaY8hkX0Cr4uVjwAFIjLcAxk67ROe
|
||||
huEb3Gt+lwJz6aNnZUU87ukMAxRVR2LL0btdxgc6z8spl66GXro/LUkXmAdyOEMV
|
||||
UDrmjf9pr7o00hC7lCHFzw==
|
||||
=WE0r
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
</pre>
|
||||
@@ -8,8 +8,8 @@
|
||||
# Consult https://www.iana.org/time-zones for the latest versions.
|
||||
|
||||
# Versions to use.
|
||||
CODE=2020a
|
||||
DATA=2020a
|
||||
CODE=2018i
|
||||
DATA=2018i
|
||||
|
||||
set -e
|
||||
rm -rf work
|
||||
@@ -21,15 +21,26 @@ curl -L -O https://www.iana.org/time-zones/repository/releases/tzdata$DATA.tar.g
|
||||
tar xzf tzcode$CODE.tar.gz
|
||||
tar xzf tzdata$DATA.tar.gz
|
||||
|
||||
# Turn off 64-bit output in time zone files.
|
||||
# We don't need those until 2037.
|
||||
perl -p -i -e 's/pass <= 2/pass <= 1/' zic.c
|
||||
|
||||
make CFLAGS=-DSTD_INSPIRED AWK=awk TZDIR=zoneinfo posix_only
|
||||
|
||||
# America/Los_Angeles should not be bigger than 1100 bytes.
|
||||
# If it is, we probably failed to disable the 64-bit output, which
|
||||
# triples the size of the files.
|
||||
size=$(ls -l zoneinfo/America/Los_Angeles | awk '{print $5}')
|
||||
if [ $size -gt 1200 ]; then
|
||||
echo 'zone file too large; 64-bit edit failed?' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cd zoneinfo
|
||||
rm -f ../../zoneinfo.zip
|
||||
zip -0 -r ../../zoneinfo.zip *
|
||||
cd ../..
|
||||
|
||||
go generate time/tzdata
|
||||
|
||||
echo
|
||||
if [ "$1" = "-work" ]; then
|
||||
echo Left workspace behind in work/.
|
||||
|
||||
Binary file not shown.
@@ -6,18 +6,18 @@ mobile subrepository:
|
||||
|
||||
https://github.com/golang/mobile
|
||||
|
||||
To run the standard library tests, enable Cgo and use an appropriate
|
||||
C compiler from the Android NDK. For example,
|
||||
To run the standard library tests, see androidtest.bash. Run it as
|
||||
|
||||
CGO_ENABLED=1 \
|
||||
GOOS=android \
|
||||
GOARCH=arm64 \
|
||||
CC_FOR_TARGET=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang \
|
||||
./all.bash
|
||||
CC_FOR_TARGET=$STANDALONE_NDK_PATH/bin/clang GOARCH=arm64 ./androidtest.bash
|
||||
|
||||
To create a standalone android NDK tool chain, follow the instructions on
|
||||
|
||||
https://developer.android.com/ndk/guides/standalone_toolchain
|
||||
|
||||
To run tests on the Android device, add the bin directory to PATH so the
|
||||
go tool can find the go_android_$GOARCH_exec wrapper generated by
|
||||
make.bash. For example, to run the go1 benchmarks
|
||||
androidtest.bash. Then, use the same GOARCH as when androidtest.bash ran
|
||||
and set GOOS to android. For example, to run the go1 benchmarks
|
||||
|
||||
export PATH=$GOROOT/bin:$PATH
|
||||
cd $GOROOT/test/bench/go1/
|
||||
|
||||
39
misc/android/cleaner.go
Normal file
39
misc/android/cleaner.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Cleaner removes anything from /data/local/tmp/goroot not on a builtin list.
|
||||
// Used by androidtest.bash.
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
const goroot = "/data/local/tmp/goroot"
|
||||
expect := make(map[string]bool)
|
||||
for _, f := range strings.Split(files, "\n") {
|
||||
expect[filepath.Join(goroot, f)] = true
|
||||
}
|
||||
|
||||
err := filepath.Walk(goroot, func(path string, info os.FileInfo, err error) error {
|
||||
if expect[path] {
|
||||
return nil
|
||||
}
|
||||
log.Printf("removing %s", path)
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// This program can be used as go_android_GOARCH_exec by the Go tool.
|
||||
// It executes binaries on an android device using adb.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -26,9 +22,12 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func run(args ...string) (string, error) {
|
||||
cmd := adbCmd(args...)
|
||||
func run(args ...string) string {
|
||||
if flags := os.Getenv("GOANDROID_ADB_FLAGS"); flags != "" {
|
||||
args = append(strings.Split(flags, " "), args...)
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
cmd := exec.Command("adb", args...)
|
||||
cmd.Stdout = io.MultiWriter(os.Stdout, buf)
|
||||
// If the adb subprocess somehow hangs, go test will kill this wrapper
|
||||
// and wait for our os.Stderr (and os.Stdout) to close as a result.
|
||||
@@ -40,114 +39,53 @@ func run(args ...string) (string, error) {
|
||||
// forcing cmd.Run to use another pipe and goroutine to pass
|
||||
// along stderr from adb.
|
||||
cmd.Stderr = struct{ io.Writer }{os.Stderr}
|
||||
log.Printf("adb %s", strings.Join(args, " "))
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("adb %s: %v", strings.Join(args, " "), err)
|
||||
log.Fatalf("adb %s: %v", strings.Join(args, " "), err)
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func adb(args ...string) error {
|
||||
if out, err := adbCmd(args...).CombinedOutput(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "adb %s\n%s", strings.Join(args, " "), out)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func adbCmd(args ...string) *exec.Cmd {
|
||||
if flags := os.Getenv("GOANDROID_ADB_FLAGS"); flags != "" {
|
||||
args = append(strings.Split(flags, " "), args...)
|
||||
}
|
||||
return exec.Command("adb", args...)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
const (
|
||||
deviceRoot = "/data/local/tmp/go_android_exec"
|
||||
deviceGoroot = deviceRoot + "/goroot"
|
||||
// Directory structure on the target device androidtest.bash assumes.
|
||||
deviceGoroot = "/data/local/tmp/goroot"
|
||||
deviceGopath = "/data/local/tmp/gopath"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
log.SetPrefix("go_android_exec: ")
|
||||
exitCode, err := runMain()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
func runMain() (int, error) {
|
||||
// Concurrent use of adb is flaky, so serialize adb commands.
|
||||
// See https://github.com/golang/go/issues/23795 or
|
||||
// https://issuetracker.google.com/issues/73230216.
|
||||
lockPath := filepath.Join(os.TempDir(), "go_android_exec-adb-lock")
|
||||
lock, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer lock.Close()
|
||||
if err := syscall.Flock(int(lock.Fd()), syscall.LOCK_EX); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// In case we're booting a device or emulator alongside all.bash, wait for
|
||||
// it to be ready. adb wait-for-device is not enough, we have to
|
||||
// wait for sys.boot_completed.
|
||||
if err := adb("wait-for-device", "exec-out", "while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;"); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Done once per make.bash.
|
||||
if err := adbCopyGoroot(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Prepare a temporary directory that will be cleaned up at the end.
|
||||
// Binary names can conflict.
|
||||
// E.g. template.test from the {html,text}/template packages.
|
||||
binName := filepath.Base(os.Args[1])
|
||||
deviceGotmp := fmt.Sprintf(deviceRoot+"/%s-%d", binName, os.Getpid())
|
||||
deviceGopath := deviceGotmp + "/gopath"
|
||||
defer adb("exec-out", "rm", "-rf", deviceGotmp) // Clean up.
|
||||
deviceGotmp := fmt.Sprintf("/data/local/tmp/%s-%d",
|
||||
filepath.Base(os.Args[1]), os.Getpid())
|
||||
run("shell", "mkdir", "-p", deviceGotmp)
|
||||
|
||||
// Determine the package by examining the current working
|
||||
// directory, which will look something like
|
||||
// "$GOROOT/src/mime/multipart" or "$GOPATH/src/golang.org/x/mobile".
|
||||
// We extract everything after the $GOROOT or $GOPATH to run on the
|
||||
// same relative directory on the target device.
|
||||
subdir, inGoRoot, err := subdir()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
deviceCwd := filepath.Join(deviceGopath, subdir)
|
||||
if inGoRoot {
|
||||
deviceCwd = filepath.Join(deviceGoroot, subdir)
|
||||
} else {
|
||||
if err := adb("exec-out", "mkdir", "-p", deviceCwd); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err := adbCopyTree(deviceCwd, subdir); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Copy .go files from the package.
|
||||
goFiles, err := filepath.Glob("*.go")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(goFiles) > 0 {
|
||||
args := append(append([]string{"push"}, goFiles...), deviceCwd)
|
||||
if err := adb(args...); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
subdir, inGoRoot := subdir()
|
||||
deviceCwd := filepath.Join(deviceGoroot, subdir)
|
||||
if !inGoRoot {
|
||||
deviceCwd = filepath.Join(deviceGopath, subdir)
|
||||
}
|
||||
|
||||
// Binary names can conflict.
|
||||
// E.g. template.test from the {html,text}/template packages.
|
||||
binName := fmt.Sprintf("%s-%d", filepath.Base(os.Args[1]), os.Getpid())
|
||||
deviceBin := fmt.Sprintf("%s/%s", deviceGotmp, binName)
|
||||
if err := adb("push", os.Args[1], deviceBin); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// The push of the binary happens in parallel with other tests.
|
||||
// Unfortunately, a simultaneous call to adb shell hold open
|
||||
// file descriptors, so it is necessary to push then move to
|
||||
// avoid a "text file busy" error on execution.
|
||||
// https://code.google.com/p/android/issues/detail?id=65857
|
||||
run("push", os.Args[1], deviceBin+"-tmp")
|
||||
run("shell", "cp '"+deviceBin+"-tmp' '"+deviceBin+"'")
|
||||
run("shell", "rm '"+deviceBin+"-tmp'")
|
||||
|
||||
// Forward SIGQUIT from the go command to show backtraces from
|
||||
// the binary instead of from this wrapper.
|
||||
@@ -157,185 +95,65 @@ func runMain() (int, error) {
|
||||
for range quit {
|
||||
// We don't have the PID of the running process; use the
|
||||
// binary name instead.
|
||||
adb("exec-out", "killall -QUIT "+binName)
|
||||
run("shell", "killall -QUIT "+binName)
|
||||
}
|
||||
}()
|
||||
// In light of
|
||||
// The adb shell command will return an exit code of 0 regardless
|
||||
// of the command run. E.g.
|
||||
// $ adb shell false
|
||||
// $ echo $?
|
||||
// 0
|
||||
// https://code.google.com/p/android/issues/detail?id=3254
|
||||
// dont trust the exitcode of adb. Instead, append the exitcode to
|
||||
// the output and parse it from there.
|
||||
// So we append the exitcode to the output and parse it from there.
|
||||
const exitstr = "exitcode="
|
||||
cmd := `export TMPDIR="` + deviceGotmp + `"` +
|
||||
`; export GOROOT="` + deviceGoroot + `"` +
|
||||
`; export GOPATH="` + deviceGopath + `"` +
|
||||
`; export CGO_ENABLED=0` +
|
||||
`; export GOPROXY=` + os.Getenv("GOPROXY") +
|
||||
`; export GOCACHE="` + deviceRoot + `/gocache"` +
|
||||
`; export PATH=$PATH:"` + deviceGoroot + `/bin"` +
|
||||
`; cd "` + deviceCwd + `"` +
|
||||
"; '" + deviceBin + "' " + strings.Join(os.Args[2:], " ") +
|
||||
"; echo -n " + exitstr + "$?"
|
||||
output, err := run("exec-out", cmd)
|
||||
output := run("shell", cmd)
|
||||
signal.Reset(syscall.SIGQUIT)
|
||||
close(quit)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
run("shell", "rm", "-rf", deviceGotmp) // Clean up.
|
||||
|
||||
exitIdx := strings.LastIndex(output, exitstr)
|
||||
if exitIdx == -1 {
|
||||
return 0, fmt.Errorf("no exit code: %q", output)
|
||||
log.Fatalf("no exit code: %q", output)
|
||||
}
|
||||
code, err := strconv.Atoi(output[exitIdx+len(exitstr):])
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("bad exit code: %v", err)
|
||||
log.Fatalf("bad exit code: %v", err)
|
||||
}
|
||||
return code, nil
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
// subdir determines the package based on the current working directory,
|
||||
// and returns the path to the package source relative to $GOROOT (or $GOPATH).
|
||||
func subdir() (pkgpath string, underGoRoot bool, err error) {
|
||||
func subdir() (pkgpath string, underGoRoot bool) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
log.Fatal(err)
|
||||
}
|
||||
cwd, err = filepath.EvalSymlinks(cwd)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
goroot, err := filepath.EvalSymlinks(runtime.GOROOT())
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
if subdir, err := filepath.Rel(goroot, cwd); err == nil {
|
||||
if !strings.Contains(subdir, "..") {
|
||||
return subdir, true, nil
|
||||
if root := runtime.GOROOT(); strings.HasPrefix(cwd, root) {
|
||||
subdir, err := filepath.Rel(root, cwd)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return subdir, true
|
||||
}
|
||||
|
||||
for _, p := range filepath.SplitList(build.Default.GOPATH) {
|
||||
pabs, err := filepath.EvalSymlinks(p)
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
if !strings.HasPrefix(cwd, p) {
|
||||
continue
|
||||
}
|
||||
if subdir, err := filepath.Rel(pabs, cwd); err == nil {
|
||||
if !strings.Contains(subdir, "..") {
|
||||
return subdir, false, nil
|
||||
}
|
||||
subdir, err := filepath.Rel(p, cwd)
|
||||
if err == nil {
|
||||
return subdir, false
|
||||
}
|
||||
}
|
||||
return "", false, fmt.Errorf("the current path %q is not in either GOROOT(%q) or GOPATH(%q)",
|
||||
log.Fatalf("the current path %q is not in either GOROOT(%q) or GOPATH(%q)",
|
||||
cwd, runtime.GOROOT(), build.Default.GOPATH)
|
||||
}
|
||||
|
||||
// adbCopyTree copies testdata, go.mod, go.sum files from subdir
|
||||
// and from parent directories all the way up to the root of subdir.
|
||||
// go.mod and go.sum files are needed for the go tool modules queries,
|
||||
// and the testdata directories for tests. It is common for tests to
|
||||
// reach out into testdata from parent packages.
|
||||
func adbCopyTree(deviceCwd, subdir string) error {
|
||||
dir := ""
|
||||
for {
|
||||
for _, path := range []string{"testdata", "go.mod", "go.sum"} {
|
||||
path := filepath.Join(dir, path)
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
continue
|
||||
}
|
||||
devicePath := filepath.Join(deviceCwd, dir)
|
||||
if err := adb("exec-out", "mkdir", "-p", devicePath); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := adb("push", path, devicePath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if subdir == "." {
|
||||
break
|
||||
}
|
||||
subdir = filepath.Dir(subdir)
|
||||
dir = filepath.Join(dir, "..")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// adbCopyGoroot clears deviceRoot for previous versions of GOROOT, GOPATH
|
||||
// and temporary data. Then, it copies relevant parts of GOROOT to the device,
|
||||
// including the go tool built for android.
|
||||
// A lock file ensures this only happens once, even with concurrent exec
|
||||
// wrappers.
|
||||
func adbCopyGoroot() error {
|
||||
// Also known by cmd/dist. The bootstrap command deletes the file.
|
||||
statPath := filepath.Join(os.TempDir(), "go_android_exec-adb-sync-status")
|
||||
stat, err := os.OpenFile(statPath, os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stat.Close()
|
||||
// Serialize check and copying.
|
||||
if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil {
|
||||
return err
|
||||
}
|
||||
s, err := ioutil.ReadAll(stat)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if string(s) == "done" {
|
||||
return nil
|
||||
}
|
||||
// Delete GOROOT, GOPATH and any leftover test data.
|
||||
if err := adb("exec-out", "rm", "-rf", deviceRoot); err != nil {
|
||||
return err
|
||||
}
|
||||
deviceBin := filepath.Join(deviceGoroot, "bin")
|
||||
if err := adb("exec-out", "mkdir", "-p", deviceBin); err != nil {
|
||||
return err
|
||||
}
|
||||
goroot := runtime.GOROOT()
|
||||
// Build go for android.
|
||||
goCmd := filepath.Join(goroot, "bin", "go")
|
||||
tmpGo, err := ioutil.TempFile("", "go_android_exec-cmd-go-*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmpGo.Close()
|
||||
defer os.Remove(tmpGo.Name())
|
||||
|
||||
if out, err := exec.Command(goCmd, "build", "-o", tmpGo.Name(), "cmd/go").CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to build go tool for device: %s\n%v", out, err)
|
||||
}
|
||||
deviceGo := filepath.Join(deviceBin, "go")
|
||||
if err := adb("push", tmpGo.Name(), deviceGo); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, dir := range []string{"src", "test", "lib", "api"} {
|
||||
if err := adb("push", filepath.Join(goroot, dir), filepath.Join(deviceGoroot)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Copy only the relevant from pkg.
|
||||
if err := adb("exec-out", "mkdir", "-p", filepath.Join(deviceGoroot, "pkg", "tool")); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := adb("push", filepath.Join(goroot, "pkg", "include"), filepath.Join(deviceGoroot, "pkg")); err != nil {
|
||||
return err
|
||||
}
|
||||
runtimea, err := exec.Command(goCmd, "list", "-f", "{{.Target}}", "runtime").Output()
|
||||
pkgdir := filepath.Dir(string(runtimea))
|
||||
if pkgdir == "" {
|
||||
return errors.New("could not find android pkg dir")
|
||||
}
|
||||
if err := adb("push", pkgdir, filepath.Join(deviceGoroot, "pkg")); err != nil {
|
||||
return err
|
||||
}
|
||||
tooldir := filepath.Join(goroot, "pkg", "tool", filepath.Base(pkgdir))
|
||||
if err := adb("push", tooldir, filepath.Join(deviceGoroot, "pkg", "tool")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := stat.Write([]byte("done")); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return "", false
|
||||
}
|
||||
|
||||
5
misc/benchcmp
Executable file
5
misc/benchcmp
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo 'misc/benchcmp has moved:' >&2
|
||||
echo ' go get -u golang.org/x/tools/cmd/benchcmp' >&2
|
||||
exit 2
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func path(file string) string {
|
||||
return filepath.Join("testdata", file)
|
||||
return filepath.Join("src", file)
|
||||
}
|
||||
|
||||
func check(t *testing.T, file string) {
|
||||
@@ -63,7 +63,7 @@ func expect(t *testing.T, file string, errors []*regexp.Regexp) {
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
dst := filepath.Join(dir, strings.TrimSuffix(file, ".go"))
|
||||
cmd := exec.Command("go", "build", "-gcflags=-L -e", "-o="+dst, path(file)) // TODO(gri) no need for -gcflags=-L if go tool is adjusted
|
||||
cmd := exec.Command("go", "build", "-gcflags=-L", "-o="+dst, path(file)) // TODO(gri) no need for -gcflags=-L if go tool is adjusted
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
t.Errorf("expected cgo to fail but it succeeded")
|
||||
@@ -107,12 +107,22 @@ func TestReportsTypeErrors(t *testing.T) {
|
||||
for _, file := range []string{
|
||||
"err1.go",
|
||||
"err2.go",
|
||||
"err3.go",
|
||||
"issue7757.go",
|
||||
"issue8442.go",
|
||||
"issue11097a.go",
|
||||
"issue11097b.go",
|
||||
"issue13129.go",
|
||||
"issue13423.go",
|
||||
"issue13467.go",
|
||||
"issue13635.go",
|
||||
"issue13830.go",
|
||||
"issue16116.go",
|
||||
"issue16591.go",
|
||||
"issue18452.go",
|
||||
"issue18889.go",
|
||||
"issue26745.go",
|
||||
"issue28721.go",
|
||||
"issue33061.go",
|
||||
} {
|
||||
check(t, file)
|
||||
}
|
||||
|
||||
@@ -7,25 +7,21 @@
|
||||
package errorstest
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var tmp = flag.String("tmp", "", "use `dir` for temporary files and do not clean up")
|
||||
|
||||
// ptrTest is the tests without the boilerplate.
|
||||
type ptrTest struct {
|
||||
name string // for reporting
|
||||
c string // the cgo comment
|
||||
c1 string // cgo comment forced into non-export cgo file
|
||||
imports []string // a list of imports
|
||||
support string // supporting functions
|
||||
body string // the body of the main function
|
||||
@@ -43,248 +39,253 @@ var ptrTests = []ptrTest{
|
||||
{
|
||||
// Passing a pointer to a struct that contains a Go pointer.
|
||||
name: "ptr1",
|
||||
c: `typedef struct s1 { int *p; } s1; void f1(s1 *ps) {}`,
|
||||
body: `C.f1(&C.s1{new(C.int)})`,
|
||||
c: `typedef struct s { int *p; } s; void f(s *ps) {}`,
|
||||
body: `C.f(&C.s{new(C.int)})`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Passing a pointer to a struct that contains a Go pointer.
|
||||
name: "ptr2",
|
||||
c: `typedef struct s2 { int *p; } s2; void f2(s2 *ps) {}`,
|
||||
body: `p := &C.s2{new(C.int)}; C.f2(p)`,
|
||||
c: `typedef struct s { int *p; } s; void f(s *ps) {}`,
|
||||
body: `p := &C.s{new(C.int)}; C.f(p)`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Passing a pointer to an int field of a Go struct
|
||||
// that (irrelevantly) contains a Go pointer.
|
||||
name: "ok1",
|
||||
c: `struct s3 { int i; int *p; }; void f3(int *p) {}`,
|
||||
body: `p := &C.struct_s3{i: 0, p: new(C.int)}; C.f3(&p.i)`,
|
||||
c: `struct s { int i; int *p; }; void f(int *p) {}`,
|
||||
body: `p := &C.struct_s{i: 0, p: new(C.int)}; C.f(&p.i)`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Passing a pointer to a pointer field of a Go struct.
|
||||
name: "ptrfield",
|
||||
c: `struct s4 { int i; int *p; }; void f4(int **p) {}`,
|
||||
body: `p := &C.struct_s4{i: 0, p: new(C.int)}; C.f4(&p.p)`,
|
||||
name: "ptr-field",
|
||||
c: `struct s { int i; int *p; }; void f(int **p) {}`,
|
||||
body: `p := &C.struct_s{i: 0, p: new(C.int)}; C.f(&p.p)`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Passing a pointer to a pointer field of a Go
|
||||
// struct, where the field does not contain a Go
|
||||
// pointer, but another field (irrelevantly) does.
|
||||
name: "ptrfieldok",
|
||||
c: `struct s5 { int *p1; int *p2; }; void f5(int **p) {}`,
|
||||
body: `p := &C.struct_s5{p1: nil, p2: new(C.int)}; C.f5(&p.p1)`,
|
||||
name: "ptr-field-ok",
|
||||
c: `struct s { int *p1; int *p2; }; void f(int **p) {}`,
|
||||
body: `p := &C.struct_s{p1: nil, p2: new(C.int)}; C.f(&p.p1)`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Passing the address of a slice with no Go pointers.
|
||||
name: "sliceok1",
|
||||
c: `void f6(void **p) {}`,
|
||||
name: "slice-ok-1",
|
||||
c: `void f(void **p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
body: `s := []unsafe.Pointer{nil}; C.f6(&s[0])`,
|
||||
body: `s := []unsafe.Pointer{nil}; C.f(&s[0])`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Passing the address of a slice with a Go pointer.
|
||||
name: "sliceptr1",
|
||||
c: `void f7(void **p) {}`,
|
||||
name: "slice-ptr-1",
|
||||
c: `void f(void **p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
body: `i := 0; s := []unsafe.Pointer{unsafe.Pointer(&i)}; C.f7(&s[0])`,
|
||||
body: `i := 0; s := []unsafe.Pointer{unsafe.Pointer(&i)}; C.f(&s[0])`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Passing the address of a slice with a Go pointer,
|
||||
// where we are passing the address of an element that
|
||||
// is not a Go pointer.
|
||||
name: "sliceptr2",
|
||||
c: `void f8(void **p) {}`,
|
||||
name: "slice-ptr-2",
|
||||
c: `void f(void **p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
body: `i := 0; s := []unsafe.Pointer{nil, unsafe.Pointer(&i)}; C.f8(&s[0])`,
|
||||
body: `i := 0; s := []unsafe.Pointer{nil, unsafe.Pointer(&i)}; C.f(&s[0])`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Passing the address of a slice that is an element
|
||||
// in a struct only looks at the slice.
|
||||
name: "sliceok2",
|
||||
c: `void f9(void **p) {}`,
|
||||
name: "slice-ok-2",
|
||||
c: `void f(void **p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
support: `type S9 struct { p *int; s []unsafe.Pointer }`,
|
||||
body: `i := 0; p := &S9{p:&i, s:[]unsafe.Pointer{nil}}; C.f9(&p.s[0])`,
|
||||
support: `type S struct { p *int; s []unsafe.Pointer }`,
|
||||
body: `i := 0; p := &S{p:&i, s:[]unsafe.Pointer{nil}}; C.f(&p.s[0])`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Passing the address of a slice of an array that is
|
||||
// an element in a struct, with a type conversion.
|
||||
name: "sliceok3",
|
||||
c: `void f10(void* p) {}`,
|
||||
name: "slice-ok-3",
|
||||
c: `void f(void* p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
support: `type S10 struct { p *int; a [4]byte }`,
|
||||
body: `i := 0; p := &S10{p:&i}; s := p.a[:]; C.f10(unsafe.Pointer(&s[0]))`,
|
||||
support: `type S struct { p *int; a [4]byte }`,
|
||||
body: `i := 0; p := &S{p:&i}; s := p.a[:]; C.f(unsafe.Pointer(&s[0]))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Passing the address of a slice of an array that is
|
||||
// an element in a struct, with a type conversion.
|
||||
name: "sliceok4",
|
||||
c: `typedef void* PV11; void f11(PV11 p) {}`,
|
||||
name: "slice-ok-4",
|
||||
c: `typedef void* PV; void f(PV p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
support: `type S11 struct { p *int; a [4]byte }`,
|
||||
body: `i := 0; p := &S11{p:&i}; C.f11(C.PV11(unsafe.Pointer(&p.a[0])))`,
|
||||
support: `type S struct { p *int; a [4]byte }`,
|
||||
body: `i := 0; p := &S{p:&i}; C.f(C.PV(unsafe.Pointer(&p.a[0])))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Passing the address of a static variable with no
|
||||
// pointers doesn't matter.
|
||||
name: "varok",
|
||||
c: `void f12(char** parg) {}`,
|
||||
support: `var hello12 = [...]C.char{'h', 'e', 'l', 'l', 'o'}`,
|
||||
body: `parg := [1]*C.char{&hello12[0]}; C.f12(&parg[0])`,
|
||||
c: `void f(char** parg) {}`,
|
||||
support: `var hello = [...]C.char{'h', 'e', 'l', 'l', 'o'}`,
|
||||
body: `parg := [1]*C.char{&hello[0]}; C.f(&parg[0])`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Passing the address of a static variable with
|
||||
// pointers does matter.
|
||||
name: "var1",
|
||||
c: `void f13(char*** parg) {}`,
|
||||
support: `var hello13 = [...]*C.char{new(C.char)}`,
|
||||
body: `parg := [1]**C.char{&hello13[0]}; C.f13(&parg[0])`,
|
||||
name: "var",
|
||||
c: `void f(char*** parg) {}`,
|
||||
support: `var hello = [...]*C.char{new(C.char)}`,
|
||||
body: `parg := [1]**C.char{&hello[0]}; C.f(&parg[0])`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Storing a Go pointer into C memory should fail.
|
||||
name: "barrier",
|
||||
c: `#include <stdlib.h>
|
||||
char **f14a() { return malloc(sizeof(char*)); }
|
||||
void f14b(char **p) {}`,
|
||||
body: `p := C.f14a(); *p = new(C.char); C.f14b(p)`,
|
||||
char **f1() { return malloc(sizeof(char*)); }
|
||||
void f2(char **p) {}`,
|
||||
body: `p := C.f1(); *p = new(C.char); C.f2(p)`,
|
||||
fail: true,
|
||||
expensive: true,
|
||||
},
|
||||
{
|
||||
// Storing a Go pointer into C memory by assigning a
|
||||
// large value should fail.
|
||||
name: "barrierstruct",
|
||||
name: "barrier-struct",
|
||||
c: `#include <stdlib.h>
|
||||
struct s15 { char *a[10]; };
|
||||
struct s15 *f15() { return malloc(sizeof(struct s15)); }
|
||||
void f15b(struct s15 *p) {}`,
|
||||
body: `p := C.f15(); p.a = [10]*C.char{new(C.char)}; C.f15b(p)`,
|
||||
struct s { char *a[10]; };
|
||||
struct s *f1() { return malloc(sizeof(struct s)); }
|
||||
void f2(struct s *p) {}`,
|
||||
body: `p := C.f1(); p.a = [10]*C.char{new(C.char)}; C.f2(p)`,
|
||||
fail: true,
|
||||
expensive: true,
|
||||
},
|
||||
{
|
||||
// Storing a Go pointer into C memory using a slice
|
||||
// copy should fail.
|
||||
name: "barrierslice",
|
||||
name: "barrier-slice",
|
||||
c: `#include <stdlib.h>
|
||||
struct s16 { char *a[10]; };
|
||||
struct s16 *f16() { return malloc(sizeof(struct s16)); }
|
||||
void f16b(struct s16 *p) {}`,
|
||||
body: `p := C.f16(); copy(p.a[:], []*C.char{new(C.char)}); C.f16b(p)`,
|
||||
struct s { char *a[10]; };
|
||||
struct s *f1() { return malloc(sizeof(struct s)); }
|
||||
void f2(struct s *p) {}`,
|
||||
body: `p := C.f1(); copy(p.a[:], []*C.char{new(C.char)}); C.f2(p)`,
|
||||
fail: true,
|
||||
expensive: true,
|
||||
},
|
||||
{
|
||||
// A very large value uses a GC program, which is a
|
||||
// different code path.
|
||||
name: "barriergcprogarray",
|
||||
name: "barrier-gcprog-array",
|
||||
c: `#include <stdlib.h>
|
||||
struct s17 { char *a[32769]; };
|
||||
struct s17 *f17() { return malloc(sizeof(struct s17)); }
|
||||
void f17b(struct s17 *p) {}`,
|
||||
body: `p := C.f17(); p.a = [32769]*C.char{new(C.char)}; C.f17b(p)`,
|
||||
struct s { char *a[32769]; };
|
||||
struct s *f1() { return malloc(sizeof(struct s)); }
|
||||
void f2(struct s *p) {}`,
|
||||
body: `p := C.f1(); p.a = [32769]*C.char{new(C.char)}; C.f2(p)`,
|
||||
fail: true,
|
||||
expensive: true,
|
||||
},
|
||||
{
|
||||
// Similar case, with a source on the heap.
|
||||
name: "barriergcprogarrayheap",
|
||||
name: "barrier-gcprog-array-heap",
|
||||
c: `#include <stdlib.h>
|
||||
struct s18 { char *a[32769]; };
|
||||
struct s18 *f18() { return malloc(sizeof(struct s18)); }
|
||||
void f18b(struct s18 *p) {}
|
||||
void f18c(void *p) {}`,
|
||||
struct s { char *a[32769]; };
|
||||
struct s *f1() { return malloc(sizeof(struct s)); }
|
||||
void f2(struct s *p) {}
|
||||
void f3(void *p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
body: `p := C.f18(); n := &[32769]*C.char{new(C.char)}; p.a = *n; C.f18b(p); n[0] = nil; C.f18c(unsafe.Pointer(n))`,
|
||||
body: `p := C.f1(); n := &[32769]*C.char{new(C.char)}; p.a = *n; C.f2(p); n[0] = nil; C.f3(unsafe.Pointer(n))`,
|
||||
fail: true,
|
||||
expensive: true,
|
||||
},
|
||||
{
|
||||
// A GC program with a struct.
|
||||
name: "barriergcprogstruct",
|
||||
name: "barrier-gcprog-struct",
|
||||
c: `#include <stdlib.h>
|
||||
struct s19a { char *a[32769]; };
|
||||
struct s19b { struct s19a f; };
|
||||
struct s19b *f19() { return malloc(sizeof(struct s19b)); }
|
||||
void f19b(struct s19b *p) {}`,
|
||||
body: `p := C.f19(); p.f = C.struct_s19a{[32769]*C.char{new(C.char)}}; C.f19b(p)`,
|
||||
struct s { char *a[32769]; };
|
||||
struct s2 { struct s f; };
|
||||
struct s2 *f1() { return malloc(sizeof(struct s2)); }
|
||||
void f2(struct s2 *p) {}`,
|
||||
body: `p := C.f1(); p.f = C.struct_s{[32769]*C.char{new(C.char)}}; C.f2(p)`,
|
||||
fail: true,
|
||||
expensive: true,
|
||||
},
|
||||
{
|
||||
// Similar case, with a source on the heap.
|
||||
name: "barriergcprogstructheap",
|
||||
name: "barrier-gcprog-struct-heap",
|
||||
c: `#include <stdlib.h>
|
||||
struct s20a { char *a[32769]; };
|
||||
struct s20b { struct s20a f; };
|
||||
struct s20b *f20() { return malloc(sizeof(struct s20b)); }
|
||||
void f20b(struct s20b *p) {}
|
||||
void f20c(void *p) {}`,
|
||||
struct s { char *a[32769]; };
|
||||
struct s2 { struct s f; };
|
||||
struct s2 *f1() { return malloc(sizeof(struct s2)); }
|
||||
void f2(struct s2 *p) {}
|
||||
void f3(void *p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
body: `p := C.f20(); n := &C.struct_s20a{[32769]*C.char{new(C.char)}}; p.f = *n; C.f20b(p); n.a[0] = nil; C.f20c(unsafe.Pointer(n))`,
|
||||
body: `p := C.f1(); n := &C.struct_s{[32769]*C.char{new(C.char)}}; p.f = *n; C.f2(p); n.a[0] = nil; C.f3(unsafe.Pointer(n))`,
|
||||
fail: true,
|
||||
expensive: true,
|
||||
},
|
||||
{
|
||||
// Exported functions may not return Go pointers.
|
||||
name: "export1",
|
||||
c: `extern unsigned char *GoFn21();`,
|
||||
support: `//export GoFn21
|
||||
func GoFn21() *byte { return new(byte) }`,
|
||||
body: `C.GoFn21()`,
|
||||
c: `extern unsigned char *GoFn();`,
|
||||
support: `//export GoFn
|
||||
func GoFn() *byte { return new(byte) }`,
|
||||
body: `C.GoFn()`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Returning a C pointer is fine.
|
||||
name: "exportok",
|
||||
c: `#include <stdlib.h>
|
||||
extern unsigned char *GoFn22();`,
|
||||
support: `//export GoFn22
|
||||
func GoFn22() *byte { return (*byte)(C.malloc(1)) }`,
|
||||
body: `C.GoFn22()`,
|
||||
extern unsigned char *GoFn();`,
|
||||
support: `//export GoFn
|
||||
func GoFn() *byte { return (*byte)(C.malloc(1)) }`,
|
||||
body: `C.GoFn()`,
|
||||
},
|
||||
{
|
||||
// Passing a Go string is fine.
|
||||
name: "passstring",
|
||||
name: "pass-string",
|
||||
c: `#include <stddef.h>
|
||||
typedef struct { const char *p; ptrdiff_t n; } gostring23;
|
||||
gostring23 f23(gostring23 s) { return s; }`,
|
||||
typedef struct { const char *p; ptrdiff_t n; } gostring;
|
||||
gostring f(gostring s) { return s; }`,
|
||||
imports: []string{"unsafe"},
|
||||
body: `s := "a"; r := C.f23(*(*C.gostring23)(unsafe.Pointer(&s))); if *(*string)(unsafe.Pointer(&r)) != s { panic(r) }`,
|
||||
body: `s := "a"; r := C.f(*(*C.gostring)(unsafe.Pointer(&s))); if *(*string)(unsafe.Pointer(&r)) != s { panic(r) }`,
|
||||
},
|
||||
{
|
||||
// Passing a slice of Go strings fails.
|
||||
name: "passstringslice",
|
||||
c: `void f24(void *p) {}`,
|
||||
name: "pass-string-slice",
|
||||
c: `void f(void *p) {}`,
|
||||
imports: []string{"strings", "unsafe"},
|
||||
support: `type S24 struct { a [1]string }`,
|
||||
body: `s := S24{a:[1]string{strings.Repeat("a", 2)}}; C.f24(unsafe.Pointer(&s.a[0]))`,
|
||||
support: `type S struct { a [1]string }`,
|
||||
body: `s := S{a:[1]string{strings.Repeat("a", 2)}}; C.f(unsafe.Pointer(&s.a[0]))`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Exported functions may not return strings.
|
||||
name: "retstring",
|
||||
c: `extern void f25();`,
|
||||
name: "ret-string",
|
||||
c: `extern void f();`,
|
||||
imports: []string{"strings"},
|
||||
support: `//export GoStr25
|
||||
func GoStr25() string { return strings.Repeat("a", 2) }`,
|
||||
body: `C.f25()`,
|
||||
c1: `#include <stddef.h>
|
||||
typedef struct { const char *p; ptrdiff_t n; } gostring25;
|
||||
extern gostring25 GoStr25();
|
||||
void f25() { GoStr25(); }`,
|
||||
support: `//export GoStr
|
||||
func GoStr() string { return strings.Repeat("a", 2) }`,
|
||||
body: `C.f()`,
|
||||
extra: []extra{
|
||||
{
|
||||
"call.c",
|
||||
`#include <stddef.h>
|
||||
typedef struct { const char *p; ptrdiff_t n; } gostring;
|
||||
extern gostring GoStr();
|
||||
void f() { GoStr(); }`,
|
||||
},
|
||||
},
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
@@ -295,37 +296,37 @@ var ptrTests = []ptrTest{
|
||||
// that is, we are testing something that is not unsafe.
|
||||
name: "ptrdata1",
|
||||
c: `#include <stdlib.h>
|
||||
void f26(void* p) {}`,
|
||||
void f(void* p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
support: `type S26 struct { p *int; a [8*8]byte; u uintptr }`,
|
||||
body: `i := 0; p := &S26{u:uintptr(unsafe.Pointer(&i))}; q := (*S26)(C.malloc(C.size_t(unsafe.Sizeof(*p)))); *q = *p; C.f26(unsafe.Pointer(q))`,
|
||||
support: `type S struct { p *int; a [8*8]byte; u uintptr }`,
|
||||
body: `i := 0; p := &S{u:uintptr(unsafe.Pointer(&i))}; q := (*S)(C.malloc(C.size_t(unsafe.Sizeof(*p)))); *q = *p; C.f(unsafe.Pointer(q))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Like ptrdata1, but with a type that uses a GC program.
|
||||
name: "ptrdata2",
|
||||
c: `#include <stdlib.h>
|
||||
void f27(void* p) {}`,
|
||||
void f(void* p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
support: `type S27 struct { p *int; a [32769*8]byte; q *int; u uintptr }`,
|
||||
body: `i := 0; p := S27{u:uintptr(unsafe.Pointer(&i))}; q := (*S27)(C.malloc(C.size_t(unsafe.Sizeof(p)))); *q = p; C.f27(unsafe.Pointer(q))`,
|
||||
support: `type S struct { p *int; a [32769*8]byte; q *int; u uintptr }`,
|
||||
body: `i := 0; p := S{u:uintptr(unsafe.Pointer(&i))}; q := (*S)(C.malloc(C.size_t(unsafe.Sizeof(p)))); *q = p; C.f(unsafe.Pointer(q))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Check deferred pointers when they are used, not
|
||||
// when the defer statement is run.
|
||||
name: "defer1",
|
||||
c: `typedef struct s28 { int *p; } s28; void f28(s28 *ps) {}`,
|
||||
body: `p := &C.s28{}; defer C.f28(p); p.p = new(C.int)`,
|
||||
name: "defer",
|
||||
c: `typedef struct s { int *p; } s; void f(s *ps) {}`,
|
||||
body: `p := &C.s{}; defer C.f(p); p.p = new(C.int)`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
// Check a pointer to a union if the union has any
|
||||
// pointer fields.
|
||||
name: "union1",
|
||||
c: `typedef union { char **p; unsigned long i; } u29; void f29(u29 *pu) {}`,
|
||||
c: `typedef union { char **p; unsigned long i; } u; void f(u *pu) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
body: `var b C.char; p := &b; C.f29((*C.u29)(unsafe.Pointer(&p)))`,
|
||||
body: `var b C.char; p := &b; C.f((*C.u)(unsafe.Pointer(&p)))`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
@@ -335,55 +336,55 @@ var ptrTests = []ptrTest{
|
||||
// integer that happens to have the same
|
||||
// representation as a pointer.
|
||||
name: "union2",
|
||||
c: `typedef union { unsigned long i; } u39; void f39(u39 *pu) {}`,
|
||||
c: `typedef union { unsigned long i; } u; void f(u *pu) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
body: `var b C.char; p := &b; C.f39((*C.u39)(unsafe.Pointer(&p)))`,
|
||||
body: `var b C.char; p := &b; C.f((*C.u)(unsafe.Pointer(&p)))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Test preemption while entering a cgo call. Issue #21306.
|
||||
name: "preemptduringcall",
|
||||
c: `void f30() {}`,
|
||||
name: "preempt-during-call",
|
||||
c: `void f() {}`,
|
||||
imports: []string{"runtime", "sync"},
|
||||
body: `var wg sync.WaitGroup; wg.Add(100); for i := 0; i < 100; i++ { go func(i int) { for j := 0; j < 100; j++ { C.f30(); runtime.GOMAXPROCS(i) }; wg.Done() }(i) }; wg.Wait()`,
|
||||
body: `var wg sync.WaitGroup; wg.Add(100); for i := 0; i < 100; i++ { go func(i int) { for j := 0; j < 100; j++ { C.f(); runtime.GOMAXPROCS(i) }; wg.Done() }(i) }; wg.Wait()`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Test poller deadline with cgocheck=2. Issue #23435.
|
||||
name: "deadline",
|
||||
c: `#define US31 10`,
|
||||
c: `#define US 10`,
|
||||
imports: []string{"os", "time"},
|
||||
body: `r, _, _ := os.Pipe(); r.SetDeadline(time.Now().Add(C.US31 * time.Microsecond))`,
|
||||
body: `r, _, _ := os.Pipe(); r.SetDeadline(time.Now().Add(C.US * time.Microsecond))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Test for double evaluation of channel receive.
|
||||
name: "chanrecv",
|
||||
c: `void f32(char** p) {}`,
|
||||
name: "chan-recv",
|
||||
c: `void f(char** p) {}`,
|
||||
imports: []string{"time"},
|
||||
body: `c := make(chan []*C.char, 2); c <- make([]*C.char, 1); go func() { time.Sleep(10 * time.Second); panic("received twice from chan") }(); C.f32(&(<-c)[0]);`,
|
||||
body: `c := make(chan []*C.char, 2); c <- make([]*C.char, 1); go func() { time.Sleep(10 * time.Second); panic("received twice from chan") }(); C.f(&(<-c)[0]);`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Test that converting the address of a struct field
|
||||
// to unsafe.Pointer still just checks that field.
|
||||
// Issue #25941.
|
||||
name: "structfield",
|
||||
c: `void f33(void* p) {}`,
|
||||
name: "struct-field",
|
||||
c: `void f(void* p) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
support: `type S33 struct { p *int; a [8]byte; u uintptr }`,
|
||||
body: `s := &S33{p: new(int)}; C.f33(unsafe.Pointer(&s.a))`,
|
||||
support: `type S struct { p *int; a [8]byte; u uintptr }`,
|
||||
body: `s := &S{p: new(int)}; C.f(unsafe.Pointer(&s.a))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Test that converting multiple struct field
|
||||
// addresses to unsafe.Pointer still just checks those
|
||||
// fields. Issue #25941.
|
||||
name: "structfield2",
|
||||
c: `void f34(void* p, int r, void* s) {}`,
|
||||
name: "struct-field-2",
|
||||
c: `void f(void* p, int r, void* s) {}`,
|
||||
imports: []string{"unsafe"},
|
||||
support: `type S34 struct { a [8]byte; p *int; b int64; }`,
|
||||
body: `s := &S34{p: new(int)}; C.f34(unsafe.Pointer(&s.a), 32, unsafe.Pointer(&s.b))`,
|
||||
support: `type S struct { a [8]byte; p *int; b int64; }`,
|
||||
body: `s := &S{p: new(int)}; C.f(unsafe.Pointer(&s.a), 32, unsafe.Pointer(&s.b))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
@@ -391,18 +392,18 @@ var ptrTests = []ptrTest{
|
||||
// evaluated when a deferred function is deferred, not
|
||||
// when it is run.
|
||||
name: "defer2",
|
||||
c: `void f35(char **pc) {}`,
|
||||
support: `type S35a struct { s []*C.char }; type S35b struct { ps *S35a }`,
|
||||
body: `p := &S35b{&S35a{[]*C.char{nil}}}; defer C.f35(&p.ps.s[0]); p.ps = nil`,
|
||||
c: `void f(char **pc) {}`,
|
||||
support: `type S1 struct { s []*C.char }; type S2 struct { ps *S1 }`,
|
||||
body: `p := &S2{&S1{[]*C.char{nil}}}; defer C.f(&p.ps.s[0]); p.ps = nil`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Test that indexing into a function call still
|
||||
// examines only the slice being indexed.
|
||||
name: "buffer",
|
||||
c: `void f36(void *p) {}`,
|
||||
c: `void f(void *p) {}`,
|
||||
imports: []string{"bytes", "unsafe"},
|
||||
body: `var b bytes.Buffer; b.WriteString("a"); C.f36(unsafe.Pointer(&b.Bytes()[0]))`,
|
||||
body: `var b bytes.Buffer; b.WriteString("a"); C.f(unsafe.Pointer(&b.Bytes()[0]))`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
@@ -410,8 +411,8 @@ var ptrTests = []ptrTest{
|
||||
name: "finalizer",
|
||||
c: `// Nothing to declare.`,
|
||||
imports: []string{"os"},
|
||||
support: `func open37() { os.Open(os.Args[0]) }; var G37 [][]byte`,
|
||||
body: `for i := 0; i < 10000; i++ { G37 = append(G37, make([]byte, 4096)); if i % 100 == 0 { G37 = nil; open37() } }`,
|
||||
support: `func open() { os.Open(os.Args[0]) }; var G [][]byte`,
|
||||
body: `for i := 0; i < 10000; i++ { G = append(G, make([]byte, 4096)); if i % 100 == 0 { G = nil; open() } }`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
@@ -419,171 +420,98 @@ var ptrTests = []ptrTest{
|
||||
name: "structof",
|
||||
c: `// Nothing to declare.`,
|
||||
imports: []string{"reflect"},
|
||||
support: `type MyInt38 int; func (i MyInt38) Get() int { return int(i) }; type Getter38 interface { Get() int }`,
|
||||
body: `t := reflect.StructOf([]reflect.StructField{{Name: "MyInt38", Type: reflect.TypeOf(MyInt38(0)), Anonymous: true}}); v := reflect.New(t).Elem(); v.Interface().(Getter38).Get()`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
// Test that a converted address of a struct field results
|
||||
// in a check for just that field and not the whole struct.
|
||||
name: "structfieldcast",
|
||||
c: `struct S40i { int i; int* p; }; void f40(struct S40i* p) {}`,
|
||||
support: `type S40 struct { p *int; a C.struct_S40i }`,
|
||||
body: `s := &S40{p: new(int)}; C.f40((*C.struct_S40i)(&s.a))`,
|
||||
support: `type MyInt int; func (i MyInt) Get() int { return int(i) }; type Getter interface { Get() int }`,
|
||||
body: `t := reflect.StructOf([]reflect.StructField{{Name: "MyInt", Type: reflect.TypeOf(MyInt(0)), Anonymous: true}}); v := reflect.New(t).Elem(); v.Interface().(Getter).Get()`,
|
||||
fail: false,
|
||||
},
|
||||
}
|
||||
|
||||
func TestPointerChecks(t *testing.T) {
|
||||
dir, exe := buildPtrTests(t)
|
||||
|
||||
// We (TestPointerChecks) return before the parallel subtest functions do,
|
||||
// so we can't just defer os.RemoveAll(dir). Instead we have to wait for
|
||||
// the parallel subtests to finish. This code looks racy but is not:
|
||||
// the add +1 run in serial before testOne blocks. The -1 run in parallel
|
||||
// after testOne finishes.
|
||||
var pending int32
|
||||
for _, pt := range ptrTests {
|
||||
pt := pt
|
||||
t.Run(pt.name, func(t *testing.T) {
|
||||
atomic.AddInt32(&pending, +1)
|
||||
defer func() {
|
||||
if atomic.AddInt32(&pending, -1) == 0 {
|
||||
os.RemoveAll(dir)
|
||||
}
|
||||
}()
|
||||
testOne(t, pt, exe)
|
||||
testOne(t, pt)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func buildPtrTests(t *testing.T) (dir, exe string) {
|
||||
var gopath string
|
||||
if *tmp != "" {
|
||||
gopath = *tmp
|
||||
dir = ""
|
||||
} else {
|
||||
d, err := ioutil.TempDir("", filepath.Base(t.Name()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dir = d
|
||||
gopath = d
|
||||
}
|
||||
|
||||
src := filepath.Join(gopath, "src", "ptrtest")
|
||||
if err := os.MkdirAll(src, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ioutil.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Prepare two cgo inputs: one for standard cgo and one for //export cgo.
|
||||
// (The latter cannot have C definitions, only declarations.)
|
||||
var cgo1, cgo2 bytes.Buffer
|
||||
fmt.Fprintf(&cgo1, "package main\n\n/*\n")
|
||||
fmt.Fprintf(&cgo2, "package main\n\n/*\n")
|
||||
|
||||
// C code
|
||||
for _, pt := range ptrTests {
|
||||
cgo := &cgo1
|
||||
if strings.Contains(pt.support, "//export") {
|
||||
cgo = &cgo2
|
||||
}
|
||||
fmt.Fprintf(cgo, "%s\n", pt.c)
|
||||
fmt.Fprintf(&cgo1, "%s\n", pt.c1)
|
||||
}
|
||||
fmt.Fprintf(&cgo1, "*/\nimport \"C\"\n\n")
|
||||
fmt.Fprintf(&cgo2, "*/\nimport \"C\"\n\n")
|
||||
|
||||
// Imports
|
||||
did1 := make(map[string]bool)
|
||||
did2 := make(map[string]bool)
|
||||
did1["os"] = true // for ptrTestMain
|
||||
fmt.Fprintf(&cgo1, "import \"os\"\n")
|
||||
|
||||
for _, pt := range ptrTests {
|
||||
did := did1
|
||||
cgo := &cgo1
|
||||
if strings.Contains(pt.support, "//export") {
|
||||
did = did2
|
||||
cgo = &cgo2
|
||||
}
|
||||
for _, imp := range pt.imports {
|
||||
if !did[imp] {
|
||||
did[imp] = true
|
||||
fmt.Fprintf(cgo, "import %q\n", imp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Func support and bodies.
|
||||
for _, pt := range ptrTests {
|
||||
cgo := &cgo1
|
||||
if strings.Contains(pt.support, "//export") {
|
||||
cgo = &cgo2
|
||||
}
|
||||
fmt.Fprintf(cgo, "%s\nfunc %s() {\n%s\n}\n", pt.support, pt.name, pt.body)
|
||||
}
|
||||
|
||||
// Func list and main dispatch.
|
||||
fmt.Fprintf(&cgo1, "var funcs = map[string]func() {\n")
|
||||
for _, pt := range ptrTests {
|
||||
fmt.Fprintf(&cgo1, "\t%q: %s,\n", pt.name, pt.name)
|
||||
}
|
||||
fmt.Fprintf(&cgo1, "}\n\n")
|
||||
fmt.Fprintf(&cgo1, "%s\n", ptrTestMain)
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ioutil.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cmd := exec.Command("go", "build", "-o", "ptrtest.exe")
|
||||
cmd.Dir = src
|
||||
cmd.Env = append(os.Environ(), "GOPATH="+gopath)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("go build: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
return dir, filepath.Join(src, "ptrtest.exe")
|
||||
}
|
||||
|
||||
const ptrTestMain = `
|
||||
func main() {
|
||||
for _, arg := range os.Args[1:] {
|
||||
f := funcs[arg]
|
||||
if f == nil {
|
||||
panic("missing func "+arg)
|
||||
}
|
||||
f()
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var csem = make(chan bool, 16)
|
||||
|
||||
func testOne(t *testing.T, pt ptrTest, exe string) {
|
||||
func testOne(t *testing.T, pt ptrTest) {
|
||||
t.Parallel()
|
||||
|
||||
// Run the tests in parallel, but don't run too many
|
||||
// executions in parallel, to avoid overloading the system.
|
||||
runcmd := func(cgocheck string) ([]byte, error) {
|
||||
csem <- true
|
||||
defer func() { <-csem }()
|
||||
cmd := exec.Command(exe, pt.name)
|
||||
cmd.Env = append(os.Environ(), "GODEBUG=cgocheck="+cgocheck)
|
||||
return cmd.CombinedOutput()
|
||||
gopath, err := ioutil.TempDir("", filepath.Base(t.Name()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(gopath)
|
||||
|
||||
src := filepath.Join(gopath, "src")
|
||||
if err := os.Mkdir(src, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
name := filepath.Join(src, fmt.Sprintf("%s.go", filepath.Base(t.Name())))
|
||||
f, err := os.Create(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b := bufio.NewWriter(f)
|
||||
fmt.Fprintln(b, `package main`)
|
||||
fmt.Fprintln(b)
|
||||
fmt.Fprintln(b, `/*`)
|
||||
fmt.Fprintln(b, pt.c)
|
||||
fmt.Fprintln(b, `*/`)
|
||||
fmt.Fprintln(b, `import "C"`)
|
||||
fmt.Fprintln(b)
|
||||
for _, imp := range pt.imports {
|
||||
fmt.Fprintln(b, `import "`+imp+`"`)
|
||||
}
|
||||
if len(pt.imports) > 0 {
|
||||
fmt.Fprintln(b)
|
||||
}
|
||||
if len(pt.support) > 0 {
|
||||
fmt.Fprintln(b, pt.support)
|
||||
fmt.Fprintln(b)
|
||||
}
|
||||
fmt.Fprintln(b, `func main() {`)
|
||||
fmt.Fprintln(b, pt.body)
|
||||
fmt.Fprintln(b, `}`)
|
||||
|
||||
if err := b.Flush(); err != nil {
|
||||
t.Fatalf("flushing %s: %v", name, err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
t.Fatalf("closing %s: %v", name, err)
|
||||
}
|
||||
|
||||
for _, e := range pt.extra {
|
||||
if err := ioutil.WriteFile(filepath.Join(src, e.name), []byte(e.contents), 0644); err != nil {
|
||||
t.Fatalf("writing %s: %v", e.name, err)
|
||||
}
|
||||
}
|
||||
|
||||
args := func(cmd *exec.Cmd) string {
|
||||
return strings.Join(cmd.Args, " ")
|
||||
}
|
||||
|
||||
cmd := exec.Command("go", "build")
|
||||
cmd.Dir = src
|
||||
cmd.Env = append(os.Environ(), "GOPATH="+gopath)
|
||||
buf, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Logf("%#q:\n%s", args(cmd), buf)
|
||||
t.Fatalf("failed to build: %v", err)
|
||||
}
|
||||
|
||||
exe := filepath.Join(src, filepath.Base(src))
|
||||
cmd = exec.Command(exe)
|
||||
cmd.Dir = src
|
||||
|
||||
if pt.expensive {
|
||||
buf, err := runcmd("1")
|
||||
cmd.Env = cgocheckEnv("1")
|
||||
buf, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Logf("%s", buf)
|
||||
t.Logf("%#q:\n%s", args(cmd), buf)
|
||||
if pt.fail {
|
||||
t.Fatalf("test marked expensive, but failed when not expensive: %v", err)
|
||||
} else {
|
||||
@@ -591,43 +519,54 @@ func testOne(t *testing.T, pt ptrTest, exe string) {
|
||||
}
|
||||
}
|
||||
|
||||
cmd = exec.Command(exe)
|
||||
cmd.Dir = src
|
||||
}
|
||||
|
||||
cgocheck := ""
|
||||
if pt.expensive {
|
||||
cgocheck = "2"
|
||||
cmd.Env = cgocheckEnv("2")
|
||||
}
|
||||
|
||||
buf, err := runcmd(cgocheck)
|
||||
buf, err = cmd.CombinedOutput()
|
||||
if pt.fail {
|
||||
if err == nil {
|
||||
t.Logf("%s", buf)
|
||||
t.Logf("%#q:\n%s", args(cmd), buf)
|
||||
t.Fatalf("did not fail as expected")
|
||||
} else if !bytes.Contains(buf, []byte("Go pointer")) {
|
||||
t.Logf("%s", buf)
|
||||
t.Logf("%#q:\n%s", args(cmd), buf)
|
||||
t.Fatalf("did not print expected error (failed with %v)", err)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Logf("%s", buf)
|
||||
t.Logf("%#q:\n%s", args(cmd), buf)
|
||||
t.Fatalf("failed unexpectedly: %v", err)
|
||||
}
|
||||
|
||||
if !pt.expensive {
|
||||
// Make sure it passes with the expensive checks.
|
||||
buf, err := runcmd("2")
|
||||
cmd := exec.Command(exe)
|
||||
cmd.Dir = src
|
||||
cmd.Env = cgocheckEnv("2")
|
||||
buf, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Logf("%s", buf)
|
||||
t.Logf("%#q:\n%s", args(cmd), buf)
|
||||
t.Fatalf("failed unexpectedly with expensive checks: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if pt.fail {
|
||||
buf, err := runcmd("0")
|
||||
cmd = exec.Command(exe)
|
||||
cmd.Dir = src
|
||||
cmd.Env = cgocheckEnv("0")
|
||||
buf, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Logf("%s", buf)
|
||||
t.Logf("%#q:\n%s", args(cmd), buf)
|
||||
t.Fatalf("failed unexpectedly with GODEBUG=cgocheck=0: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cgocheckEnv(val string) []string {
|
||||
return append(os.Environ(), "GODEBUG=cgocheck="+val)
|
||||
}
|
||||
|
||||
18
misc/cgo/errors/src/err1.go
Normal file
18
misc/cgo/errors/src/err1.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -L/nonexist
|
||||
|
||||
void test() {
|
||||
xxx; // ERROR HERE
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
C.test()
|
||||
}
|
||||
13
misc/cgo/errors/src/err2.go
Normal file
13
misc/cgo/errors/src/err2.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
s := ""
|
||||
_ = s
|
||||
C.malloc(s) // ERROR HERE
|
||||
}
|
||||
18
misc/cgo/errors/src/err3.go
Normal file
18
misc/cgo/errors/src/err3.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
/*
|
||||
typedef struct foo foo_t;
|
||||
typedef struct bar bar_t;
|
||||
|
||||
foo_t *foop;
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
x := (*C.bar_t)(nil)
|
||||
C.foop = x // ERROR HERE
|
||||
}
|
||||
14
misc/cgo/errors/src/issue13129.go
Normal file
14
misc/cgo/errors/src/issue13129.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// issue 13129: used to output error about C.unsignedshort with CC=clang
|
||||
|
||||
package main
|
||||
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
var x C.ushort
|
||||
x = int(0) // ERROR HERE: C\.ushort
|
||||
}
|
||||
12
misc/cgo/errors/src/issue13423.go
Normal file
12
misc/cgo/errors/src/issue13423.go
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
// #include <stdio.h>
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
_ = C.fopen() // ERROR HERE
|
||||
}
|
||||
15
misc/cgo/errors/src/issue13467.go
Normal file
15
misc/cgo/errors/src/issue13467.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
/*
|
||||
static int transform(int x) { return x; }
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func F() {
|
||||
var x rune = '✈'
|
||||
var _ rune = C.transform(x) // ERROR HERE: C\.int
|
||||
}
|
||||
24
misc/cgo/errors/src/issue13635.go
Normal file
24
misc/cgo/errors/src/issue13635.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// issue 13635: used to output error about C.unsignedchar.
|
||||
// This test tests all such types.
|
||||
|
||||
package pkg
|
||||
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
var (
|
||||
_ C.uchar = "uc" // ERROR HERE: C\.uchar
|
||||
_ C.schar = "sc" // ERROR HERE: C\.schar
|
||||
_ C.ushort = "us" // ERROR HERE: C\.ushort
|
||||
_ C.uint = "ui" // ERROR HERE: C\.uint
|
||||
_ C.ulong = "ul" // ERROR HERE: C\.ulong
|
||||
_ C.longlong = "ll" // ERROR HERE: C\.longlong
|
||||
_ C.ulonglong = "ull" // ERROR HERE: C\.ulonglong
|
||||
_ C.complexfloat = "cf" // ERROR HERE: C\.complexfloat
|
||||
_ C.complexdouble = "cd" // ERROR HERE: C\.complexdouble
|
||||
)
|
||||
}
|
||||
26
misc/cgo/errors/src/issue13830.go
Normal file
26
misc/cgo/errors/src/issue13830.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// cgo converts C void* to Go unsafe.Pointer, so despite appearances C
|
||||
// void** is Go *unsafe.Pointer. This test verifies that we detect the
|
||||
// problem at build time.
|
||||
|
||||
package main
|
||||
|
||||
// typedef void v;
|
||||
// void F(v** p) {}
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type v [0]byte
|
||||
|
||||
func f(p **v) {
|
||||
C.F((**C.v)(unsafe.Pointer(p))) // ERROR HERE
|
||||
}
|
||||
|
||||
func main() {
|
||||
var p *v
|
||||
f(&p)
|
||||
}
|
||||
12
misc/cgo/errors/src/issue16116.go
Normal file
12
misc/cgo/errors/src/issue16116.go
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
// void f(void *p, int x) {}
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
_ = C.f(1) // ERROR HERE
|
||||
}
|
||||
17
misc/cgo/errors/src/issue16591.go
Normal file
17
misc/cgo/errors/src/issue16591.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Issue 16591: Test that we detect an invalid call that was being
|
||||
// hidden by a type conversion inserted by cgo checking.
|
||||
|
||||
package p
|
||||
|
||||
// void f(int** p) { }
|
||||
import "C"
|
||||
|
||||
type x *C.int
|
||||
|
||||
func F(p *x) {
|
||||
C.f(p) // ERROR HERE
|
||||
}
|
||||
17
misc/cgo/errors/src/issue26745.go
Normal file
17
misc/cgo/errors/src/issue26745.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
// int a;
|
||||
// void CF(int i) {}
|
||||
import "C"
|
||||
|
||||
func F1(i int) int {
|
||||
return C.a + 1 // ERROR HERE: :13
|
||||
}
|
||||
|
||||
func F2(i int) {
|
||||
C.CF(i) // ERROR HERE: :6
|
||||
}
|
||||
14
misc/cgo/errors/src/issue7757.go
Normal file
14
misc/cgo/errors/src/issue7757.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
/*
|
||||
void foo() {}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
C.foo = C.foo // ERROR HERE
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user