code
stringlengths
10
1.34M
language
stringclasses
1 value
// 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. // Socket options for Windows package net import ( "os" "syscall" ) func setDefaultSockopts(s syscall.Handle, f, t int, ipv6only bool) error { switch f {...
Go
// 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. package smtp import ( "crypto/hmac" "crypto/md5" "errors" "fmt" ) // Auth is implemented by an SMTP authentication mechanism. type Auth interface { // St...
Go
// 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. // Package smtp implements the Simple Mail Transfer Protocol as defined in RFC 5321. // It also implements the following extensions: // 8BITMIME RFC 1652 // AU...
Go
// 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. // Package html provides functions for escaping and unescaping HTML text. package html import ( "bytes" "strings" "unicode/utf8" ) type writer interface { ...
Go
// 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 template import ( "bytes" "strings" ) // transitionFunc is the array of context transition functions for text nodes. // A transition function takes ...
Go
// 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 template import ( "bytes" "fmt" "unicode" "unicode/utf8" ) // endsWithCSSKeyword returns whether b ends with an ident that // case-insensitively m...
Go
// 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 template import ( "bytes" "fmt" "strings" ) // urlFilter returns its input unless it contains an unsafe protocol in which // case it defangs the en...
Go
// 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 template import ( "fmt" "reflect" ) // Strings of content from a trusted source. type ( // CSS encapsulates known safe content that matches any of:...
Go
// 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 template import ( "strings" ) // attrTypeMap[n] describes the value of the given attribute. // If an attribute affects (or can mask) the encoding or ...
Go
// 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 template import ( "fmt" ) // Error describes a problem encountered during template Escaping. type Error struct { // ErrorCode describes the kind of ...
Go
// 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 template import ( "bytes" "fmt" "html" "io" "text/template" "text/template/parse" ) // escapeTemplates rewrites the named templates, which must ...
Go
// 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 template import ( "bytes" "encoding/json" "fmt" "reflect" "strings" "unicode/utf8" ) // nextJSCtx returns the context that determines whether a ...
Go
// 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 template import ( "bytes" "fmt" "strings" "unicode/utf8" ) // htmlNospaceEscaper escapes for inclusion in unquoted attribute values. func htmlNosp...
Go
// 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 template import ( "fmt" ) // context describes the state an HTML parser must be in when it reaches the // portion of HTML produced by evaluating a pa...
Go
// 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 template import ( "fmt" "io" "io/ioutil" "path/filepath" "sync" "text/template" "text/template/parse" ) // Template is a specialized template.T...
Go
// 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 template (html/template) implements data-driven templates for generating HTML output safe against code injection. It provides the same interface as p...
Go
// 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. package html // All entities that do not end with ';' are 6 or fewer bytes long. const longestEntityWithoutSemicolon = 6 // entity is a map from HTML entity n...
Go
// Copyright 2009 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 crc64 implements the 64-bit cyclic redundancy check, or CRC-64, // checksum. See http://en.wikipedia.org/wiki/Cyclic_redundancy_check for // informat...
Go
// Copyright 2009 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 adler32 implements the Adler-32 checksum. // // It is defined in RFC 1950: // Adler-32 is composed of two sums accumulated per byte: s1 is // the sum...
Go
// Copyright 2009 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 hash provides interfaces for hash functions. package hash import "io" // Hash is the common interface implemented by all hash functions. type Hash ...
Go
// 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 fnv implements FNV-1 and FNV-1a, non-cryptographic hash functions // created by Glenn Fowler, Landon Curt Noll, and Phong Vo. // See http://isthe.com...
Go
// Copyright 2009 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 crc32 implements the 32-bit cyclic redundancy check, or CRC-32, // checksum. See http://en.wikipedia.org/wiki/Cyclic_redundancy_check for // informat...
Go
// 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 crc32 // This file contains the code to call the SSE 4.2 version of the Castagnoli // CRC. // haveSSE42 is defined in crc_amd64.s and uses CPUID to te...
Go
// 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. // +build 386 arm package crc32 // The file contains the generic version of updateCastagnoli which just calls // the software implementation. func updateCast...
Go
// 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 builtin provides documentation for Go's predeclared identifiers. The items documented here are not actually in package builtin but their descripti...
Go
// Copyright 2012 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 linux darwin freebsd openbsd netbsd package tar import ( "os" "syscall" ) func init() { sysStat = statUnix } func statUnix(fi os.FileInfo, h *H...
Go
// Copyright 2009 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 tar implements access to tar archives. // It aims to cover most of the variations, including those produced // by GNU and BSD tars. // // References:...
Go
// Copyright 2012 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 linux openbsd package tar import ( "syscall" "time" ) func statAtime(st *syscall.Stat_t) time.Time { return time.Unix(st.Atim.Unix()) } func st...
Go
// Copyright 2009 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 tar // TODO(dsymonds): // - catch more errors (no first header, etc.) import ( "errors" "fmt" "io" "strconv" ) var ( ErrWriteTooLong = errors...
Go
// Copyright 2012 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 darwin freebsd netbsd package tar import ( "syscall" "time" ) func statAtime(st *syscall.Stat_t) time.Time { return time.Unix(st.Atimespec.Unix(...
Go
// Copyright 2009 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 tar // TODO(dsymonds): // - pax extensions import ( "bytes" "errors" "io" "io/ioutil" "os" "strconv" "time" ) var ( ErrHeader = errors.New(...
Go
// 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 zip import ( "bufio" "compress/flate" "encoding/binary" "errors" "hash" "hash/crc32" "io" ) // TODO(adg): support zip file comments // TODO(adg...
Go
// 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. /* Package zip provides support for reading and writing ZIP archives. See: http://www.pkware.com/documents/casestudies/APPNOTE.TXT This package does not suppo...
Go
// 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. package zip import ( "bufio" "compress/flate" "encoding/binary" "errors" "hash" "hash/crc32" "io" "io/ioutil" "os" ) var ( ErrFormat = errors.New...
Go
// 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. package netchan import ( "encoding/gob" "errors" "io" "reflect" "sync" "time" ) // The direction of a connection from the client's perspective. type Dir...
Go
// 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. package netchan import ( "errors" "io" "log" "net" "reflect" "sync" "time" ) // Import // impLog is a logging convenience function. The first argumen...
Go
// 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. /* Package netchan implements type-safe networked channels: it allows the two ends of a channel to appear on different computers connected by a network. It ...
Go
// 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. package main import ( "bufio" "fmt" "os" "strconv" "strings" ) // Generic expression parser/evaluator type Value interface { String() string BinaryOp...
Go
// 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. // This code differs from the slides in that it handles errors. package main import ( "crypto/aes" "crypto/cipher" "compress/gzip" "io" "log" "os" ) f...
Go
// 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. package main import ( "container/heap" "flag" "fmt" "math/rand" "time" ) const nRequester = 100 const nWorker = 10 var roundRobin = flag.Bool("r", fals...
Go
// 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. // This code differs from the slides in that it handles errors. package main import ( "crypto/aes" "crypto/cipher" "compress/gzip" "io" "log" "os" ) f...
Go
// 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. package main import ( "bufio" "fmt" "os" "strconv" "strings" ) // Generic expression parser/evaluator type Value interface { String() string BinaryOp...
Go
// 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. package main import ( "bytes" "flag" "go/ast" "go/parser" "go/printer" "go/token" "log" "os" "text/template" ) var ( srcFn = flag.String("src", ""...
Go
package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }
Go
// 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. package main import ( "fmt" "io/ioutil" "net/http" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title +...
Go
// 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. package main import ( "fmt" "io/ioutil" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" ret...
Go
// 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. package main import ( "html/template" "io/ioutil" "net/http" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename :=...
Go
// 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" ) var ( post = flag.String("post", "", "urlencoded form data to POST") ...
Go
// 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. package main import ( "html/template" "io/ioutil" "net/http" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename :=...
Go
// 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. package main import ( "html/template" "io/ioutil" "net/http" "regexp" ) type Page struct { Title string Body []byte } func (p *Page) save() error { f...
Go
// 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. package main import ( "fmt" "io/ioutil" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" ret...
Go
// 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. package main import ( "html/template" "io/ioutil" "net/http" "regexp" ) type Page struct { Title string Body []byte } func (p *Page) save() error { f...
Go
// 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. package main import ( "io/ioutil" "os" "text/template" ) func main() { b, _ := ioutil.ReadAll(os.Stdin) template.HTMLEscape(os.Stdout, b) }
Go
// 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. package main import ( "errors" "html/template" "io/ioutil" "net/http" "regexp" ) type Page struct { Title string Body []byte } func (p *Page) save() ...
Go
// 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. package main import ( "fmt" "io/ioutil" "net/http" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title +...
Go
// Peano integers are represented by a linked // list whose nodes contain no data // (the nodes are the data). // http://en.wikipedia.org/wiki/Peano_axioms // This program demonstrates the power of Go's // segmented stacks when doing massively // recursive computations. package main import "fmt" // Number is a poin...
Go
// Go's concurrency primitives make it easy to // express concurrent concepts, such as // this binary tree comparison. // // Trees may be of different shapes, // but have the same contents. For example: // // 4 6 // 2 6 4 7 // 1 3 5 7 2 5 // 1 3 // ...
Go
// This program solves the (English) peg // solitaire board game. // http://en.wikipedia.org/wiki/Peg_solitaire package main import "fmt" const N = 11 + 1 // length of a row (+1 for \n) // The board must be surrounded by 2 illegal // fields in each direction so that move() // doesn't need to check the board boundar...
Go
// A concurrent prime sieve package main // Send the sequence 2, 3, 4, ... to channel 'ch'. func Generate(ch chan<- int) { for i := 2; ; i++ { ch <- i // Send 'i' to channel 'ch'. } } // Copy the values from channel 'in' to channel 'out', // removing those divisible by 'prime'. func Filter(in <-chan int, out cha...
Go
package main import "fmt" func main() { fmt.Println("Hello, 世界") }
Go
// Concurrent computation of pi. // See http://goo.gl/ZuTZM. // // This demonstrates Go's ability to handle // large numbers of concurrent processes. // It is an unreasonable way to calculate pi. package main import ( "fmt" "math" ) func main() { fmt.Println(pi(5000)) } // pi launches n goroutines to compute an /...
Go
package main // fib returns a function that returns // successive Fibonacci numbers. func fib() func() int { a, b := 0, 1 return func() int { a, b = b, a+b return a } } func main() { f := fib() // Function calls are evaluated left-to-right. println(f(), f(), f(), f(), f()) }
Go
// skip // Copyright 2012 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 rand2 /* #include <stdlib.h> */ import "C" func Random() int { var r C.long = C.random() return int(r) } // STOP OMIT func Seed(i int) { C...
Go
// cmpout // Copyright 2012 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 ( "fmt" "math" ) func InterfaceExample() { var i interface{} i = "a string" i = 2011 i = 2.777 // STOP OMIT r := i.(f...
Go
// cmpout // Copyright 2012 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. // This file contains the code snippets included in "The Laws of Reflection." package main import ( "fmt" "reflect" ) func main() { var x float...
Go
// cmpout // Copyright 2012 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 ( "fmt" "image" ) func main() { r := image.Rect(2, 1, 5, 5).Add(image.Pt(-4, -2)) fmt.Println(r.Dx(), r.Dy(), image.Pt(0, 0...
Go
// compile // Copyright 2012 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. // This file contains the code snippets included in "The Laws of Reflection." package main import ( "bufio" "bytes" "io" "os" ) type MyInt in...
Go
// skip // Copyright 2012 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 print // #include <stdio.h> // #include <stdlib.h> import "C" import "unsafe" func Print(s string) { cs := C.CString(s) C.fputs(cs, (*C.FILE...
Go
// compile // Copyright 2012 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 timeout import ( "time" ) func Timeout() { ch := make(chan bool, 1) timeout := make(chan bool, 1) go func() { time.Sleep(1 * time.Sec...
Go
// compile // 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. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) func init() { ...
Go
// compile // 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. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) func init() { ...
Go
// compile // Copyright 2012 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 ( "encoding/json" "fmt" "log" "reflect" ) func Decode() { b := []byte(`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Mo...
Go
// compile // Copyright 2009 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" "log" "net/http" "text/template" ) var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18 ...
Go
// compile // 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. // This file contains the code snippets included in "Error Handling and Go." package main import ( "encoding/json" "errors" "fmt" "log" "net"...
Go
// cmpout // Copyright 2009 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 "fmt" type ByteSize float64 const ( _ = iota // ignore first value by assigning to blank identifier KB ByteSize = ...
Go
// compile // 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 gobs1 type T struct{ X, Y, Z int } // Only exported fields are encoded and decoded. var t = T{X: 7, Y: 0, Z: 8} // STOP OMIT type U struc...
Go
// skip // Copyright 2012 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 rand /* #include <stdlib.h> */ import "C" // STOP OMIT func Random() int { return int(C.random()) } // STOP OMIT func Seed(i int) { C.srand...
Go
// cmpout // Copyright 2012 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 ( "fmt" "image" ) func main() { r := image.Rect(0, 0, 4, 3).Intersect(image.Rect(2, 2, 5, 5)) // Size returns a rectangle's...
Go
// cmpout // Copyright 2012 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 ( "fmt" "image" ) func main() { r := image.Rect(2, 1, 5, 5) // Dx and Dy return a rectangle's width and height. fmt.Printl...
Go
// compile // Copyright 2012 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 ( "encoding/json" "log" "os" ) func main() { dec := json.NewDecoder(os.Stdin) enc := json.NewEncoder(os.Stdout) for { ...
Go
// cmpout // Copyright 2012 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 ( "fmt" "image" "image/color" ) func main() { m := image.NewRGBA(image.Rect(0, 0, 640, 480)) m.Set(5, 5, color.RGBA{255, 0...
Go
// compile // this file will output a list of filenames in cwd, not suitable for cmpout // 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. // This file contains examples to embed in the Go 1 release notes docum...
Go
// cmpout // 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. // This file contains the code snippets included in "Defer, Panic, and Recover." package main import "fmt" import "io" // OMIT import "os" // OMIT ...
Go
// compile // Copyright 2012 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 ( "io/ioutil" "regexp" ) func AppendByte(slice []byte, data ...byte) []byte { m := len(slice) n := m + len(data) if n > c...
Go
// cmpout // 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. // This file contains the code snippets included in "Defer, Panic, and Recover." package main import ( "fmt" "io" "os" ) func a() { i := 0 de...
Go
// cmpout // Copyright 2009 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 ( "fmt" "sort" ) func main() { seq := Sequence{6, 2, -1, 44, 16} sort.Sort(seq) fmt.Println(seq) } type Sequence []int /...
Go
// compile // Copyright 2012 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. // This file contains the code snippets included in "The Go image/draw package." package main import ( "image" "image/color" "image/draw" ) fu...
Go
// cmpout // Copyright 2012 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 ( "fmt" "image" ) func main() { p := image.Point{2, 1} fmt.Println("X is", p.X, "Y is", p.Y) }
Go
// run // Copyright 2012 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 ( "encoding/json" "log" "reflect" ) type FamilyMember struct { Name string Age int Parents []string } // STOP OMIT ...
Go
// compile // 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. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) type appError s...
Go
// compile // 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 ( "bytes" "encoding/gob" "fmt" "log" ) type P struct { X, Y, Z int Name string } type Q struct { X, Y *int32 Name ...
Go
// cmpout // Copyright 2012 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 ( "fmt" "image" ) func main() { m0 := image.NewRGBA(image.Rect(0, 0, 8, 5)) m1 := m0.SubImage(image.Rect(1, 2, 5, 5)).(*ima...
Go
// compile // Copyright 2012 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 query type Conn string func (c Conn) DoQuery(query string) Result { return Result("result") } type Result string func Query(conns []Conn...
Go
// skip // Copyright 2012 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 print // #include <stdio.h> // #include <stdlib.h> import "C" import "unsafe" func Print(s string) { cs := C.CString(s) defer C.free(unsafe....
Go
// run // Copyright 2012 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 ( "encoding/json" "log" "reflect" ) type Message struct { Name string Body string Time int64 } // STOP OMIT func Encode() ...
Go
// 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. /* Generating random text: a Markov chain algorithm Based on the program presented in the "Design and Implementation" chapter of The Practice of Programming (...
Go
// 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 ( "fmt" "math/rand" ) const ( win = 100 // The winning score in a game of Pig gamesPerSeries = 10 // The number of games p...
Go
// 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. package main import ( "log" "net/http" "time" ) const ( numPollers = 2 // number of Poller goroutines to launch pollInterval = 60 * ...
Go
// 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 ( "fmt" "swig/callback" ) type GoCallback struct{} func (p *GoCallback) Run() string { return "GoCallback.Run" } func main() { c :=...
Go
// 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 "swig/file" func main() { file.Puts("Hello, world") }
Go