code stringlengths 10 1.34M | language stringclasses 1
value |
|---|---|
// Copyright 2011 The LevelDB-Go 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 crc implements the checksum algorithm used throughout leveldb.
//
// The algorithm is CRC-32 with Castagnoli's polynomial, followed by a bit
... | Go |
// Copyright 2012 The LevelDB-Go 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 leveldb
import (
"encoding/binary"
)
const batchHeaderLen = 12
// Batch is a sequence of Sets and/or Deletes that are applied atomically.
ty... | Go |
// Copyright 2012 The LevelDB-Go 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 leveldb
import (
"bufio"
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"sort"
"code.google.com/p/leveldb-go/leveldb/db"
)
// TODO: de... | Go |
// Copyright 2011 The LevelDB-Go 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 table implements readers and writers of leveldb tables.
Tables are either opened for reading or created for writing but not both.
A reader ... | Go |
// Copyright 2011 The LevelDB-Go 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 table
import (
"bufio"
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"code.google.com/p/leveldb-go/leveldb/crc"
"code.google.com/p/lev... | Go |
// Copyright 2011 The LevelDB-Go 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 table
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"sort"
"code.google.com/p/leveldb-go/leveldb/crc"
"code.google.com/p/leve... | Go |
// Copyright 2012 The LevelDB-Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !linux,!amd64 !darwin,!amd64
package db
import (
"fmt"
"io"
"runtime"
)
func (defFS) Lock(name string) (io.Closer, error) {
return nil,... | Go |
// Copyright 2012 The LevelDB-Go 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 db
import (
"io"
"os"
"syscall"
"unsafe"
)
// lockCloser hides all of an os.File's methods, except for Close.
type lockCloser struct {
f ... | Go |
// Copyright 2011 The LevelDB-Go 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 db defines the interfaces for a key/value store.
//
// A DB's basic operations (Get, Set, Delete) should be self-explanatory. Get
// and Dele... | Go |
// Copyright 2012 The LevelDB-Go 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 db
import (
"io"
"os"
"syscall"
"unsafe"
)
// lockCloser hides all of an os.File's methods, except for Close.
type lockCloser struct {
f ... | Go |
// Copyright 2011 The LevelDB-Go 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 db
// Compression is the per-block compression algorithm to use.
type Compression int
const (
DefaultCompression Compression = iota
NoCompre... | Go |
// Copyright 2012 The LevelDB-Go 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 db
import (
"io"
"os"
)
// File is a readable, writable sequence of bytes.
//
// Typically, it will be an *os.File, but test code may choose... | Go |
// Copyright 2011 The LevelDB-Go 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 db
import (
"bytes"
)
// Comparer defines a total ordering over the space of []byte keys: a 'less
// than' relationship.
type Comparer interf... | Go |
// Copyright 2011 The LevelDB-Go 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 record reads and writes sequences of records. Each record is a stream
// of bytes that completes before the next record starts.
//
// When re... | Go |
// Copyright 2012 The LevelDB-Go 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 leveldb provides an ordered key/value store.
//
// BUG: This package is incomplete.
package leveldb
import (
"bytes"
"fmt"
"io"
"path/fi... | Go |
// Package moderator provides access to the Moderator API.
//
// See http://code.google.com/apis/moderator/v1/using_rest.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/moderator/v1"
// ...
// moderatorService, err := moderator.New(oauthHttpClient)
package moderator
import (
"byte... | Go |
// Package shopping provides access to the Search API for Shopping.
//
// See http://code.google.com/apis/shopping/search/v1/getting_started.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/shopping/v1"
// ...
// shoppingService, err := shopping.New(oauthHttpClient)
package shopping
... | Go |
// Package buzz provides access to the Buzz API.
//
// See http://code.google.com/apis/buzz/v1/using_rest.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/buzz/v1"
// ...
// buzzService, err := buzz.New(oauthHttpClient)
package buzz
import (
"bytes"
"fmt"
"http"
"io"
"json"
"o... | Go |
// Package siteverification provides access to the Google Site Verification API.
//
// See http://code.google.com/apis/siteverification/
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/siteverification/v1"
// ...
// siteverificationService, err := siteverification.New(oauthHttpClient)
pa... | Go |
// Package discovery provides access to the APIs Discovery Service.
//
// See http://code.google.com/apis/discovery
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/discovery/v1"
// ...
// discoveryService, err := discovery.New(oauthHttpClient)
package discovery
import (
"bytes"
"fmt"
... | Go |
// Package analytics provides access to the Google Analytics API.
//
// See http://code.google.com/apis/analytics
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/analytics/v3"
// ...
// analyticsService, err := analytics.New(oauthHttpClient)
package analytics
import (
"bytes"
"fmt"
"... | Go |
// Package analytics provides access to the Google Analytics API.
//
// See http://code.google.com/apis/analytics
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/analytics/v2.4"
// ...
// analyticsService, err := analytics.New(oauthHttpClient)
package analytics
import (
"bytes"
"fmt"
... | Go |
// Package translate provides access to the Translate API.
//
// See http://code.google.com/apis/language/translate/v2/using_rest.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/translate/v2"
// ...
// translateService, err := translate.New(oauthHttpClient)
package translate
import... | Go |
// Package latitude provides access to the Google Latitude API.
//
// See http://code.google.com/apis/latitude/v1/using_rest.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/latitude/v1"
// ...
// latitudeService, err := latitude.New(oauthHttpClient)
package latitude
import (
"byte... | Go |
// Package audit provides access to the Enterprise Audit API.
//
// See http://code.google.com/googleapps/domain/audit_admin/v1/getting_started.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/audit/v1"
// ...
// auditService, err := audit.New(oauthHttpClient)
package audit
import (... | Go |
// Package tasks provides access to the Tasks API.
//
// See http://code.google.com/apis/tasks/v1/using.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/tasks/v1"
// ...
// tasksService, err := tasks.New(oauthHttpClient)
package tasks
import (
"bytes"
"fmt"
"http"
"io"
"json"
... | 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 main
import (
"bytes"
"exec"
"flag"
"fmt"
"go/token"
"go/parser"
"go/printer"
"http"
"io/ioutil"
"json"
"os"
"path/filepath"
"log"
"strings"
... | Go |
// Package taskqueue provides access to the TaskQueue API.
//
// See http://code.google.com/appengine/docs/python/taskqueue/rest.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/taskqueue/v1beta1"
// ...
// taskqueueService, err := taskqueue.New(oauthHttpClient)
package taskqueue
im... | Go |
// Package blogger provides access to the Blogger API.
//
// See https://code.google.com/apis/blogger/docs/2.0/json/getting_started.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/blogger/v2"
// ...
// bloggerService, err := blogger.New(oauthHttpClient)
package blogger
import (
"b... | Go |
// Package urlshortener provides access to the URL Shortener API.
//
// See http://code.google.com/apis/urlshortener/v1/getting_started.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/urlshortener/v1"
// ...
// urlshortenerService, err := urlshortener.New(oauthHttpClient)
package ur... | Go |
// Package pagespeedonline provides access to the Page Speed Online API.
//
// See https://code.google.com/apis/pagespeedonline/v1/getting_started.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/pagespeedonline/v1"
// ...
// pagespeedonlineService, err := pagespeedonline.New(oauthHt... | Go |
// Package books provides access to the Books API.
//
// See https://code.google.com/apis/books/docs/v1/getting_started.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/books/v1"
// ...
// booksService, err := books.New(oauthHttpClient)
package books
import (
"bytes"
"fmt"
"http"... | 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 googleapi contains the common code shared by all Google API
// libraries.
package googleapi
import (
"bytes"
"fmt"
"http"
"io"
"io/ioutil"
"json"
... | Go |
// Package prediction provides access to the Prediction API.
//
// See http://code.google.com/apis/predict/docs/developer-guide.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/prediction/v1.3"
// ...
// predictionService, err := prediction.New(oauthHttpClient)
package prediction
im... | Go |
// Package prediction provides access to the Prediction API.
//
// See http://code.google.com/apis/predict/docs/developer-guide.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/prediction/v1.2"
// ...
// predictionService, err := prediction.New(oauthHttpClient)
package prediction
im... | Go |
// Package orkut provides access to the Orkut API.
//
// See http://code.google.com/apis/orkut/v2/
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/orkut/v2"
// ...
// orkutService, err := orkut.New(oauthHttpClient)
package orkut
import (
"bytes"
"fmt"
"http"
"io"
"json"
"os"
"str... | Go |
package main
import (
"http"
"log"
orkut "google-api-go-client.googlecode.com/hg/orkut/v2"
)
func init() {
registerDemo("orkut", orkut.OrkutScope, orkutMain)
}
func orkutMain(client *http.Client, argv []string) {
orkutapi, _ := orkut.New(client)
myBadges, err := orkutapi.Badges.List("me").Do()
if err != nil ... | Go |
package main
import (
"fmt"
"http"
"os"
"log"
"strings"
urlshortener "google-api-go-client.googlecode.com/hg/urlshortener/v1"
)
func init() {
registerDemo("urlshortener", urlshortener.UrlshortenerScope, urlShortenerMain)
}
func urlShortenerMain(client *http.Client, argv []string) {
if len(argv) != 1 {
fmt... | 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 main
import (
"exec"
"flag"
"fmt"
"gob"
"http"
"http/httptest"
"io/ioutil"
"os"
"path/filepath"
"log"
"runtime"
"strings"
"time"
"url"
"goa... | Go |
package main
import (
"bytes"
"fmt"
"http"
"io"
"io/ioutil"
"os"
)
type logTransport struct {
rt http.RoundTripper
}
func (t *logTransport) RoundTrip(req *http.Request) (*http.Response, os.Error) {
var buf bytes.Buffer
os.Stdout.Write([]byte("\n[request]\n"))
if req.Body != nil {
req.Body = ioutil.NopCl... | Go |
package main
import (
"http"
"log"
tasks "google-api-go-client.googlecode.com/hg/tasks/v1"
)
func init() {
registerDemo("tasks", tasks.TasksScope, tasksMain)
}
func tasksMain(client *http.Client, argv []string) {
taskapi, _ := tasks.New(client)
task, err := taskapi.Tasks.Insert("@default", &tasks.Task{
Titl... | Go |
package main
import (
"flag"
"http"
"os"
"log"
buzz "google-api-go-client.googlecode.com/hg/buzz/v1"
)
func init() {
registerDemo("buzz", buzz.BuzzScope, buzzMain)
}
func buzzMain(client *http.Client, argv []string) {
fs := flag.NewFlagSet("buzz", flag.ExitOnError)
includeMedia := fs.Bool("media", false, "I... | Go |
// Package customsearch provides access to the CustomSearch API.
//
// See http://code.google.com/apis/customsearch/v1/using_rest.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/customsearch/v1"
// ...
// customsearchService, err := customsearch.New(oauthHttpClient)
package customse... | Go |
// Package diacritize provides access to the Diacritize API.
//
// See http://code.google.com/apis/language/diacritize/v1/using_rest.html
//
// Usage example:
//
// import "google-api-go-client.googlecode.com/hg/diacritize/v1"
// ...
// diacritizeService, err := diacritize.New(oauthHttpClient)
package diacritize
... | 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.
// Hello is a trivial example of a main package.
package main
import (
"fmt"
"code.google.com/p/go.example/newmath"
)
func main() {
fmt.Printf("Hello, wo... | 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 newmath is a trivial example package.
package newmath
// Sqrt returns an approximation to the square root of x.
func Sqrt(x float64) float64 {
// ... | 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, row := r... | Go |
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"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 struct {
Height, Width int
}
func (m Image) ColorModel() color.Model {
return color... | 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 |
package main
import "fmt"
func add(x, y int) int {
return x + y
}
func main() {
fmt.Println(add(42, 13))
}
| Go |
package main
import (
"fmt"
"math"
)
type Vertex struct {
X, Y float64
}
func (v *Vertex) Scale(f float64) {
v.X = v.X * f
v.Y = v.Y * f
}
func (v *Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
func main() {
v := &Vertex{3, 4}
v.Scale(5)
fmt.Println(v, v.Abs())
}
| Go |
package main
import "fmt"
func split(sum int) (x, y int) {
x = sum * 4 / 9
y = sum - x
return
}
func main() {
fmt.Println(split(17))
}
| Go |
package main
import (
"fmt"
"math"
)
func pow(x, n, lim float64) float64 {
if v := math.Pow(x, n); v < lim {
return v
}
return lim
}
func main() {
fmt.Println(
pow(3, 2, 10),
pow(3, 3, 20),
)
}
| Go |
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
}
func main() {
s := strings.NewReader(
"Lbh penpxrq gur pbqr!")
r := rot13Reader{s}
io.Copy(os.Stdout, &r)
}
| Go |
package main
import (
"fmt"
"time"
)
type MyError struct {
When time.Time
What string
}
func (e *MyError) Error() string {
return fmt.Sprintf("at %v, %s",
e.When, e.What)
}
func run() error {
return &MyError{
time.Now(),
"it didn't work",
}
}
func main() {
if err := run(); err != nil {
fmt.Println(... | Go |
package main
import (
"fmt"
"math"
)
func sqrt(x float64) string {
if x < 0 {
return sqrt(-x) + "i"
}
return fmt.Sprint(math.Sqrt(x))
}
func main() {
fmt.Println(sqrt(2), sqrt(-4))
}
| Go |
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.pi)
}
| Go |
package main
import (
"fmt"
"time"
)
func say(s string) {
for i := 0; i < 5; i++ {
time.Sleep(100 * time.Millisecond)
fmt.Println(s)
}
}
func main() {
go say("world")
say("hello")
}
| Go |
package main
import (
"fmt"
)
func Sqrt(f float64) (float64, error) {
return 0, nil
}
func main() {
fmt.Println(Sqrt(2))
fmt.Println(Sqrt(-2))
}
| Go |
package main
import (
"fmt"
"math"
)
func main() {
hypot := func(x, y float64) float64 {
return math.Sqrt(x*x + y*y)
}
fmt.Println(hypot(3, 4))
}
| Go |
package main
import (
"code.google.com/p/go-tour/wc"
)
func WordCount(s string) map[string]int {
return map[string]int{"x": 1}
}
func main() {
wc.Test(WordCount)
}
| Go |
package main
import "fmt"
func swap(x, y string) (string, string) {
return y, x
}
func main() {
a, b := swap("hello", "world")
fmt.Println(a, b)
}
| Go |
package main
func main() {
for {
}
}
| Go |
package main
import "fmt"
type Vertex struct {
X, Y int
}
var (
p = Vertex{1, 2} // has type Vertex
q = &Vertex{1, 2} // has type *Vertex
r = Vertex{X: 1} // Y:0 is implicit
s = Vertex{} // X:0 and Y:0
)
func main() {
fmt.Println(p, q, r, s)
}
| Go |
package main
import (
"fmt"
"os"
)
type Reader interface {
Read(b []byte) (n int, err error)
}
type Writer interface {
Write(b []byte) (n int, err error)
}
type ReadWriter interface {
Reader
Writer
}
func main() {
var w Writer
// os.Stdout implements Writer
w = os.Stdout
fmt.Fprintf(w, "hello, writer\n... | Go |
package main
import (
"fmt"
"time"
)
func main() {
tick := time.Tick(1e8)
boom := time.After(5e8)
for {
select {
case <-tick:
fmt.Println("tick.")
case <-boom:
fmt.Println("BOOM!")
return
default:
fmt.Println(" .")
time.Sleep(5e7)
}
}
}
| Go |
package main
import "fmt"
func main() {
c := make(chan int, 2)
c <- 1
c <- 2
fmt.Println(<-c)
fmt.Println(<-c)
}
| Go |
package main
import (
"fmt"
"math"
)
type MyFloat float64
func (f MyFloat) Abs() float64 {
if f < 0 {
return float64(-f)
}
return float64(f)
}
func main() {
f := MyFloat(-math.Sqrt2)
fmt.Println(f.Abs())
}
| Go |
package main
import "fmt"
type Vertex struct {
X int
Y int
}
func main() {
fmt.Println(Vertex{1, 2})
}
| Go |
package main
import "fmt"
type Vertex struct {
X, Y int
}
func main() {
v := new(Vertex)
fmt.Println(v)
v.X, v.Y = 11, 9
fmt.Println(v)
}
| Go |
package main
import "fmt"
func main() {
sum := 1
for ; sum < 1000; {
sum += sum
}
fmt.Println(sum)
}
| Go |
package main
import "fmt"
type Vertex struct {
Lat, Long float64
}
var m = map[string]Vertex{
"Bell Labs": {40.68433, -74.39967},
"Google": {37.42202, -122.08408},
}
func main() {
fmt.Println(m)
}
| Go |
package main
import "fmt"
func main() {
sum := 0
for i := 0; i < 10; i++ {
sum += i
}
fmt.Println(sum)
}
| Go |
package main
import "fmt"
var x, y, z int = 1, 2, 3
var c, python, java = true, false, "no!"
func main() {
fmt.Println(x, y, z, c, python, java)
}
| Go |
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("When's Saturday?")
today := time.Now().Weekday()
switch time.Saturday {
case today + 0:
fmt.Println("Today.")
case today + 1:
fmt.Println("Tomorrow.")
case today + 2:
fmt.Println("In two days.")
default:
fmt.Println("Too far away.")
}
}... | Go |
package main
import "fmt"
var pow = []int{1, 2, 4, 8, 16, 32, 64, 128}
func main() {
for i, v := range pow {
fmt.Printf("2**%d = %d\n", i, v)
}
}
| Go |
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Print("Go runs on ")
switch os := runtime.GOOS; os {
case "darwin":
fmt.Println("OS X.")
case "linux":
fmt.Println("Linux.")
default:
// freebsd, openbsd,
// plan9, windows...
fmt.Printf("%s.", os)
}
}
| Go |
package main
import "fmt"
func Cbrt(x complex128) complex128 {
}
func main() {
fmt.Println(Cbrt(2))
}
| Go |
package main
import "fmt"
func main() {
var x, y, z int = 1, 2, 3
c, python, java := true, false, "no!"
fmt.Println(x, y, z, c, python, java)
}
| Go |
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
}
func main() {
pic.Show(Pic)
}
| Go |
package main
import "fmt"
func adder() func(int) int {
sum := 0
return func(x int) int {
sum += x
return sum
}
}
func main() {
pos, neg := adder(), adder()
for i := 0; i < 10; i++ {
fmt.Println(
pos(i),
neg(-2*i),
)
}
}
| Go |
package main
import (
"fmt"
"math/cmplx"
)
var (
ToBe bool = false
MaxInt uint64 = 1<<64 - 1
z complex128 = cmplx.Sqrt(-5 + 12i)
)
func main() {
const f = "%T(%v)\n"
fmt.Printf(f, ToBe, ToBe)
fmt.Printf(f, MaxInt, MaxInt)
fmt.Printf(f, z, z)
}
| Go |
package main
import "fmt"
type Vertex struct {
X int
Y int
}
func main() {
v := Vertex{1, 2}
v.X = 4
fmt.Println(v.X)
}
| Go |
package main
import "fmt"
func main() {
a := make([]int, 5)
printSlice("a", a)
b := make([]int, 0, 5)
printSlice("b", b)
c := b[:2]
printSlice("c", c)
d := c[2:5]
printSlice("d", d)
}
func printSlice(s string, x []int) {
fmt.Printf("%s len=%d cap=%d %v\n",
s, len(x), cap(x), x)
}
| Go |
package main
import "fmt"
type Vertex struct {
Lat, Long float64
}
var m map[string]Vertex
func main() {
m = make(map[string]Vertex)
m["Bell Labs"] = Vertex{
40.68433, -74.39967,
}
fmt.Println(m["Bell Labs"])
}
| Go |
package main
import "fmt"
func main() {
p := []int{2, 3, 5, 7, 11, 13}
fmt.Println("p ==", p)
for i := 0; i < len(p); i++ {
fmt.Printf("p[%d] == %d\n",
i, p[i])
}
}
| Go |
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Now you have %g problems.",
math.Nextafter(2, 3))
}
| Go |
package main
import "fmt"
func fibonacci(c, quit chan int) {
x, y := 0, 1
for {
select {
case c <- x:
x, y = y, x+y
case <-quit:
fmt.Println("quit")
return
}
}
}
func main() {
c := make(chan int)
quit := make(chan int)
go func() {
for i := 0; i < 10; i++ {
fmt.Println(<-c)
}
quit <- 0... | Go |
package main
import "fmt"
func main() {
sum := 1
for sum < 1000 {
sum += sum
}
fmt.Println(sum)
}
| Go |
package main
import "fmt"
type Vertex struct {
X int
Y int
}
func main() {
p := Vertex{1, 2}
q := &p
q.X = 1e9
fmt.Println(p)
}
| Go |
package main
import "fmt"
func main() {
var z []int
fmt.Println(z, len(z), cap(z))
if z == nil {
fmt.Println("nil!")
}
}
| Go |
package main
import (
"net/http"
)
func main() {
// your http.Handle calls here
http.ListenAndServe("localhost:4000", nil)
}
| Go |
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println("Happy", math.Pi, "Day")
}
| Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.