Introducing the new features of Google Golang 1.1

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


Https://go.googlecode.com/hg/doc/go1.1.html

go1.1 and Go1 have some changes:

Changes to the standard library

Bufio. Scanner

The various routines to scan textual input in the Bufio package, readbytes, ReadString and particularly ReadLine, is need lessly complex to use for simple purposes. In Go 1.1, a new type, Scanner, have been added to make it easier to does simple tasks such as read the input as a sequence O F lines or space-delimited words. It simplifies the problem by terminating the scan on problematic input such as pathologically long lines, and have a sim ple default:line-oriented input with all line stripped of its terminator. Here's code to reproduce the input a line at a time:

Scanner: = Bufio. Newscanner (OS. Stdin) for scanner. Scan () {    fmt. PRINTLN (scanner. Text ())//PRINTLN would add back the final ' \ n '}if err: = Scanner. ERR (); Err! = Nil {    FMT. Fprintln (OS. Stderr, "Reading standard input:", err)}

Scanning behavior can is adjusted through a function to control subdividing the input (see the documentation for SPLITFUNC Tough problems or the need to continue past errors, the older interface could still be required.

Net

The protocol-specific resolvers in the net package were formerly lax is about the network name passed in. Although the documentation is clear that the only valid networks for RESOLVETCPADDR is "TCP", "TCP4", and "TCP6", the Go 1.0 implementation silently accepted any string. The Go 1.1 implementation returns an error if the network was not one of the those strings. The same is true for the other protocol-specific resolvers resolveipaddr, Resolveudpaddr, and resolveunixaddr.

The previous implementation of Listenunixgram returned a udpconn as a representation of the connection endpoint. The Go 1.1 implementation instead returns a Unixconn to allow reading and writing with its Readfrom and WriteTo methods.

Reflect

The reflect package has several significant additions.

It is now possible to run a "select" statement using the reflect package; See the description of Select and selectcase for details.

The new method Value.convert (or Type.convertibleto) provides functionality to execute a Go conversion or Type assertion O Peration on a Value (or test for its possibility).

The new function Makefunc creates a wrapper function to make it easier to call a function with existing Values, doing the Standard Go conversions Among the arguments, for instance to pass an actual int to a formal interface{}.

Finally, the new functions chanof, MAPOF and sliceof construct new Types from existing Types, for example to construct a T He type []t given only T.

Time

On FreeBSD, Linux, NetBSD, OS X and OpenBSD, previous versions of the time package returned times with microsecond Precisi On. The Go 1.1 implementation on these systems now returns times with nanosecond precision. Programs that write to a external format with microsecond precision and read it back, expecting to recover the original V Alue, 'll is affected by the loss of precision. There is the new methods of time, Round and Truncate, that can is used to remove precision from a time before passing it to external storage.

The new method Yearday returns the One-indexed integral day number of the year specified by the time value.

The timer type has a new method, Reset that modifies, the timer to expire after a specified duration.

Finally, the new function parseinlocation is like the existing. Parse but parses the time in the context of a location (Tim E zone), ignoring time zone information in the parsed string. This function addresses a common source of confusion in the time API.

Updating: Code that needs to read and write times using a external format with lower precision should be modifie D to use the new methods.

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.