Golang 1.10 outlook

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Golang 1.10 Beta officially released today, Golang 1.10 will be published in February 2018, we might as well first look at the features of 1.10. You can download the installation from this link go1.10 beta. The verification output is as follows: the installation was successful.

➜  ~ go versiongo version go1.10beta1 darwin/amd64

If you now have other versions installed on your machine, you can experience them in the following ways.

$ go get golang.org/x/build/version/go1.10beta1$ go1.10beta1 download

Use GO1.10BETA1 to replace the previous GO command. Let's look at the main features of Go 1.10 below.

1. Compatibility

The language itself is still forward compatible, and there is no difference between the operating system and the previous version. It is worth noting that go 1.10 will be the last version that can run on OS X 10.8, and go 1.11 requires an OS system of 10.9 as well as an updated system. Other operating system requirements are also adjusted in Go 1.11.

2. Tool Chain

1. Build & Install

The build is now compiled based on the latest source code.

2. Test

Test will cache the results. I think this is not necessarily a good mechanism.

In addition, go vet is executed automatically by going to test.

3. Diagnostics

Added overview of available Go program diagnostic tools.

3. Runtime

LockOSThreadand UnlockOSThread the behavior of the lock is now nested (nested). The function of these two functions is to bind goroutine to a particular operating system thread, and the previous go version behavior is multiple lock equals one lock, so no matter how many times the lock is called, it will be unlocked once the Unlock is called.

GOMAXPROCSthere is no limit to the additional settings. (limited to 1024 at 1.9).

4. Performance

Slightly improved.

5. GC

Fine tune.

6. Standard library

Standard library changes are relatively small, involving changes in the package including crypto, encoding, and so on, here are a few of the changes I feel worthy of attention.

1. bytes

Bytes inside the function,, Fields FieldsFunc Split SplitAfter (function prototype as follows) The returned Subslice is the address that points to the original slice, and the previous capacity. The Subslice returned by version 1.10 also points to the original address space, but the capacity is resized to the same size as Subslice, allowing the memory to be redistributed when the returned Subslice is append, without affecting any other subslice.

funcFields(s[]byte)[][]byte{...}

Example code: Go 1.10 Beta.

 Package MainImport (    "bytes"    "FMT")func Main() {    Str := []byte("Hello World")     Fields := bytes. Fields(Str)    FMT.Printf("filed0 cap:%d. field1 cap:%d.\n", Len( Fields[0]), Len( Fields[1]))    _ = Append( Fields[0], ' X ', ' Y ')    FMT.Printf("Old string:%s. Field0:%s. Field1:%s.\n", string(Str),  Fields[0],  Fields[1])}

Output Result:

➜  go go run bytes_fields.gofiled0 cap: 5. field1 cap: 5.old string: Hello world. field0: Hello. field1: world.

Previous versions of the output are as follows

➜  go go run bytes_fields.gofiled0 cap: 16. field1 cap: 10.old string: HelloXYorld. field0: Hello. field1: Yorld.

2. Go/doc

When you use Go doc to view the T type, you also return a function that returns a value of T, *t, **t slice.

$ go doc mail.Addresspackage mail // import "net/mail"type Address struct {Name    string Address string}    Address represents a single mail address.func ParseAddress(address string) (*Address, error)func ParseAddressList(list string) ([]*Address, error)func (a *Address) String() string

3. Strings

The strings package adds a new type Builder that can be used to concatenate strings.

//A Builder is used to efficiently build A string using Write methods.//It minimizes memory copying. The zero value is a ready-to-use.type Builder struct {buf []byte}//String returns the accumulated string.func (b *Builder) String() string {return *(*string)(unsafe.Pointer(&b.buf))}//Len returns the number of accumulated bytes; B.len () = = Len (b.string ()).func (b *Builder) Len() int { return Len(b.buf) }//Reset resets the Builder to be empty.func (b *Builder) Reset() { b.buf = Nil }

Connect byte.

// WriteByte appends the byte c to b's buffer.// The returned error is always nil.func(b*Builder)WriteByte(cbyte)error{b.buf=append(b.buf,c)returnnil}

connect string.

//WriteString appends the contents of S to B ' s buffer.//It Returns the length of S and a nil error.func (b *Builder) writestring(s string) (int, Error) {b.buf = Append(b.buf, s...)return Len(s), Nil}

4. StrConv

Now StrConv's Parseuint function returns to the upper bound if it is ErrRange wrong, and the previous return is 0.

 Package MainImport (    "StrConv"    "FMT")func Main() {    FMT.Println(StrConv.Parseuint("1234", Ten, Ten))    //output:1024    FMT.Println(StrConv.Parseuint("1234", Ten,  One))    //output:1234} 

5. Net/smtp

Client Add activity function: Noop.

6. Net/url

ResolveReferenceThe function now preserves all backslashes in the URL, and the previous version merges the backslash after the host into one, which sometimes causes redirect to be inaccurate.

 Package MainImport (    "Net/url"    "FMT")func Main() {    Base, _ := URL.Parse("Http://host//path//to//page1")    Target, _ := URL.Parse("Page2")    FMT.Println(Base.resolvereference(Target))}

Go 1.10 output is:/ httphost//path//to//page2, old version output is Http://host/path//to//page2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.