code stringlengths 10 1.34M | language stringclasses 1
value |
|---|---|
package main
import "fmt"
func add(x int, y int) int {
return x + y
}
func main() {
fmt.Println(add(42, 13))
}
| Go |
package main
import (
"fmt"
)
func Sqrt(x float64) float64 {
}
func main() {
fmt.Println(Sqrt(2))
}
| Go |
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
}
// Crawl uses fetcher to recursively crawl
// pages starting with url, to a maximum of depth.
func Crawl(url string, depth... | Go |
package main
import (
"fmt"
"image"
)
func main() {
m := image.NewRGBA(image.Rect(0, 0, 100, 100))
fmt.Println(m.Bounds())
fmt.Println(m.At(0, 0).RGBA())
}
| Go |
package main
import "fmt"
func main() {
m := make(map[string]int)
m["Answer"] = 42
fmt.Println("The value:", m["Answer"])
m["Answer"] = 48
fmt.Println("The value:", m["Answer"])
delete(m, "Answer")
fmt.Println("The value:", m["Answer"])
v, ok := m["Answer"]
fmt.Println("The value:", v, "Present?", ok)
}
| Go |
package main
import "fmt"
const Pi = 3.14
func main() {
const World = "世界"
fmt.Println("Hello", World)
fmt.Println("Happy", Pi, "Day")
const Truth = true
fmt.Println("Go rules?", Truth)
}
| Go |
package main
import (
"fmt"
"time"
)
func main() {
t := time.Now()
switch {
case t.Hour() < 12:
fmt.Println("Good morning!")
case t.Hour() < 17:
fmt.Println("Good afternoon.")
default:
fmt.Println("Good evening.")
}
}
| Go |
package main
import (
"fmt"
"math"
)
type Vertex struct {
X, Y float64
}
func (v *Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
func main() {
v := &Vertex{3, 4}
fmt.Println(v.Abs())
}
| Go |
package main
import "fmt"
var x, y, z int
var c, python, java bool
func main() {
fmt.Println(x, y, z, c, python, java)
}
| Go |
package main
import "fmt"
const (
Big = 1 << 100
Small = Big >> 99
)
func needInt(x int) int { return x*10 + 1 }
func needFloat(x float64) float64 {
return x * 0.1
}
func main() {
fmt.Println(needInt(Small))
fmt.Println(needFloat(Small))
fmt.Println(needFloat(Big))
}
| Go |
package main
import (
"fmt"
"math"
)
func pow(x, n, lim float64) float64 {
if v := math.Pow(x, n); v < lim {
return v
} else {
fmt.Printf("%g >= %g\n", v, lim)
}
// can't use v here, though
return lim
}
func main() {
fmt.Println(
pow(3, 2, 10),
pow(3, 3, 20),
)
}
| Go |
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
}
func main() {
f := fibonacci()
for i := 0; i < 10; i++ {
fmt.Println(f())
}
}
| Go |
package main
import (
"fmt"
)
func fibonacci(n int, c chan int) {
x, y := 0, 1
for i := 0; i < n; i++ {
c <- x
x, y = y, x+y
}
close(c)
}
func main() {
c := make(chan int, 10)
go fibonacci(cap(c), c)
for i := range c {
fmt.Println(i)
}
}
| Go |
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
| Go |
package main
import (
"fmt"
"math"
)
type Abser interface {
Abs() float64
}
func main() {
var a Abser
f := MyFloat(-math.Sqrt2)
v := Vertex{3, 4}
a = f // a MyFloat implements Abser
a = &v // a *Vertex implements Abser
a = v // a Vertex, does NOT
// implement Abser
fmt.Println(a.Abs())
}
type MyFloat... | Go |
package main
import "fmt"
type Vertex struct {
Lat, Long float64
}
var m = map[string]Vertex{
"Bell Labs": Vertex{
40.68433, -74.39967,
},
"Google": Vertex{
37.42202, -122.08408,
},
}
func main() {
fmt.Println(m)
}
| Go |
package main
import "code.google.com/p/go-tour/tree"
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int)
// Same determines whether the trees
// t1 and t2 contain the same values.
func Same(t1, t2 *tree.Tree) bool
func main() {
}
| Go |
package main
import "fmt"
func main() {
pow := make([]int, 10)
for i := range pow {
pow[i] = 1 << uint(i)
}
for _, value := range pow {
fmt.Printf("%d\n", value)
}
}
| Go |
package main
import "fmt"
func sum(a []int, c chan int) {
sum := 0
for _, v := range a {
sum += v
}
c <- sum // send sum to c
}
func main() {
a := []int{7, 2, 8, -9, 4, 0}
c := make(chan int)
go sum(a[:len(a)/2], c)
go sum(a[len(a)/2:], c)
x, y := <-c, <-c // receive from c
fmt.Println(x, y, x+y)
}
| Go |
package main
import "fmt"
func main() {
p := []int{2, 3, 5, 7, 11, 13}
fmt.Println("p ==", p)
fmt.Println("p[1:4] ==", p[1:4])
// missing low index implies 0
fmt.Println("p[:3] ==", p[:3])
// missing high index implies len(s)
fmt.Println("p[4:] ==", p[4:])
}
| Go |
package main
import (
"fmt"
"net/http"
)
type Hello struct{}
func (h Hello) ServeHTTP(
w http.ResponseWriter,
r *http.Request) {
fmt.Fprint(w, "Hello!")
}
func main() {
var h Hello
http.ListenAndServe("localhost:4000", h)
}
| Go |
package main
import (
"code.google.com/p/go-tour/pic"
"image"
)
type Image struct{}
func main() {
m := Image{}
pic.ShowImage(m)
}
| Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package wc
import "fmt"
// Test runs a test suite against f.
func Test(f func(string) map[string]int) {
ok := true
for _, c := range testCases {
got := 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 tree
import (
"fmt"
"math/rand"
)
// A Tree is a binary tree with integer values.
type Tree struct {
Left *Tree
Value int
Right *Tree
}
// New... | Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package pic
import (
"bytes"
"encoding/base64"
"fmt"
"image"
"image/png"
)
func Show(f func(int, int) [][]uint8) {
const (
dx = 256
dy = 256
)
da... | 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 (
"bytes"
"encoding/json"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"net/http"
)
func init() {
http.HandleFunc("/fmt", fmtHand... | Go |
// Copyright 2013 The Go 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"
"fmt"
"html/template"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"time"
"code.google.com/p/go.talks/pkg/present... | Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !appengine
package main
import (
"flag"
"fmt"
"go/build"
"io"
"log"
"net"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"... | Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build appengine
package main
import (
"bufio"
"bytes"
"io"
"net/http"
"appengine"
_ "code.google.com/p/go.talks/pkg/playground"
)
const runUrl =... | Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uuid
import (
"encoding/binary"
"time"
)
// A Time represents a time as the number of 100's of nanoseconds since 15 Oct
// 1582.
type Time int64
const... | Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uuid
import (
"io"
)
// randomBits completely fills slice b with random data.
func randomBits(b []byte) {
if _, err := io.ReadFull(rander, b); err != n... | Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uuid
import (
"bytes"
"crypto/rand"
"fmt"
"io"
"strings"
)
// A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC
// 4122.
t... | Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uuid
import (
"crypto/md5"
"crypto/sha1"
"hash"
)
// Well known Name Space IDs and UUIDs
var (
NameSpace_DNS = Parse("6ba7b810-9dad-11d1-80b4-00c04f... | Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uuid
import (
"encoding/binary"
"fmt"
"os"
)
// A Domain represents a Version 2 domain
type Domain byte
// Domain constants for DCE Security (Version... | Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uuid
// Random returns a Random (Version 4) UUID or panics.
//
// The strength of the UUIDs is based on the strength of the crypto/rand
// package.
//
// ... | Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uuid
import "net"
var (
interfaces []net.Interface // cached list of interfaces
ifname string // name of interface being used
nodeID ... | Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// The uuid package generates and inspects UUIDs.
//
// UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security Services.
package uuid
| Go |
// Copyright 2011 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uuid
import (
"encoding/binary"
)
// NewUUID returns a Version 1 UUID based on the current NodeID and clock
// sequence, and the current time. If the N... | 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 regexp implements regular expression search tuned for
// use in grep-like programs.
package regexp
import "regexp/syntax"
func bug() {
panic("cod... | 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 regexp
import (
"regexp/syntax"
"unicode"
"unicode/utf8"
)
const (
instFail = syntax.InstFail
instAlt = syntax.InstAlt
instByteRange... | 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 regexp
import (
"bytes"
"encoding/binary"
"flag"
"fmt"
"io"
"os"
"regexp/syntax"
"sort"
"code.google.com/p/codesearch/sparse"
)
// A matche... | 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.
// Copied from Go's regexp/syntax.
// Formatters edited to handle instByteRange.
package regexp
import (
"bytes"
"fmt"
"regexp/syntax"
"sort"
"strconv"
... | 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 index
import (
"regexp/syntax"
"sort"
"strconv"
"strings"
"unicode"
)
// A Query is a matching machine, like a regular expression,
// that match... | 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 index
import (
"log"
"os"
"syscall"
)
func mmapFile(f *os.File) mmapData {
st, err := f.Stat()
if err != nil {
log.Fatal(err)
}
size := st.S... | 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 index
import (
"io"
"io/ioutil"
"log"
"os"
"strings"
"unsafe"
"code.google.com/p/codesearch/sparse"
)
// Index writing. See read.go for deta... | 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 index
import (
"log"
"os"
"syscall"
"unsafe"
)
func mmapFile(f *os.File) mmapData {
st, err := f.Stat()
if err != nil {
log.Fatal(err)
}
si... | 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 index
// Merging indexes.
//
// To merge two indexes A and B (newer) into a combined index C:
//
// Load the path list from B and determine for each 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.
package index
// Index format.
//
// An index stored on disk has the format:
//
// "csearch index 1\n"
// list of paths
// list of names
// list of posting li... | Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin freebsd openbsd netbsd
package index
import (
"log"
"os"
"syscall"
)
// missing from package syscall on freebsd, openbsd
const (
_PROT_... | 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 sparse implements sparse sets.
package sparse
// For comparison: running cindex over the Linux 2.6 kernel with this
// implementation of trigram se... | 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"
"log"
"os"
"runtime/pprof"
"code.google.com/p/codesearch/index"
"code.google.com/p/codesearch/regexp"
)
var usageM... | 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"
"log"
"os"
"path/filepath"
"runtime/pprof"
"sort"
"code.google.com/p/codesearch/index"
)
var usageMessage = `usag... | 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"
"log"
"os"
"runtime/pprof"
"code.google.com/p/codesearch/regexp"
)
var usageMessage = `usage: cgrep [-c] [-h] [-i] ... | 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 wc
import "fmt"
// Test runs a test suite against f.
func Test(f func(string) map[string]int) {
ok := true
for _, c := range testCases {
got := 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 goplay
import (
"bytes"
"encoding/json"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"net/http"
)
func init() {
http.HandleFunc("/fmt", fmtHa... | 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 goplay
import (
"fmt"
"io"
"net/http"
"appengine"
"appengine/urlfetch"
)
const runUrl = "http://golang.org/compile?output=json"
func init() {
... | 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 tree
import (
"fmt"
"math/rand"
)
// A Tree is a binary tree with integer values.
type Tree struct {
Left *Tree
Value int
Right *Tree
}
// New... | Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package pic
import (
"bytes"
"encoding/base64"
"fmt"
"image"
"image/png"
)
func Show(f func(int, int) [][]uint8) {
const (
dx = 256
dy = 256
)
da... | 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"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprintf("Sqrt: negative number %g"... | 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"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
f, g := 0, 1
return func... | 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"
"tour/tree"
)
func walkImpl(t *tree.Tree, ch chan int) {
if t.Left != nil {
walkImpl(t.Left, ch)
}
ch <- t.Value
if t.Rig... | 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 (
"strings"
"tour/wc"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
for _, f := range strings.Fields(s) {
m... | 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 "tour/pic"
func Pic(dx, dy int) [][]uint8 {
p := make([][]uint8, dy)
for i := range p {
p[i] = make([]uint8, dx)
}
for y := range ... | 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"
"os"
"strings"
)
func rot13(b byte) byte {
var a, z byte
switch {
case 'a' <= b && b <= 'z':
a, z = 'a', 'z'
case 'A' <= ... | 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/cmplx"
)
const delta = 1e-10
func Cbrt(x complex128) complex128 {
z := x
for {
n := z - (z*z*z-x)/(3*z*z)
if cmplx... | 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 (
"errors"
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetc... | 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 (
"image"
"image/color"
"tour/pic"
)
type Image [][]uint8
func (m Image) ColorModel() color.Model {
return color.RGBAModel
}
func (... | 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"
)
const delta = 1e-10
func Sqrt(x float64) float64 {
z := x
for {
n := z - (z*z-x)/(2*z)
if math.Abs(n-z) < delta... | 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 (
"bytes"
"encoding/json"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"net/http"
)
func init() {
http.HandleFunc("/fmt", fmtHand... | 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/build"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
"... | 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 (
"encoding/json"
"log"
"net/http"
)
func init() {
http.HandleFunc("/compile", Compile)
}
type Response struct {
Output string `jso... | Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin freebsd linux netbsd openbsd
package time
import (
"errors"
"syscall"
)
// for testing: whatever interrupts a sleep
func interrupt() {
sy... | 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.
// +build helenos
package time
import (
"errors"
"runtime"
)
func initLocal() {
// TODO: Implement this once HelenOS supports timezones.
// Fall back to ... | 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 time
import (
"errors"
"syscall"
)
// for testing: whatever interrupts a sleep
func interrupt() {
}
// readFile reads and returns the content of th... | 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 time provides functionality for measuring and displaying time.
//
// The calendrical calculations always assume a Gregorian calendar.
package time
i... | Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build plan9
package time
import (
"errors"
"syscall"
)
// for testing: whatever interrupts a sleep
func interrupt() {
// cannot predict pid, don't wan... | 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 time
import "errors"
// A Ticker holds a synchronous channel that delivers `ticks' of a clock
// at intervals.
type Ticker struct {
C <-chan Time // ... | 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 time
import (
"sync"
)
// A Location maps time instants to the zone in use at that time.
// Typically, the Location represents the collection of time... | 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.
// Parse Plan 9 timezone(2) files.
package time
import (
"errors"
"runtime"
"syscall"
)
func isSpace(r rune) bool {
return r == ' ' || r == '\t' || 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.
// Parse "zoneinfo" time zone file.
// This is a fairly standard file format used on OS X, Linux, BSD, Sun, and others.
// See tzfile(5), http://en.wikipedia.or... | 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 time
import "errors"
// These are predefined layouts for use in Time.Format.
// The standard time used in the layouts is:
// Mon Jan 2 15:04:05 MST 20... | Go |
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build helenos
package time
import (
"errors"
"syscall"
)
// readFile reads and returns the content of the named file.
// It is a trivial implementation... | 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.
// +build darwin freebsd linux netbsd openbsd
// Parse "zoneinfo" time zone file.
// This is a fairly standard file format used on OS X, Linux, BSD, Sun, and o... | 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 time
// Sleep pauses the current goroutine for the duration d.
func Sleep(d Duration)
func nano() int64 {
sec, nsec := now()
return sec*1e9 + int64(... | 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 time
import (
"errors"
"runtime"
"syscall"
)
// TODO(rsc): Fall back to copy of zoneinfo files.
// BUG(brainman,rsc): On Windows, the operating sy... | 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 io
type multiReader struct {
readers []Reader
}
func (mr *multiReader) Read(p []byte) (n int, err error) {
for len(mr.readers) > 0 {
n, err = mr.r... | 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 ioutil
import (
"os"
"path/filepath"
"strconv"
"time"
)
// Random number state, accessed without lock; racy but harmless.
// We generate random 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.
// Package ioutil implements some I/O utility functions.
package ioutil
import (
"bytes"
"io"
"os"
"sort"
)
// readAll reads from r until an error or EOF ... | 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 io provides basic interfaces to I/O primitives.
// Its primary job is to wrap existing implementations of such primitives,
// such as those in 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.
// Pipe adapter to connect code expecting an io.Reader
// with code expecting an io.Writer.
package io
import (
"errors"
"sync"
)
// ErrClosedPipe is the 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.
package syscall
func itoa(val int) string { // do it here rather than with fmt to avoid dependency
if val < 0 {
return "-" + itoa(-val)
}
var buf [32]byte... | Go |
package syscall
import (
"unsafe"
"sync"
)
var (
lock sync.Mutex
objects map[unsafe.Pointer]int
)
func init() {
objects = make(map[unsafe.Pointer]int)
}
func LockObject(ptr unsafe.Pointer) {
lock.Lock()
defer lock.Unlock()
objects[ptr] = 1;
}
func UnlockObject(ptr unsafe.Pointer) {
lock.Lock()
defer loc... | 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 syscall
// An Errno is a signed number describing an error condition.
// It implements the error interface. The zero Errno is by convention
// a non-e... | Go |
package event
import (
"syscall"
)
type Type int
type TaskType int
const (
KLOG = Type(iota)
KCONSOLE
FAULT
FIRST_NONGLOBAL
)
const (
TASK_STATE_CHANGE = TaskType(FIRST_NONGLOBAL + iota)
)
//extern event_subscribe
func event_subscribe(event_type Type, method syscall.Arg) int
//extern event_task_subscribe
... | Go |
package syscall
const (
EOK = Errno(0)
ENOENT = Errno(_ENOENT)
ENOMEM = Errno(_ENOMEM)
ELIMIT = Errno(_ELIMIT)
EREFUSED = Errno(_EREFUSED)
EFORWARD = Errno(_EFORWARD)
EPERM = Errno(_EPERM)
EHANGUP = Errno(_EHANGUP)
EPARTY = Errno(_EPARTY)
EEXISTS = Errno(_EEXISTS)
EBADMEM = Errno(_EBADMEM)
ENOTSUP = Errno... | Go |
// A direct port of libc's ns.c file.
package service
import (
"syscall"
"syscall/async"
)
func ConvertID(s string) (result uint32) {
bytes := [4]byte{ ' ', ' ', ' ', ' ' }
switch len(s) {
default:
panic("Invalid input to service.ConvertID()")
case 4:
bytes[3] = byte(s[3])
fallthrough
case 3:
bytes[2... | Go |
package service
import (
"syscall/async"
"unsafe"
"runtime"
)
var (
session *async.Session
)
//extern go_syscall_service_ns_session
func libcSession() unsafe.Pointer
func nsSession() *async.Session {
if session == nil {
session = async.WrapSession(libcSession())
runtime.SetFinalizer(session, nil)
}
ret... | 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.
// Declarations for functions which are actually written in C.
package syscall
func GetErrno() Errno
func SetErrno(Errno)
// These functions are used by CGO ... | 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 syscall contains an interface to the low-level operating system
// primitives. The details vary depending on the underlying system.
// Its primary u... | Go |
package async
import (
"syscall"
"syscall/fibril"
"unsafe"
"runtime"
)
// FIXME: Make sure all Go memory passed to C code is referenced somewhere.
type Call struct {
id syscall.IpcCallidT
data callData
}
func (c *Call) Arg(n int) syscall.Arg {
return c.data.args[n]
}
func (c *Call) Method() syscall.Arg {
... | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.