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. package main import ( "bufio" "fmt" "go/ast" "go/build" "go/doc" "go/parser" "go/token" "io/ioutil" "os" "os/exec" "runtime" "sort" "strings" "ti...
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" "os" "strconv" "strings" ) // The flag handling part of gotest is large and distracting. // We can't use the flag package beca...
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. /* Gotest is an automated testing tool for Go packages. Normally a Go package is compiled without its test files. Gotest is a tool that recompiles the packag...
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. /* 8c is a version of the Plan 9 C compiler. The original is documented at http://plan9.bell-labs.com/magic/man2html/1/2c Its target architecture is the x8...
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 ( "bytes" "flag" "fmt" "go/ast" "go/parser" "go/printer" "go/scanner" "go/token" "io" "io/ioutil" "os" "os/exec" "path/filepat...
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 ( "go/ast" "go/token" "reflect" ) type simplifier struct{} func (s *simplifier) Visit(node ast.Node) ast.Visitor { switch n := node.(...
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. /* Gofmt formats Go programs. Without an explicit path, it processes the standard input. Given a file, it operates on that file; given a directory, it operate...
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" "go/ast" "go/parser" "go/token" "os" "reflect" "strings" "unicode" "unicode/utf8" ) func initRewrite() { if *rewriteRul...
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. /* 8a is a version of the Plan 9 assembler. The original is documented at http://plan9.bell-labs.com/magic/man2html/1/2a Its target architecture is the x86...
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. /* Prof is a rudimentary real-time profiler. Given a command to run or the process id (pid) of a command already running, it samples the program's state at re...
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 var cmdGet = &Command{ Run: runGet, UsageLine: "get [importpath...]", Short: "download and install packages and dependencies", Long...
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 var cmdBuild = &Command{ Run: runBuild, UsageLine: "build [-n] [-v] [importpath...]", Short: "compile and install packages and depen...
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" "runtime" ) var cmdVersion = &Command{ Run: runVersion, UsageLine: "version", Short: "print Go version", Long: ...
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" "os" "strings" "text/template" ) // A Command is an implementation of a go command // like go build or go fix. ...
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 var cmdList = &Command{ Run: runList, UsageLine: "list [-f format] [-json] [importpath...]", Short: "list packages", Long: ` List l...
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 var helpImportpath = &Command{ UsageLine: "importpath", Short: "description of import paths", Long: ` Many commands apply to a set of pack...
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 var cmdFmt = &Command{ Run: runFmt, UsageLine: "fmt [importpath...]", Short: "run gofmt -w on packages", Long: ` Fmt runs the comma...
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 var cmdVet = &Command{ Run: runVet, UsageLine: "vet [importpath...]", Short: "run govet on packages", Long: ` Vet runs the govet co...
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 var cmdTest = &Command{ Run: runTest, UsageLine: "test [importpath...]", Short: "test packages", Long: ` Test runs gotest to test 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 main var cmdFix = &Command{ Run: runFix, UsageLine: "fix [importpath...]", Short: "run gofix on packages", Long: ` Fix runs the gofix co...
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 var cmdClean = &Command{ Run: runClean, UsageLine: "clean [-nuke] [importpath...]", Short: "remove intermediate objects", Long: ` 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. /* Go is a tool for managing Go source code. Usage: go command [arguments] The commands are: build compile and install packages and dependencies ...
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. /* Cov is a rudimentary code coverage tool. Given a command to run, it runs the command while tracking which sections of code have been executed. When the co...
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. /* 5g is the version of the gc compiler for the ARM. The $GOARCH for these tools is arm. It reads .go files and outputs .5 files. The flags are documented in ...
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. // Govet is a simple checker for static errors in Go source code. // See doc.go for more information. package main import ( "bytes" "flag" "fmt" "go/ast" ...
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. /* Govet does simple checking of Go source code. It checks for simple errors in calls to functions named Print Printf Println Fprint Fprintf Fprintln Sprin...
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. /* Nm is a version of the Plan 9 nm command. The original is documented at http://plan9.bell-labs.com/magic/man2html/1/nm It prints the name list (symbol t...
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. /* 6g is the version of the gc compiler for the x86-64. The $GOARCH for these tools is amd64. It reads .go files and outputs .6 files. The flags are documente...
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. // The template uses the function "code" to inject program // source into the output by extracting code from files and // injecting them as HTML-escaped <pre> b...
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 second = 1e9 ...
Go
package main import ( "fmt" "io/ioutil" "net/http" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) (*Page, error) { filename := title + ".txt" body, err := ioutil.ReadFi...
Go
package main import ( "flag" "fmt" "io" "log" "net" "net/http" "os" "strings" ) var ( post = flag.String("post", "", "urlencoded form data to POST") addr = flag.Bool("addr", false, "find open address and print to stdout") ) func main() { flag.Parse() if *addr { l, err := net.Listen("tcp", "127.0.0.1:0"...
Go
package main import ( "fmt" "io/ioutil" "net/http" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) (*Page, error) { filename := title + ".txt" body, err := ioutil.ReadFi...
Go
package main import ( "fmt" "io/ioutil" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) *Page { filename := title + ".txt" body, _ := ioutil.ReadFile(filename) return &P...
Go
package main import ( "io/ioutil" "net/http" "text/template" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) (*Page, error) { filename := title + ".txt" body, err := iou...
Go
package main import ( "io/ioutil" "os" "text/template" ) func main() { b, _ := ioutil.ReadAll(os.Stdin) template.HTMLEscape(os.Stdout, b) }
Go
package main import ( "io/ioutil" "net/http" "text/template" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) (*Page, error) { filename := title + ".txt" body, err := iou...
Go
package main import ( "fmt" "io/ioutil" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) (*Page, error) { filename := title + ".txt" body, err := ioutil.ReadFile(filename)...
Go
package main import ( "io/ioutil" "net/http" "regexp" "text/template" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) (*Page, error) { filename := title + ".txt" body, ...
Go
package main import ( "errors" "io/ioutil" "net/http" "regexp" "text/template" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) (*Page, error) { filename := title + ".tx...
Go
package main import ( "bytes" "flag" "go/ast" "go/parser" "go/printer" "go/token" "log" "os" "text/template" ) var ( srcFn = flag.String("src", "", "source filename") getName = flag.String("name", "", "func/type name to output") html = flag.Bool("html", true, "output HTML") showPkg = flag.Bool("pkg"...
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
package main import ( "io/ioutil" "net/http" "regexp" "text/template" ) type Page struct { Title string Body []byte } func (p *Page) save() error { filename := p.Title + ".txt" return ioutil.WriteFile(filename, p.Body, 0600) } func loadPage(title string) (*Page, error) { filename := title + ".txt" body, ...
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 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" // Send the sequence 2, 3, 4, ... to returned channel func generate() chan int { ch := make(chan int) go func() { for i := 2; ;...
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 ( "./file" "flag" "fmt" "os" ) func cat(f *file.File) { const NBUF = 512 var buf [NBUF]byte for { switch nr, er := f.Read(buf[:])...
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" func main() { var u64 uint64 = 1<<64 - 1 fmt.Printf("%d %d\n", u64, int64(u64)) // harder stuff type T struct { a int b str...
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 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 ( "log" "unicode" ) func main() { stringAppend() mapDelet...
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 testType struct { a int b string } func (t *testType) String() string { return fmt.Sprint(t.a) + " " + t.b } func main() {...
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 "os" func main() { s := "hello" if s[1] != 'e' { os.Exit(1) } s = "good bye" var p *string = &s *p = "ciao" }
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" // Send the sequence 2, 3, 4, ... to channel 'ch'. func generate(ch chan int) { for i := 2; ; i++ { ch <- i // Send 'i' to channe...
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 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 ( "./file" "fmt" "os" ) func main() { hello := []byte("hello, world\n") file.Stdout.Write(hello) f, err := file.Open("/does/not/exis...
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 file import ( "os" "syscall" ) type File struct { fd int // file descriptor number name string // file name at Open time } func newFile(fd i...
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 ( "os" "flag" // command line option parser ) var omitNewline = flag.Bool("n", false, "don't print final newline") const ( Space = "...
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 request struct { a, b int replyc chan int } type binOp func(a, b int) int func run(op binOp, req *request) { reply := op...
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 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 ( "./file" "flag" "fmt" "os" ) var rot13Flag = flag.Bool("rot13", false, "rot13 the input") func rot13(b byte) byte { if 'a' <= b &&...
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 ints() { data := []int{74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586} a := sort.IntSlice(d...
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 request struct { a, b int replyc chan int } type binOp func(a, b int) int func run(op binOp, req *request) { reply := op...
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" func sum(a []int) int { // returns an int s := 0 for i := 0; i < len(a); i++ { s += a[i] } return s } func main() { x := [3]...
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 "fmt" // Package implementing formatted I/O. func main() { fmt.Printf("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界\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 sort type Interface interface { Len() int Less(i, j int) bool Swap(i, j int) } func Sort(data Interface) { for i := 1; i < data.Len(); i++ { for...
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 file import ( "os" "syscall" ) type File struct { fd syscall.Handle // file descriptor number name string // file name at Open time } f...
Go
// $G $D/$F.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 P import ( ) const ( ) var ( ) type ( )
Go
// $G $D/$F.go && $L $F.$A && ./$A.out // 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 // Test that dynamic interface checks treat byte=uint8 // and rune=int or rune=int32. func main() { var...
Go
// $G $F.go && $L $F.$A && ./$A.out // 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" "math" "runtime" "strings" ) type ErrorTest struct { name string fn func() err stri...
Go
// $G $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. package main import ( "fmt" "os" "unicode/utf8" ) func main() { s := "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe\U001...
Go
// errchk $G $D/$F.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 type T struct { } func (t *T) M(int, string) // GCCGO_ERROR "previous" func (t *T) M(int, float64) { } // ERROR "redeclar...
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. // Garbage collection benchmark: parse Go packages repeatedly. package main import ( "flag" "fmt" "go/ast" "go/parser" "go/token" "log" "net/http" _ ...
Go
// $G $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. package main import ( "fmt" "runtime" "time" ) type Number struct { next *Number } // ----------------------------...
Go
/* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form ...
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" "runtime" "sort" ) func gcstats(name string, n int, t int64) { st := &runtime.MemStats fmt.Printf("garbage.%sMem Alloc=%d/%d...
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
// errchk $G -e $D/$F.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 "io" func whatis(x interface{}) string { switch x.(type) { case int: return "int" case int: // ERROR "dupli...
Go
// $G $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. package main func assertequal(is, shouldbe int, msg string) { if is != shouldbe { print("assertion fail", msg, "\n") ...
Go
// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: compos // 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 type T struct { int } func f() *T { return &T{1} } func main() { x := f() y := ...
Go
// $G $D/$F.go && $L $F.$A && ./$A.out // 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 ( "runtime" "strings" ) var didbug bool func bug() { if didbug { return } println("BUG") ...
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. // Check that static interface conversion of // interface value nil succeeds. package main type R interface { R() } ty...
Go
// $G $D/$F.go || echo BUG: should 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 main type I1 interface { foo() I2 } type I2 interface { bar() I1...
Go
// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG interface6 // 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. // Interface values containing structures. package main import "os" var fail int func check(b...
Go
// errchk $G -e $D/$F.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. // Check methods derived from embedded interface and *interface values. package main import "os" const Value = 1e12 type Inter int...
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. // Interface comparisons using types hidden // inside reflected-on structs. package main import "reflect" type T stru...
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. package main import "./private1" type Exported interface { private() } type Implementation struct{} func (p *Imple...
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. // Check uses of all the different interface // conversion runtime functions. package main type Stringer interface { ...
Go
// errchk $G $D/$F.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. // Check that interface{M()} = *interface{M()} produces a compiler error. package main type Inst interface { Next() *Inst } type Rege...
Go
// errchk $G -e $D/$F.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. // Static error messages about interface conversions. package main type T struct { a int } var t *T type I interface { M() } va...
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. // Check methods derived from embedded interface values. package main import "os" const Value = 1e12 type Inter inte...
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. // Check that static interface conversion of // interface value nil succeeds. package main type R interface { R() } ty...
Go
// errchk $G $D/$F.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. // Error messages about missing implicit methods. package main type T int func (t T) V() func (t *T) P() type V interface { V() } ty...
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. // Check that interface conversion fails when method is missing. package main type I interface { Foo() } func main()...
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. // Implicit methods for embedded types. // Mixed pointer and non-pointer receivers. package main type T int var nv, n...
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. // Check that embedded interface types can have local methods. package main import "./embed0" type...
Go