code
stringlengths
10
1.34M
language
stringclasses
1 value
// 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 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 ( "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 ( "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 ( "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 ( "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 ( "html/template" "io/ioutil" "net/http" "regexp" ) type Page struct { Title string Body []byte } func (p *Page) save() error { f...
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 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 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
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
// 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
// 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
// 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
// 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
// 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. // 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. 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 ( "bufio" "fmt" "os" "strconv" "strings" ) // Generic expression parser/evaluator type Value interface { String() string BinaryOp...
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. package timeout import ( "time" ) func Timeout() { ch := make(chan bool, 1) timeout := make(chan bool, 1) go func() { time.Sleep(1 * time.Second) timeo...
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. package main import ( "encoding/json" "log" "os" ) func main() { dec := json.NewDecoder(os.Stdin) enc := json.NewEncoder(os.Stdout) for { var v map[st...
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. 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)).(*image.RGBA) f...
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. package main import ( "fmt" "math" ) func InterfaceExample() { var i interface{} i = "a string" i = 2011 i = 2.777 // STOP OMIT r := i.(float64) fm...
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 main import "fmt" type ByteSize float64 const ( _ = iota // ignore first value by assigning to blank identifier KB ByteSize = 1 << (10 * ...
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. 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)(C.stdou...
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. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) type appError struct { Err...
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. // This file contains the code snippets included in "The Laws of Reflection." package main import ( "fmt" "reflect" ) func main() { var x float64 = 3.4 f...
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. // This file contains the code snippets included in "The Go image/draw package." package main import ( "image" "image/color" "image/draw" ) func main() { ...
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. // This file contains examples to embed in the Go 1 release notes document. package main import ( "errors" "flag" "fmt" "log" "os" "path/filepath" "tes...
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. 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, 0, 255}) ...
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. package main import ( "io/ioutil" "regexp" ) func AppendByte(slice []byte, data ...byte) []byte { m := len(slice) n := m + len(data) if n > cap(slice) { ...
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. // This file contains the code snippets included in "Error Handling and Go." package main import ( "encoding/json" "errors" "fmt" "log" "net" "os" "tim...
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. package main import ( "encoding/json" "log" "reflect" ) type Message struct { Name string Body string Time int64 } // STOP OMIT func Encode() { m := ...
Go
package main import ( "flag" "log" "net/http" "text/template" ) var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18 var templ = template.Must(template.New("qr").Parse(templateStr)) func main() { flag.Parse() http.Handle("/", http.HandlerFunc(QR)) err := http.ListenAndServe(*addr, ni...
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. package main import ( "encoding/json" "fmt" "log" "reflect" ) func Decode() { b := []byte(`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Morticia"]}`) ...
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 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 struct{ X, Y *int...
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. package main import ( "encoding/json" "log" "reflect" ) type FamilyMember struct { Name string Age int Parents []string } // STOP OMIT func Dec...
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. // This file contains the code snippets included in "Defer, Panic, and Recover." package main import "fmt" import "io" // OMIT import "os" // OMIT func main(...
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. package print // #include <stdio.h> // #include <stdlib.h> import "C" import "unsafe" func Print(s string) { cs := C.CString(s) defer C.free(unsafe.Pointer(c...
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. 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 width and ...
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. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) func init() { http.Handle(...
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. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) func init() { http.HandleF...
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. // This file contains the code snippets included in "Defer, Panic, and Recover." package main import ( "fmt" "io" "os" ) func a() { i := 0 defer fmt.Pri...
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. // This file contains the code snippets included in "The Laws of Reflection." package main import ( "bufio" "bytes" "io" "os" ) type MyInt int var i int...
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. 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).In(r)) //...
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 main import ( "fmt" "sort" ) func main() { seq := Sequence{6, 2, -1, 44, 16} sort.Sort(seq) fmt.Println(seq) } type Sequence []int // Methods r...
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. package main import ( "fmt" "image" ) func main() { p := image.Point{2, 1} fmt.Println("X is", p.X, "Y is", p.Y) }
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. package query type Conn string func (c Conn) DoQuery(query string) Result { return Result("result") } type Result string func Query(conns []Conn, query stri...
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. 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.srandom(...
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. package rand /* #include <stdlib.h> */ import "C" // STOP OMIT func Random() int { return int(C.random()) } // STOP OMIT func Seed(i int) { C.srandom(C.uint...
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. 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.Println(r.Dx(), r...
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 ( "bytes" "encoding/gob" "fmt" "log" ) type P struct { X, Y, Z int Name string } type Q struct { X, Y *int32 Name string } fu...
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. // Test that top-level parenthesized declarations can be empty. // Compiles but does not run. package P import ( ) const ( ) var ( ) type ( )
Go
// run // 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. // Test that dynamic interface checks treat byte=uint8 // and rune=int or rune=int32. package main func main() { var x interface{} x = byte(1) sw...
Go
// $G $D/method4a.go && $G $D/$F.go && $L $F.$A && ./$A.out // 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. // Test method expressions with arguments. package main import "./method4a" type T1 int type T2...
Go
// run // 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. // Test that zero division causes a panic. package main import ( "fmt" "math" "runtime" "strings" ) type ErrorTest struct { name string fn fu...
Go
// run // 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. // Test range over strings. package main import ( "fmt" "os" "unicode/utf8" ) func main() { s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U001...
Go
// errorcheck // 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. // Verify that method redeclarations are caught by the compiler. // Does not compile. package main type T struct { } func (t *T) M(int, string)...
Go
// $G $D/$F.go && $L $F.$A && // ./$A.out -pass 0 >tmp.go && $G tmp.go && $L -o $A.out1 tmp.$A && ./$A.out1 && // ./$A.out -pass 1 >tmp.go && errchk $G -e tmp.go && // ./$A.out -pass 2 >tmp.go && errchk $G -e tmp.go // rm -f tmp.go $A.out1 // Copyright 2010 The Go Authors. All rights reserved. // Use of this source c...
Go
// $G $D/$F.go && $L -X main.tbd hello $F.$A && ./$A.out // 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. // Test the -X facility of the gc linker (6l etc.). package main var tbd string func main() { if ...
Go
// errorcheck // 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. // Verify that various erroneous type switches are caught be the compiler. // Does not compile. package main import "io" func whatis(x interfa...
Go
// run // 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. // Test if statements in various forms. package main func assertequal(is, shouldbe int, msg string) { if is != shouldbe { print("assertion fail", m...
Go
// run // 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. // Test that returning &T{} from a function causes an allocation. package main type T struct { int } func f() *T { return &T{1} } func main() { ...
Go
// run // 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. // Test recovering from runtime errors. package main import ( "runtime" "strings" ) var didbug bool func bug() { if didbug { return } printl...
Go
// run // 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. // Test static interface conversion of interface value nil. package main type R interface { R() } type RW interface { R(); W() } var e interface {} v...
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. // Check mutually recursive interfaces package recursive type I1 interface { foo() I2 } type I2 interface { bar() I1 } type T int func (t T) f...
Go
// run // 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. // Test interface values containing structures. package main import "os" var fail int func check(b bool, msg string) { if (!b) { println("failure...
Go
// errorcheck // 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. // Test methods derived from embedded interface and *interface values. package main import "os" const Value = 1e12 type Inter interface { M()...
Go
// skip # used by recursive2 // 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. // Mutually recursive type definitions imported and used by recursive1.go. package p type I1 interface { F() I2 } type I2 int...
Go
// run // 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. // Test interface comparisons using types hidden // inside reflected-on structs. package main import "reflect" type T struct { F float32 G float32 ...
Go
// $G $D/${F}1.go && errchk $G $D/$F.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. // Test that unexported methods are not visible outside the package. // Does not compile. package main import "./priv...
Go
// run // 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. // Test all the different interface conversion runtime functions. package main type Stringer interface { String() string } type StringLengther interf...
Go
// errorcheck // 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. // Test that interface{M()} = *interface{M()} produces a compiler error. // Does not compile. package main type Inst interface { Next() *Inst ...
Go
// errorcheck // 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. // Verify compiler messages about erroneous static interface conversions. // Does not compile. package main type T struct { a int } var t *T ...
Go
// run // 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. // Test methods derived from embedded interface values. package main import "os" const Value = 1e12 type Inter interface { M() int64 } type T int64...
Go
// run // 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. // Test static interface conversion of interface value nil. package main type R interface { R() } type RW interface { R(); W() } var e interface {} v...
Go
// $G $D/recursive1.go && $G $D/$F.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. // Test that the mutually recursive types in recursive1.go made it // intact and with the same meaning, by assigning to ...
Go
// errorcheck // 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. // Verify compiler complains about missing implicit methods. // Does not compile. package main type T int func (t T) V() func (t *T) P() type...
Go
// run // 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. // Test that interface conversion fails when method is missing. package main type I interface { Foo() } func main() { shouldPanic(p1) } func p1() ...
Go
// run // 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. // Test Implicit methods for embedded types and // mixed pointer and non-pointer receivers. package main type T int var nv, np int func (t T) V() { ...
Go
// $G $D/embed0.go && $G $D/$F.go && $L $F.$A && ./$A.out // 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. // Test that embedded interface types can have local methods. package main import "./embed0" type ...
Go
// run // 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. // Test interface methods with different return types are distinct. package main type S struct { a int } type T struct { b string } func (s *S) Name(...
Go
// skip # used by private.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. // Imported by private.go, which should not be able to see the private method. package p type Exported interface { private() } ...
Go
// run // 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. // Test big vs. small, pointer vs. value interface methods. package main type I interface { M() int64 } type BigPtr struct { a, b, c, d int64 } func ...
Go
// skip # used by embed1.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. // Test that embedded interface types can have local methods. package p type T int func (t T) m() {} type I interface { m() } ty...
Go
// run // 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. // Test run-time error detection for interface values containing types // that cannot be compared for equality. package main func main() { cmp(1) ...
Go
// errorcheck // 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. // Verify that renamed identifiers no longer have their old meaning. // Does not compile. package main func main() { var n byte // ERRO...
Go
// errorcheck // 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. // Verify goto semantics. // Does not compile. // // Each test is in a separate function just so that if the // compiler stops processing after ...
Go
// run // 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. // Test basic operation of finalizers. package main import ( "runtime" "time" ) const N = 250 type A struct { b *B n int } type B struct { n i...
Go
// run // 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. // Simple test of the garbage collector. package main import "runtime" func mk2() { b := new([10000]byte) _ = b // println(b, "stored at", &b) } ...
Go
// run // 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. // Solve the 2,3,5 problem (print all numbers with 2, 3, or 5 as factor) using channels. // Test the solution, silently. package main type T chan uint...
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. // Run runs tests in the test directory. // // TODO(bradfitz): docs of some sort, once we figure out how we're changing // headers of files package m...
Go
// errorcheck // 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. // Verify that incorrect comparisons are detected. // Does not compile. package main func use(bool) {} type T1 *int type T2 *int type T3 stru...
Go
// run // 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. // Test string literal syntax. package main import "os" var ecode int func assert(a, b, c string) { if a != b { ecode = 1 print("FAIL: ", c, ":...
Go