code
stringlengths
10
1.34M
language
stringclasses
1 value
// Share is a piece of demo code to illustrate the flexibility of the rpc and netchan // packages. It requires one instance to be running in server mode on some network // address addr, e.g. localhost:3456: // // share -s localhost:3456 // // Then in other windows or on other machines, run some client instances: // sh...
Go
// The stackgraph command reads a Go stack trace (as produced by a Go // panic) from its standard input and writes an SVG file suitable for // viewing in a web browser on its standard output. It assumes that // graphviz is installed. // // All the dot(1) heuristics were unashamedly stolen from go tool pprof. // // Exam...
Go
package main import ( "bytes" "fmt" "io" "log" "math" "os" "os/exec" "regexp" "strings" "text/template" ) func (n *Node) ArgCounts() string { counts := make([]string, len(n.ArgCount)) for i, m := range n.ArgCount { if len(m) == 1 { for val, _ := range m { counts[i] = fmt.Sprintf("=%#x", val) }...
Go
// Share is a piece of demo code to illustrate the flexibility of the rpc and netchan // packages. It requires one instance to be running in server mode on some network // address addr, e.g. localhost:3456: // // share -s localhost:3456 // // Then in other windows or on other machines, run some client instances: // sh...
Go
// Share is a piece of demo code to illustrate the flexibility of the rpc and netchan // packages. It requires one instance to be running in server mode on some network // address addr, e.g. localhost:3456: // // share -s localhost:3456 // // Then in other windows or on other machines, run some client instances: // sh...
Go
package main import ( "code.google.com/p/goplan9/plan9/acme" "fmt" "io" "os" "os/user" "strconv" "strings" ) // We would use io.Copy except for a bug in acme // where it crashes when reading trying to read more // than the negotiated 9P message size. func copyBody(w io.Writer, win *acme.Win) error { buf := ma...
Go
// The apipe command pipes the contents of the current acme window // through its argument shell command and updates them to the result // by applying minimal changes. // // For example: // // apipe gofmt // // will alter only the pieces of source code that // have changed, leaving the rest untouched. package main im...
Go
package main import ( "code.google.com/p/freetype-go/freetype/raster" "code.google.com/p/rog-go/canvas" "code.google.com/p/rog-go/values" "exp/draw" "exp/draw/x11" "fmt" "image" "image/color" "log" ) var cvs *canvas.Canvas func main() { ctxt, err := x11.NewWindow() if ctxt == nil { log.Fatalf("no window...
Go
// The timestamp command annotates lines read from standard input // with the time that they were read. This is useful for seeing // timing information on running commands from the shell. // // With no file arguments, timestamp prints lines read // from standard input prefixed with a timestamp, // the time since the ti...
Go
package main import ( "code.google.com/p/freetype-go/freetype/truetype" "code.google.com/p/rog-go/canvas" "code.google.com/p/rog-go/values" "code.google.com/p/x-go-binding/ui" "code.google.com/p/x-go-binding/ui/x11" "fmt" "image" "image/color" "io/ioutil" "log" "math" "math/rand" "os" "time" ) // to add...
Go
package main import ( "code.google.com/p/rog-go/canvas" "exp/draw" "exp/draw/x11" "flag" "image" "image/color" "log" "time" ) type stack struct { f Fractal centre draw.Point iterations int next *stack } type context struct { cvs *canvas.Canvas f Fractal pushed *s...
Go
// rpcreader demonstrates using RPC to initiate file streaming // over the same connection. // // Start a server instance with: // // rpcreader -s addr // // Start a client with: // // rpcreader addr // // The client is interactive. There's only one command: read, // which takes a list of filename arguments and...
Go
// A "simple" program to display some text and let the // user drag it around. It will get simpler... package main import ( "code.google.com/p/freetype-go/freetype/truetype" "code.google.com/p/rog-go/canvas" "code.google.com/p/rog-go/x11" "exp/draw" "image" "io/ioutil" "log" "os" ) var cvs *canvas.Canvas fun...
Go
package main import ( "fmt" "sort" ) var help = genericOp{0, 0, func(*stack, string) { var lines []string for name, vs := range ops { lines = append(lines, fmt.Sprintf("%s[%d]", name, argCount(vs[0]))) } sort.Strings(lines) for _, l := range lines { fmt.Printf("%s\n", l) } }} func printAll() { for name,...
Go
package main import ( "errors" "fmt" "math/big" "os" "reflect" "strings" ) // TODO: // simplify - remove all [ ], [[ ]]. // reinstate fc's -x, -b format specifiers // remove % operator. // instead, make (float, rat, int) operators taint // the stack so that input numbers are converted by // default when non-spe...
Go
/* Calc is a calculator designed to be run on the command line. Expressions rarely require quoting and work easily with other command line tools that produce or require whitespace-separated text. Here is a brief overview by demonstration: # The command line is revert-polish - operands are # pushed onto a stack; ope...
Go
package main import ( "math" "math/big" "regexp" "strconv" "strings" ) var ops = map[string][]interface{}{ // constants "pi": {math.Pi}, "e": {math.E}, "phi": {math.Phi}, "nan": {math.NaN()}, "infinity": {math.Inf(1)}, // functions from math package. "abs": {math.Abs, (*big...
Go
package main import ( "fmt" "math/rand" // "time" stats "github.com/patrick-higgins/summstat" ) func main() { // rand.Seed(int64(time.Now().Nanosecond())) r := make([]*stats.Stats, 4) for i := range r { r[i] = stats.NewStats() // r[i].CreateBins(100, 0, 200) } const n = 100000 for i := 0; i < n; i++ { cs ...
Go
package main func newCharacter(paths map[string][]square) *character { ch := &character{ paths: paths, roll: roll, } ch.pos = findPos(ch, "start", 1) return ch } var peterPaths = map[string][]square{ "start": []square{ 5: { land: jumpTo("start", 1), }, 7: { land: jumpTo("under gate", 1), }, 1...
Go
package main import ( "code.google.com/p/rog-go/loopback" "flag" "fmt" "io" "os" ) var localNet = flag.String("i", "tcp", "network to listen on (accepts loopback options)") var remoteNet = flag.String("r", "tcp", "network to dial (accepts loopback options)") var useStdin = flag.Bool("s", false, "use stdin and st...
Go
/* The pxargs command is a simpler version of xargs(1) that can execute commands in parallel. It reads lines from standard input and executes the command with the lines as arguments. Flags determine the maximum number of arguments to give to the command and the maximum number of commands to run concurrently. Unlike xa...
Go
package main import ( "bytes" "flag" "fmt" "launchpad.net/goamz/aws" "launchpad.net/goamz/ec2" "os" "regexp" "strings" ) type cmd struct { name string args string f func(cmd, *ec2.EC2, []string) flags *flag.FlagSet } var cmds []cmd func main() { flag.Parse() if flag.Arg(0) == "" { errorf("no c...
Go
package loopback import ( "errors" "io" "log" "sync" "time" ) // TODO implement CloseWithError. // BUG close propagates faster than latency time. // send close as a block with nil data. type block struct { // t holds the time that the block is due to emerge into the // input queue. t time.Time data []byt...
Go
package loopback import ( "errors" "io" "net" "time" ) // NetPipe creates a synchronous, in-memory, full duplex // network connection; both ends implement the net.Conn interface. // The opt0 options apply to the traffic from c0 to c1; // the opt1 options apply to the traffic from c1 to c0. func NetPipe(opt0, opt1...
Go
package loopback import ( "bytes" "errors" "fmt" "io" "strings" "time" "unicode" ) var errEmpty = errors.New("empty") func parseNetwork(net string) (inOpts, outOpts Options, actualNet string, err error) { if net == "" { err = errors.New("empty network name") return } if net[0] != '[' { actualNet = ne...
Go
package loopback import ( "code.google.com/p/rog-go/fakenet" "io" "net" ) // Dial is the same as net.Dial except that it also recognises // networks with the prefix "loopback:"; it removes // the prefix, dials the original network, and then applies // the given loopback Options. Incoming data has inOpts // applied...
Go
package basic import ( "code.google.com/p/rog-go/exp/abc" "os" ) func init() { abc.Register("stdout", map[string]abc.Socket{ "1": abc.Socket{FdT, abc.Female}, }, makeStdout) } func makeStdout(_ *abc.Status, args map[string]interface{}) abc.Widget { in := args["1"].(Fd) in.PutWriter(os.Stdout) return nil }
Go
package basic import ( "code.google.com/p/rog-go/exp/abc" "os" ) func init() { abc.Register("write", map[string]abc.Socket{ "1": abc.Socket{FdT, abc.Female}, "2": abc.Socket{abc.StringT, abc.Female}, }, makeWrite) } func makeWrite(_ *abc.Status, args map[string]interface{}) abc.Widget { in := args["1"].(Fd)...
Go
package basic import ( "code.google.com/p/rog-go/exp/abc" "io" ) func Use() { } // male side sends reader (or nil if it has no preference); // female replies with the actual fd to use (or nil if there's been an error) var FdT = &abc.Type{"fd", false, func(x interface{}) (ok bool) { _, ok = x.(Fd); return }} type ...
Go
package basic import ( "code.google.com/p/rog-go/exp/abc" "strings" ) func init() { abc.Register("echo", map[string]abc.Socket{ "1": abc.Socket{abc.StringT, abc.Female}, "out": abc.Socket{FdT, abc.Male}, }, makeEcho) } func makeEcho(_ *abc.Status, args map[string]interface{}) abc.Widget { s := args["1"].(s...
Go
package basic import ( "code.google.com/p/rog-go/exp/abc" ) func init() { abc.Register("rot13", map[string]abc.Socket{ "out": abc.Socket{FdT, abc.Male}, "1": abc.Socket{FdT, abc.Female}, }, makeRot13) } func makeRot13(_ *abc.Status, args map[string]interface{}) abc.Widget { in := args["1"].(Fd) out := NewF...
Go
package basic import ( "code.google.com/p/rog-go/exp/abc" "io" "os" ) func init() { abc.Register("stdin", map[string]abc.Socket{ "out": abc.Socket{FdT, abc.Male}, }, makeStdin) } func makeStdin(_ *abc.Status, args map[string]interface{}) abc.Widget { out := NewFd() args["out"].(chan interface{}) <- out if ...
Go
package basic import ( "code.google.com/p/rog-go/exp/abc" "io" "os" ) func init() { abc.Register("read", map[string]abc.Socket{ "1": abc.Socket{abc.StringT, abc.Female}, "out": abc.Socket{FdT, abc.Male}, }, makeRead) } func makeRead(_ *abc.Status, args map[string]interface{}) abc.Widget { f := args["1"]....
Go
package abc import ( "container/vector" "fmt" "strconv" ) // transform ADT into a set of commands type tContext struct { *context cmds *vector.Vector } func (ctxt *context) transform(a *assign, cmds *vector.Vector) { tctxt := &tContext{context: ctxt, cmds: cmds} tctxt.transformAssign(a) fmt.Println("done tr...
Go
package abc import ( "container/vector" "fmt" "os" "reflect" "strconv" "strings" "text/scanner" ) type Type struct { Name string Mux bool Test func(interface{}) bool } var StringT = &Type{ "string", true, IsType(""), } type Gender bool const ( Male = Gender(false) Female = Gender(true) ) type So...
Go
package abc import ( "fmt" "sync" ) var StatusT = &Type{ "status", true, IsType((*StatusManager)(nil)), } type StatusManager struct { lock sync.Mutex running int waiting int wakeup chan bool } type Status struct { m *StatusManager } func (m *StatusManager) Go(fn func(status *Status)) { m.lock.Lock()...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" ) func init() { abc.Register("auwrite", map[string]abc.Socket{ "out": abc.Socket{basic.Fd, abc.Male}, "1": abc.Socket{SamplesT, abc.Female}, }, makeWrite) } func makeWrite(args map[string]interface{}) abc.Widget { out := basic.NewFd() args["out"].(...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" "fmt" "math" "os" "strconv" ) // phaser stolen from audacity. // audacity-src-1.3.12-beta/src/effects/Phaser.cpp type PhaserWidget struct { Format input Widget // parameters freq, startphase, fb, drywet float32 depth, stages int //...
Go
package audio import ( "bytes" "fmt" ) var indentLevel int func un(_ bool, rets ... interface{}) { if x := recover(); x != nil { panic(x) } indentLevel-- if Debug { s := "" if len(rets) > 0 { s = " -> " + fmt.Sprint(rets...) } fmt.Printf("%s}%s\n", indent(), s) } } func log(f string, args ... int...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" "fmt" "strings" "sync" ) var SamplesT = &abc.Type{"samples", false, abc.IsType((*node)(nil))} var AudioEnvT = &abc.Type{"audio", true, abc.IsType((*context)(nil))} var TimeT = &abc.Type{"time", true, abc.IsType(Time{})} type widgetKind int const ( wInpu...
Go
package audio import ( "fmt" "sync" ) type RingBufWidget struct { minr0 int64 // minimum offset of any reader, in elements (but no reader can be more than maxsize behind r1, so r1 - minr0 <= maxsize) r1 int64 // offset of max sample in buffer + 1. samples Buffer size int // current capacity of buffer ...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" "fmt" "strconv" "strings" "os" ) type Time struct { t int64 real bool // real time (in nanoseconds) ? } func init() { abc.Register("time", map[string]abc.Socket{ "1": abc.Socket{abc.StringT, abc.Female}, "out": abc.Socket{TimeT, abc.Male}, }...
Go
package audio import ( "math" "strconv" "code.google.com/p/rog-go/exp/abc" ) type waveWidget struct { freq float64 samples []float32 Format } func SinWave(freq float64, rate int) (w *waveWidget) { w = &waveWidget{} w.Rate = rate w.NumChans = 1 w.Type = Float32Type w.Layout = Interleaved w.freq = freq ...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" "fmt" ) // a simplified, 1-reader ring buffer that can // deal with reads greater than the buffer size. type DelayWidget struct { Format buf Buffer size int delay Time r0 int64 // time of sample in buffer input Widget eofpos int64 eof ...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" "bufio" "fmt" "os" ) type GraphWidget struct { Format input Widget } func init() { Register("graph", wOutput, map[string]abc.Socket{ "1": abc.Socket{SamplesT, abc.Female}, }, makeGraph) } func makeGraph(status *abc.Status, args map[string]interface...
Go
package main import "abc/audio" import "testing" var tests = []testing.Test { testing.Test{ "audio.TestParserWithPipes", audio.TestParserWithPipes }, testing.Test{ "audio.TestConversion", audio.TestConversion }, } var benchmarks = []testing.Benchmark { } func main() { testing.Main(tests); testing.RunBenchmarks(b...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" "strconv" ) type EnvelopeWidget struct { Format read func(b Float32Buf, t int64) int64 t0, a, d, s, r Time sustainlev float32 } func init() { Register("envelope", wOutput, map[string]abc.Socket{ "start": abc.Socket{TimeT, abc.Female}, ...
Go
package audio import "code.google.com/p/rog-go/exp/abc" type PermuteWidget struct { Format input Widget p []int buf Buffer permute func(b0, b1 Buffer, p []int) } func init() { Register("permute", wProc, map[string]abc.Socket{ "out": abc.Socket{SamplesT, abc.Male}, "1": abc.Socket{SamplesT, abc.Fem...
Go
package audio import "code.google.com/p/rog-go/exp/abc" type MultiplierWidget struct { Format eof bool buf ContiguousFloat32Buffer w0, w1 Widget } func init() { Register("multiply", wProc, map[string]abc.Socket{ "out": abc.Socket{SamplesT, abc.Male}, "1": abc.Socket{SamplesT, abc.Female}, "2": a...
Go
package audio import ( "fmt" ) type Buffer interface { Len() int Zero(i0, i1 int) Copy(i0 int, src Buffer, j0, j1 int) Slice(i0, i1 int) Buffer GetFormat() Format } type ContiguousFloat32Buffer interface { Buffer AsFloat32Buf() Float32Buf AllocFromFloat32Buf(buf Float32Buf) ContiguousFloat32Buffer } type F...
Go
package audio type Format struct { NumChans int // number of channels (0 if unset) Rate int // samples per second (0 if unset) Layout int Type int } type Formatted interface { GetFormat(name string) Format } type FormatSetter interface { SetFormat(f Format) } const Unspecified = 0 // layouts (earlier are...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" "strconv" ) func init() { Register("mix", wProc, map[string]abc.Socket{ "out": abc.Socket{SamplesT, abc.Male}, "1": abc.Socket{SamplesT, abc.Female}, "2": abc.Socket{SamplesT, abc.Female}, }, makeMixer) } type MixWidget struct { Format buf ...
Go
package audio import ( "fmt" ) type Buffer interface { Len() int Zero(i0, i1 int) Copy(i0 int, src Buffer, j0, j1 int) Slice(i0, i1 int) Buffer GetFormat() Format } type ContiguousFloat32Buffer interface { Buffer AsFloat32Buf() Float32Buf AllocFromFloat32Buf(buf Float32Buf) ContiguousFloat32Buffer } type F...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" "os" "fmt" "io" "encoding/binary" "reflect" "strings" ) func init() { Register("readwav", wInput, map[string]abc.Socket{ "out": abc.Socket{SamplesT, abc.Male}, "1": abc.Socket{abc.StringT, abc.Female}, }, makeWavReader) Register("writewav", wOu...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" ) func init() { abc.Register("input", map[string]abc.Socket{ "audio", abc.Socket{SamplesT, abc.Female}, "out": abc.Socket{SamplesT, abc.Male}, "1": abc.Socket{abc.StringT, abc.Female}, }, makeInput) } func makeInput(args map[string]interface{}) abc...
Go
package audio import ( "code.google.com/p/rog-go/exp/abc" ) func init() { abc.Register("auread", map[string]abc.Socket{ "out": abc.Socket{SamplesT, abc.Male}, "1": abc.Socket{basic.Fd, abc.Female}, }, makeRead) } func makeRead(args map[string]interface{}) abc.Widget { var r sampleReader r.Init(args["1"].(...
Go
package audio import ( "fmt" ) type ConverterWidget struct { outfmt Format infmt Format input Widget } // conversions, in order of application // type - float32 -> int16 & vice versa (punt for now) // num channels - use permute // layout // sample rate - punt for now func Converter(input Widget, f Format) (w *C...
Go
// +build ignore package audio import ( "code.google.com/p/rog-go/exp/abc" ) func init() { abc.Register("output", map[string]abc.Socket{ "audio", abc.Socket{SamplesT, abc.Female}, "1": abc.Socket{SamplesT, abc.Female}, "2": abc.Socket{abc.StringT, abc.Female}, }, makeOutput) } func makeOutput(args map[stri...
Go
// The stringfs package provides a way to recursively encode the // data in a directory as a string, and to extract the contents later. package stringfs import ( "bytes" "encoding/binary" "encoding/gob" "errors" "os" "strings" "sync" ) // The file system encoding uses gob to encode the // metadata. // It takes...
Go
package rpcreflect import ( "fmt" "encoding/json" "reflect" "strings" ) // simple types: // string -> "string" // int8, int64 etc -> "number" // interface{} -> "any" // // composite types: // slice, array -> [elemType] // struct -> {"Field1": field1Type, "Field2": field2Type, etc} // map -> {"_map": elemType} // ...
Go
package breader import ( "io" "io/ioutil" "os" ) type bufferedReader struct { req chan []byte reply chan int tmpf *os.File error error } const ioUnit = 16 * 1024 // NewReader continually reads from in and buffers the data // inside a temporary file (created with ioutil.TempFile(dir, prefix)). // It return...
Go
package stquery import ( "fmt" "reflect" "strings" ) // Scanner represents a database row that can scan itself. type Scanner interface { Scan(dest ...interface{}) error } // Statement returns an SQL query statement that selects columns based // on the names of the fields in dest, which must be a pointer // to a ...
Go
// Timestamp recording (for debugging). package stamp import ( "bytes" "fmt" "sort" "sync" "time" ) type stamp struct { msg string t int64 } var mu sync.Mutex type stampVector []stamp var stamps = make(stampVector, 0, 100) // AddTime records a timestamp at the given time. func AddTime(msg string, t int64...
Go
package key // Mapping holds a set of unique keys corresponding // to Hasher values. type Mapping struct { keys map[uint64]*entry } // Hasher represents a value that can be used as a map key. type Hasher interface { Hashcode() uint64 Equals(m Hasher) bool } type entry struct { mkey Hasher key Key next *entry ...
Go
// ulimit -n 30000 package main import ( "bytes" "code.google.com/p/go.net/websocket" "encoding/json" "fmt" "io" "log" "net/http" "os" "strconv" "sync" "time" ) func echoServer(ws *websocket.Conn) { io.Copy(ws, ws) } type Stat struct { Delay time.Duration Connect time.Duration Latency []time.Duratio...
Go
package main import ( "bufio" "code.google.com/p/rog-go/exp/go/token" "fmt" "io" "log" "os" "strings" "unicode" ) func readLines(f func(sl *symLine) error) error { r := bufio.NewReader(os.Stdin) for { line, isPrefix, err := r.ReadLine() if err == io.EOF { break } if err != nil { return fmt.Err...
Go
// The gosym command manipulates symbols in Go source code. // It supports the following commands: // // gosym short // // The short command reads lines from standard input // in short or long format (see the list command) and // prints them in short format: // file-position name new-name // The file-position field h...
Go
package main import ( "code.google.com/p/rog-go/exp/go/ast" "code.google.com/p/rog-go/exp/go/sym" "code.google.com/p/rog-go/exp/go/types" "flag" "fmt" "log" "strings" "unicode" ) type listCmd struct { all bool verbose bool printType bool kinds string ctxt *context } var listAbout = ` go...
Go
package main import ( "code.google.com/p/rog-go/exp/go/ast" "code.google.com/p/rog-go/exp/go/sym" "code.google.com/p/rog-go/exp/go/token" "fmt" "log" ) type writeCmd struct { *context // lines holds all input lines. lines map[token.Position]*symLine // symPkgs holds packages that are mentioned in input //...
Go
package main import ( "code.google.com/p/rog-go/exp/go/ast" "code.google.com/p/rog-go/exp/go/token" "fmt" "regexp" "strconv" "strings" ) type symLine struct { pos token.Position // file address of identifier; addr.Offset is zero. referPos token.Position // file address of referred-to identifier. long ...
Go
package test import "other" func %test test X func+%X() { %test test x var+%x := 0 for %test test i var+%i := 0; %test test i var%i < %test test x var%x; %test test i var%i++ { %test test i var+%i := %test test i var%i %test test x var%x += %test test i var%i } other.%test other Println func%Println(%test test...
Go
package main import ( "encoding/json" "fmt" "os" "sort" "time" ) type Stat struct { Delay time.Duration Connect time.Duration Latency []time.Duration Error string `json:"omitempty"` } type Info struct { Stats []Stat Total time.Duration } func main() { var info Info err := json.NewDecoder(os.Stdin)....
Go
package main import ( "fmt" "io" "os" "os/user" "strconv" "strings" "github.com/9fans/go/acme" ) type acmeFile struct { name string body []byte offset int runeOffset int } func acmeCurrentFile() (*acmeFile, error) { win, err := acmeCurrentWin() if err != nil { return nil, err } defe...
Go
package main import ( "bytes" "code.google.com/p/rog-go/exp/go/ast" "code.google.com/p/rog-go/exp/go/parser" "code.google.com/p/rog-go/exp/go/printer" "code.google.com/p/rog-go/exp/go/token" "code.google.com/p/rog-go/exp/go/types" "errors" "flag" "fmt" "go/build" "io/ioutil" "os" "path/filepath" "runtime...
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. /* Godef prints the source location of definitions in Go programs. Usage: godef [-t] [-a] [-A] [-o offset] [-i] [-f file][-acme] [expr] File specifies the ...
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" "flag" "fmt" "go/ast" "go/format" "go/parser" "go/scanner" "go/token" "io/ioutil" "os" "os/exec" "path/filepath" "so...
Go
package main import ( "fmt" "go/ast" "go/token" "log" "path" "strconv" "strings" ) func init() { register(causeFix) register(maskFix) register(newFix) } const errgoPkgPath = "github.com/juju/errgo" var maskFix = fix{ "errgo-mask", "2014-02-10", errgoMask, `wrap all returned errors; use errgo for all e...
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" "go/ast" "go/token" "os" "reflect" "strings" ) // Partial type checker. // // The fact that it is partial is very important...
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" "go/ast" "go/parser" "go/token" "os" "path" "reflect" "strconv" "strings" ) type fix struct { name string date string ...
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. /* Fix finds Go programs that use old APIs and rewrites them to use newer ones. After you update to a new Go release, fix helps make the necessary changes to y...
Go
package main import ( "fmt" "go/token" "reflect" "unsafe" "code.google.com/p/go.tools/go/ssa" "code.google.com/p/go.tools/oracle" ) func (ctxt *context) callees(inst *ssa.Call) ([]*ssa.Function, error) { pos := ctxt.lprog.Fset.Position(inst.Pos()) if pos.Line <= 0 { return nil, fmt.Errorf("no position") }...
Go
package main import ( "errors" "flag" "fmt" "io" "log" "os" "regexp" "go/token" "code.google.com/p/go.tools/go/loader" "code.google.com/p/go.tools/go/ssa" "code.google.com/p/go.tools/go/types" "code.google.com/p/go.tools/oracle" "github.com/davecgh/go-spew/spew" ) var spewConf = spew.ConfigState{ Inden...
Go
// +build ignore package main import ( "errors" "fmt" "os" "local/foo.bar" ) func errorHandler(err *error) {} // doScan does the real work for scanning without a format string. func doScan(a []interface{}) (numProcessed int, err error) { defer errorHandler(&err) return } func main() { testProg() } func te...
Go
package gobrpc import ( "code.google.com/p/rog-go/exp/filemarshal" "io" "net/rpc" ) type clientCodec struct { c io.Closer enc filemarshal.Encoder dec filemarshal.Decoder } func NewClientCodec(conn io.ReadWriteCloser, enc filemarshal.Encoder, dec filemarshal.Decoder) rpc.ClientCodec { return &clientCodec{con...
Go
// package filemarshal import ( "code.google.com/p/rog-go/typeapply" "errors" "io" "io/ioutil" "os" ) // A File holds on-disk storage. type File struct { Name string // The name of the file. file *os.File } // NewFile creates a new file referring to f, // which should be seekable (i.e. not a pipe // or netwo...
Go
package callback //#include "callback.h" import "C" import ( "runtime" "unsafe" ) //export newCallbackRunner func newCallbackRunner() { go C.runCallbacks() } func init() { // work around issue 1560. if runtime.GOMAXPROCS(0) < 2 { runtime.GOMAXPROCS(2) } C.callbackInit() go C.runCallbacks() } // Func hold...
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 scanner import ( "code.google.com/p/rog-go/exp/go/token" "fmt" "io" "sort" ) // An implementation of an ErrorHandler may be provided to the Scanne...
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 scanner implements a scanner for Go source text. Takes a []byte as // source which can then be tokenized through repeated calls to the Scan // functi...
Go
// The sym package provides a way to iterate over and change the symbols in Go // source files. package sym import ( "bytes" "code.google.com/p/rog-go/exp/go/ast" "code.google.com/p/rog-go/exp/go/parser" "code.google.com/p/rog-go/exp/go/printer" "code.google.com/p/rog-go/exp/go/token" "code.google.com/p/rog-go/e...
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. // A parser for Go source files. Input may be provided in a variety of // forms (see the various Parse* functions); the output is an abstract // syntax tree (AS...
Go
package parser import "code.google.com/p/rog-go/exp/go/ast" var Universe = ast.NewScope(nil) func declObj(kind ast.ObjKind, name string) { // don't use Insert because it forbids adding to Universe Universe.Objects[name] = ast.NewObj(kind, name) } func init() { declObj(ast.Typ, "bool") declObj(ast.Typ, "complex...
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. // This file contains the exported entry points for invoking the parser. package parser import ( "bytes" "code.google.com/p/rog-go/exp/go/ast" "code.google...
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. // This package defines constants representing the lexical // tokens of the Go programming language and basic operations // on tokens (printing, predicates). //...
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. // TODO(gri) consider making this a separate package outside the go directory. package token import ( "fmt" "sort" "sync" ) // Position describes an arbit...
Go
package types import ( "runtime" "strings" ) // Code for determining system-specific files stolen from // goinstall. We can't automatically generate goosList and // goarchList if this package is to remain goinstallable. const goosList = "darwin freebsd linux plan9 windows " const goarchList = "386 amd64 arm " // ...
Go
// Types infers source locations and types from Go expressions. // and allows enumeration of the type's method or field members. package types import ( "bytes" "container/list" "fmt" "go/build" "log" "os" "path/filepath" "runtime" "strconv" "strings" "code.google.com/p/rog-go/exp/go/ast" "code.google.com/...
Go
package types import ( "code.google.com/p/rog-go/exp/go/ast" "code.google.com/p/rog-go/exp/go/token" ) func declPos(name string, decl ast.Node) token.Pos { switch d := decl.(type) { case nil: return token.NoPos case *ast.AssignStmt: for _, n := range d.Lhs { if n, ok := n.(*ast.Ident); ok && n.Name == nam...
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 ast declares the types used to represent syntax trees for Go // packages. // package ast import ( "code.google.com/p/rog-go/exp/go/token" "unicode...
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 file contains printing suppport for ASTs. package ast import ( "code.google.com/p/rog-go/exp/go/token" "fmt" "io" "os" "reflect" ) // A FieldFil...
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 implements NewPackage. package ast import ( "code.google.com/p/rog-go/exp/go/scanner" "code.google.com/p/rog-go/exp/go/token" "fmt" "strconv"...
Go