code stringlengths 10 1.34M | language stringclasses 1
value |
|---|---|
// Copyright 2012, 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.
// vt binlog server: Serves binlog for out of band replication.
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"io"
_ "net/http/pprof"
"os"
"os/signal... | Go |
// Copyright 2012, 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 (
"flag"
"fmt"
_ "net/http/pprof"
"os"
"code.google.com/p/vitess/go/relog"
rpc "code.google.com/p/vitess/go/rpcplus"
"code.google.com/... | Go |
// Copyright 2013, 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
// Imports and register the Zookeeper TopologyServer
import (
_ "code.google.com/p/vitess/go/vt/zktopo"
)
| Go |
// Copyright 2012, 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 (
"expvar"
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"code.google.com/p/vitess/go/jscfg"
"code.google.com/p/vitess/go/relog"
r... | Go |
// Copyright 2012, 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.
/*
This packages contains a few utility functions for network related functions.
*/
package netutil
import (
"fmt"
"math/rand"
"net"
"os"
"sort"
"strconv"
... | Go |
// Copyright 2012, 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 pools
import (
"fmt"
"sync"
"time"
)
// RoundRobin is deprecated. Use ResourcePool instead.
// RoundRobin allows you to use a pool of resources in a r... | Go |
// Copyright 2012, 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 pools provides functionality to manage and reuse resources
// like connections.
package pools
import (
"fmt"
"time"
"code.google.com/p/vitess/go/sy... | Go |
// Copyright 2012, 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 pools
import (
"errors"
"fmt"
"sync"
"time"
)
// Numbered allows you to manage resources by tracking them with numbers.
// There are no interface res... | Go |
// Copyright 2013, 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 sync2
import (
"sync"
)
// Cond is an alternate implementation of sync.Cond
type Cond struct {
L sync.Locker
sema chan struct{}
waiters Atom... | Go |
package sync2
// What's in a name? Channels have all you need to emulate a counting
// semaphore with a boatload of extra functionality. However, in some
// cases, you just want a familiar API.
//
// Additionally there is great debate on how to do this correctly:
//
// https://groups.google.com/forum/#!msg/golang-dev/... | Go |
// Copyright 2013, 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 sync2
import (
"sync/atomic"
"time"
)
type AtomicInt32 int32
func (i *AtomicInt32) Add(n int32) int32 {
return atomic.AddInt32((*int32)(i), n)
}
fun... | Go |
// Copyright 2012, 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 sqltypes implements interfaces and types that represent SQL values.
package sqltypes
import (
"encoding/base64"
"encoding/gob"
"encoding/json"
"fmt... | Go |
package main
import (
"code.google.com/p/vitess/go/umgmt"
"flag"
)
var sockPath = flag.String("sock-path", "", "")
func main() {
flag.Parse()
println("sock path: ", *sockPath)
uc, err := umgmt.Dial(*sockPath)
if err != nil {
panic(err)
}
msg, err := uc.Ping()
if err != nil {
panic(err)
}
println("msg:... | Go |
// Copyright 2012, 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 umgmt
import (
"io"
"net"
"net/rpc"
"code.google.com/p/vitess/go/relog"
)
type Client struct {
*rpc.Client
conn io.ReadWriteCloser
}
func Dial(ad... | Go |
// Copyright 2012, 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 umgmt
import (
"fmt"
"net"
"os"
"syscall"
)
func SendFd(conn *net.UnixConn, file *os.File) error {
rights := syscall.UnixRights(int(file.Fd()))
dum... | Go |
// Copyright 2012, 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 micromanagment module provides a tiny server running on a unix
// domain socket.
//
// It is meant as an alternative to signals for handling graceful
// ser... | Go |
// Copyright 2012, 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 umgmt
import (
"crypto/tls"
"crypto/x509"
"expvar"
"net"
"net/http"
"os"
"strings"
"sync"
"code.google.com/p/vitess/go/relog"
)
var connectionC... | Go |
// Copyright 2012, 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 jscfg
// A few simple macros for keeping JSON config files human readable
// and consistent.
import (
"encoding/json"
"fmt"
"io/ioutil"
"code.google... | Go |
package streamlog
import (
"expvar"
"io"
"net/http"
"net/url"
"sync"
"code.google.com/p/vitess/go/relog"
"code.google.com/p/vitess/go/sync2"
)
var droppedMessages = expvar.NewMap("streamlog-dropped-messages")
// A StreamLogger makes messages sent to it available through HTTP.
type StreamLogger struct {
data... | Go |
// Copyright 2012, 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 db defines an alternate (and simplified)
// db api compared to go's database/sql.
package db
import (
"fmt"
)
// Driver is the interface that must b... | Go |
// Copyright 2012, 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 bytes2 gives you alternate implementations of functionality
// similar to go's bytes package
package bytes2
import (
"code.google.com/p/vitess/go/hac... | Go |
// Copyright 2012, 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.
// Utility functions for custom encoders
package bson
import (
"code.google.com/p/vitess/go/bytes2"
)
func EncodeStringArray(buf *bytes2.ChunkedWriter, name st... | Go |
// Copyright 2012, 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 bson
import (
"io"
"math"
"reflect"
"strconv"
"time"
"code.google.com/p/vitess/go/bytes2"
)
var (
TimeType = reflect.TypeOf(time.Time{})
BytesT... | Go |
// Copyright 2012, 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.
// Utility functions for custom decoders
package bson
import (
"bytes"
"math"
"strconv"
"time"
"code.google.com/p/vitess/go/hack"
)
var (
emptybytes = []... | Go |
// Copyright 2012, 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 bson
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"math"
"reflect"
"strconv"
"time"
)
// BSON documents are lttle endian
var Pack = b... | Go |
// Copyright 2012, 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 logfile
import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"sync"
"time"
)
type Logfile struct {
mu sync.Mutex
handle *os.File
curName strin... | 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 bufio implements buffered I/O. It wraps an io.Reader or io.Writer
// object, creating another object (Reader or AsyncWriter) that also implements
//... | Go |
// Copyright 2012, 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 (
"flag"
"fmt"
"math/rand"
"os"
"sync"
"time"
"code.google.com/p/vitess/go/vt/client2/tablet"
)
func main() {
goroutines := flag.Int... | Go |
package main
type Version struct {
value []int
} | Go |
package main
import "fmt"
type PackageVersion struct {
Package string
Version Version
}
func (p PackageVersion) String() string {
return fmt.Sprintf("%v %v", p.Package, p.Version)
}
| Go |
package main
import (
"fmt"
)
// main entry point
func main() {
packages := make([]*Package, 0, 100)
packageVersions := make([]*PackageVersion, 0, 100)
p := new(Package)
p.title = "Test package"
p.name = "test"
packages = append(packages, p)
pv := new(PackageVersion)
pv.Package = p.name
... | Go |
package main
// a package like "Go Lite IDE"
type Package struct {
name string
title string
}
func (p Package) String() string {
return p.title + " (" + p.name + ")"
}
| 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 2012 The golibpcap 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 pcap package provides support for using the C pcap library from within a
// Go program. Not... | Go |
// Copyright 2012 The golibpcap 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 pkt
/*
#include <netinet/ip.h>
#include <netinet/in.h>
*/
import "C"
import (
"fmt"
"net"
... | Go |
// Copyright 2012 The golibpcap 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 pkt
/*
#include <netinet/in.h>
#include <netinet/tcp.h>
*/
import "C"
import (
"fmt"
"refl... | Go |
// Copyright 2012 The golibpcap 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 pkt package provides access to the packet internals.
//
package pkt
/... | Go |
// Copyright 2012 The golibpcap 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 pkt
import (
"fmt"
"strconv"
"strings"
)
// The point of a HttpHdr is to ease the mappin... | Go |
// Copyright 2012 The golibpcap 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 pkt
/*
#include <net/ethernet.h>
#include <netinet/ether.h>
#include <netinet/in.h>
*/
impor... | Go |
// Copyright 2012 The golibpcap 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 pkt
/*
#include <netinet/ip6.h>
*/
import "C"
import (
"f... | Go |
// Copyright 2012 The golibpcap 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 serves as an example of how to use of the Loop method for tracing a
// network interface. Basically it is a very limited tcpdump.
//
// Example ... | Go |
// Copyright (c) Google Inc. All Rights Reserved.
// Author: Andrew Gerrand (adg@google.com)
package timer
import (
"bytes"
"fmt"
"time"
)
type Timer struct {
start time.Time
point []time.Duration
label []string
}
func New() *Timer {
return &Timer{start: time.Now()}
}
// Point adds a opint to the Timer, ass... | Go |
// Copyright (c) Google Inc. All Rights Reserved.
// Author: Chris Broadfoot (cbro@google.com)
package overlaytiler
import (
"errors"
"fmt"
"image"
"io"
"math"
"net/http"
"strconv"
"strings"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"appengine"
"appengine/blobstore"
"appengine/datastore"
"appengine/... | Go |
// Copyright (c) Google Inc. All Rights Reserved.
// Author: Chris Broadfoot (cbro@google.com)
package overlaytiler
import (
"fmt"
"appengine"
"appengine/datastore"
)
const (
tilesPerZoom = 1000 // limit to prevent DoS
sliceQueue = "slice"
tileQueue = "tile"
zipQueue = "zip"
sendQueue = "send"
sliceB... | Go |
// Copyright (c) Google Inc. All Rights Reserved.
// Author: Chris Broadfoot (cbro@google.com)
// Author: Andrew Gerrand (adg@google.com)
package overlaytiler
import (
"archive/zip"
"bytes"
"encoding/json"
"fmt"
"html/template"
"image"
"image/png"
"math"
"net/http"
"net/url"
"time"
"appengine"
"appengin... | Go |
// Copyright (c) Google Inc. All Rights Reserved.
// Author: Chris Broadfoot (cbro@google.com)
// Author: Andrew Gerrand (adg@google.com)
package overlaytiler
import (
"encoding/json"
"fmt"
"html/template"
"net/http"
"net/url"
"appengine"
"appengine/blobstore"
"appengine/channel"
"appengine/datastore"
"app... | Go |
/*
* jQuery File Upload Plugin GAE Go Example 3.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
package app
import (
"appengine"
"appengine/blobstore"
"appengine/ima... | Go |
package bit
import (
"math/big"
)
// A bit array.
type Array struct {
*big.Int
}
// NewArray allocates and returns a new Bits set to x.
func NewArray(x int64) *Array {
return &Array{big.NewInt(x)}
}
// Count counts the number of set bits in b.
func (b *Array) Count() (c int) {
for _, v := range b.Bits() {
c +... | Go |
package algogo
// Factorial returns n!.
func Factorial(n int) (f int) {
if n <= 1 {
return 1
}
f = 1
for i := n; i > 1; i-- {
f *= i
}
return
}
// Permutations returns the number of k-permutations of n.
func Permutations(n, k int) (p int) {
if k > n {
return 0
}
p = 1
m := n - k
for i := n; i > m; i-... | Go |
package algogo
// Reverse reverses the elements of array a
func Reverse(a []int) {
last := len(a)
mid := last / 2
last--
for i := 0; i < mid; i++ {
j := last - i
a[i], a[j] = a[j], a[i]
}
}
// Reversed returns a reversed copy of array a
func Reversed(a []int) []int {
b := Copied(a)
Reverse(b)
return b
}
... | Go |
package unionfind
// UnionFind implementing quick-union and find with path compression.
// NB New sets are created for each union
// TODO Keep track of cluster sizes and use union-by-rank?
type UnionFind struct {
// parent index array
Parent []int
// index for new set
newIndex int
}
func NewUnionFind(n int) *Un... | Go |
package algogo
// Modify array in and out to generate the next
// k-combination of the n total elements of in and out.
// Arrays in and out must be sorted in ascending order.
// k elements are chosen from arrays in and out and placed in array in
// array in constitutes the chosen elements; out consitutes the remaining... | Go |
package algogo
// NextPermutation modifies array a in place to the next permutation that is
// lexicographically greater.
// It returns false when the permutation is at the lexicographical minimum
// (i.e. sorted in nondecreasing order).
// It returns false no permutation is possible.
// It returns true otherwise.
// ... | Go |
package main
import (
"flag"
"fmt"
"os"
)
func main() {
} | Go |
// Copyright 2010 Abiola Ibrahim <abiola89@gmail.com>. All rights reserved.
// Use of this source code is governed by New BSD License
// http://www.opensource.org/licenses/bsd-license.php
// The content and logo is governed by Creative Commons Attribution 3.0
// The mascott is a property of Go governed by Creative Comm... | Go |
// Copyright 2010 Abiola Ibrahim <abiola89@gmail.com>. All rights reserved.
// Use of this source code is governed by New BSD License
// http://www.opensource.org/licenses/bsd-license.php
// The content and logo is governed by Creative Commons Attribution 3.0
// The mascott is a property of Go governed by Creative Comm... | Go |
// -*- tab-width: 4 -*-
package couch
import (
"bytes"
"errors"
"fmt"
"http"
"io/ioutil"
"json"
"net"
"net/http/httputil"
"url"
)
var def_hdrs = map[string][]string{}
type buffer struct {
b *bytes.Buffer
}
func (b *buffer) Read(out []byte) (int, error) {
return b.b.Read(out)
}
func (b *buffer) Close() e... | Go |
// Hello package
package hellopkg
// Say Hi function
func SayHi() string {
return "Hi"
}
| Go |
// Hello command
package main
import (
"alvaro/hellopkg"
"fmt"
)
// Main function for the hello command
func main() {
fmt.Println(hellopkg.SayHi())
}
| 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 (
"encoding/json"
"go/format"
"net/http"
"code.google.com/p/go.tools/imports"
)
func init() {
http.HandleFunc("/fmt", fmtHandler)... | 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 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 goplay
import (
"io"
"net/http"
"code.google.com/p/go.tools/godoc/static"
)
func init() {
http.HandleFunc("/playground.js", play)
}
func play(w... | 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 (
"appengine"
"appengine/datastore"
"bytes"
"crypto/sha1"
"encoding/base64"
"fmt"
"io"
"net/http"
)
const salt = "[replace this... | 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 (
"html/template"
"net/http"
"strings"
"appengine"
"appengine/datastore"
)
const hostname = "play.golang.org"
func init() {
htt... | Go |
package main
import (
"./dep"
)
func main() {
dep.Meh()
}
| Go |
package dep
type bleh struct {
hi int
}
func (me bleh) meh() string {
if me == (bleh{}) {
return "0"
}
return "1"
}
func Meh() {
(bleh{}).meh()
}
| Go |
package main
//import "flag"
import "fmt"
import "math"
import "os"
import "runtime"
import "strconv"
type prime uint
func generate(out chan prime) {
out <- 2
out <- 3
for i := 6; ; i += 6 {
out <- prime(i - 1)
out <- prime(i + 1)
}
}
func filter(in, out chan prime, n prime) {
va... | Go |
package main
import "flag"
import "fmt"
import "os"
import "strconv"
func main() {
flag.Parse()
if flag.NArg() != 1 {
os.Exit(2)
}
count, err := strconv.Atoi(flag.Arg(0))
if err != nil {
os.Exit(2)
}
fmt.Println(fib(uint64(count)))
}
func fib(n uint64) []uint64 {
retval := make([]uint64, n)
var a, b uin... | Go |
package main
import (
"url"
"strconv"
"http"
"io/ioutil"
"os"
)
const (
noneEvent = 0
completedEvent = 1
startedEvent = 2
stoppedEvent = 3
)
type Tracker interface {
Announce(Torrent) ([]string, int, os.Error)
}
type udpTracker struct {
host string
path string
}
func... | Go |
package main
import (
"flag"
"os"
"bencode"
"log"
)
const block_size = 1 << 14
func newTorrent(metainfo bencode.Dict) *Torrent {
t := &Torrent{Metainfo: metainfo}
t.numberOfPieces = uint(len(t.Metainfo["info"].(bencode.Dict)["pieces"].(string)) / 20)
url :=
t.trackers = append(t.track... | Go |
package main
| Go |
package bencode
import (
"io"
"os"
"strconv"
)
var e = new(interface{})
type List []interface{}
type Dict map[string]interface{}
func Decode(r io.Reader) (interface{}, os.Error) {
var t [1]byte
n, err := r.Read(t[:])
if n != 1 {
return nil, err
}
switch c := t[0]; {
case c... | Go |
package main
import (
"bencode"
"flag"
"strconv"
"os"
"fmt"
)
func main() {
flag.Parse()
val, err := bencode.Decode(os.Stdin)
if err != nil {
panic(err)
}
for _, arg := range flag.Args() {
fmt.Println(arg)
switch val.(type) {
case bencode.List:
... | Go |
package main
import fmt "fmt"
func main() {
fmt.Printf("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界\n")
}
| Go |
package main
import "sync"
type Manager struct {
lock sync.Mutex
running uint
waiting uint
wakeup chan bool
}
func (m *Manager) Go(fn func()) {
m.lock.Lock()
m.running++
m.lock.Unlock()
go func() {
fn()
defer func() {
m.lock.Lock()
m.running--
if m.running == 0 && m.waiting > 0 {
for ; m... | Go |
package main
import (
"crypto/md5"
"flag"
"fmt"
"path"
"os"
"runtime"
"runtime/pprof"
)
func abspath(p string) string {
base, _ := os.Getwd()
return path.Clean(path.Join(base, p))
}
type Walker struct {
paths chan<- string
visited map[string]bool
}
func (me Walker) VisitDir(path string, f *os.FileInfo)... | Go |
package main
import (
"io"
"os"
)
type Data interface {}
func Decode(r io.Reader) (out chan Data) {
out = make(chan Data)
go func() {
for {
var c [1]byte
n, _ := r.Read(c[:])
if n == 0 {
return
}
switch c[0] {
... | Go |
package main
//import "flag"
import "fmt"
//import "math"
import "os"
import "runtime"
import "strconv"
type prime uint
func generate(out chan prime) {
for i := prime(2); ; i++ {
out <- i
}
}
func filter(in, out chan prime, q prime) {
for {
p := <-in
if p % q != 0 {
o... | Go |
package main
//import "flag"
import "fmt"
import "math"
import "os"
import "runtime"
import "strconv"
type prime uint
//const bufsize = 1000
func primes(n prime) {
var primes []prime
for p := prime(2); p <= n; p++ {
s := prime(math.Sqrt(float64(p)))
isprime := true
for _, q := range ... | Go |
package main
import (
"http"
"io/ioutil"
"regexp"
"url"
"strconv"
)
var langre = regexp.MustCompile("/languages/([^/\"]+)")
func languages() (langs []string) {
resp, err := http.Get("http://github.com/languages")
if err != nil {
panic(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
... | Go |
// The ncrpc package layers client-server and server-client
// RPC interfaces on top of netchan.
package ncrpc
import (
"code.google.com/p/rog-go/ncnet"
"errors"
"fmt"
"io"
"log"
"net"
"net/rpc"
"netchan"
"sync"
)
type Server struct {
Exporter *netchan.Exporter
RPCServer *rpc.Server
mu sync.Mutex
... | Go |
package values
import (
"errors"
"fmt"
)
// Float64ToString returns a Lens which transforms from float64
// to string. The given formats are used to effect the conversion;
// fmt.Sprintf(printf, x) is used to convert the float64 value x to string;
// fmt.Sscanf(s, scanf, &x) is used to scan the string s into the fl... | Go |
package values
import (
"errors"
"reflect"
)
// NewConst returns a Value of type t which always returns the value v,
// and gives an error when set.
func NewConst(val interface{}, t reflect.Type) Value {
if t == nil {
return &constValue{reflect.ValueOf(val)}
}
v := &constValue{reflect.New(t).Elem()}
v.val.Set... | Go |
// The values package provides multiple-writer,
// multiple-listener access to changing values.
// It also provides (through the Transform function
// and the Lens type) the facility to have multiple,
// mutually updating views of the same value.
//
package values
import (
"reflect"
"sync"
)
// A Value represents a... | Go |
package values
import (
"fmt"
"reflect"
)
// A Lens can transform from values of type T to values
// of type T1. It can be reversed to transform in the
// other direction, and be combined with other Lenses.
//
type Lens struct {
f, finv func(reflect.Value) (reflect.Value, error)
t, t1 reflect.Type
}
func okTra... | Go |
// +build ignore
package values
// Marshal returns the value encoding of v.
// Marshal traverses the value recursively.
//
// Boolean values encode as bool.
// Signed integer types encode as int64.
// Unsigned integer types encode as uint64.
// Floating point types encode as float64
// Complex types encode as comple... | Go |
// The netchanrpc package makes it possible to run an RPC service
// over netchan.
package ncnet
import (
"errors"
"fmt"
"io"
"log"
"net"
"netchan"
)
const initMessage = "netconnect"
type netchanAddr string
type hanguper interface {
Hangup(name string) error
}
func (a netchanAddr) String() string {
return ... | Go |
// The parallel package provides a way of running functions
// concurrently while limiting the maximum number
// running at once.
package parallel
import (
"fmt"
"sync"
)
// Run represents a number of functions running concurrently.
type Run struct {
limiter chan struct{}
done chan error
err chan error
w... | Go |
// The fakenet package provides a way to turn a regular io.ReadWriter
// into a net.Conn, including support for timeouts.
package fakenet
import (
"io"
"net"
"time"
)
type Addr string
func (a Addr) Network() string {
return "fakenet"
}
func (a Addr) String() string {
return "fakenet:" + string(a)
}
// we've g... | Go |
package fakenet
import (
"errors"
"io"
"runtime"
"sync"
"time"
)
// A ChanReader reads from a chan []byte to
// satisfy Read requests.
type ChanReader struct {
mu sync.Mutex
buf []byte
c <-chan []byte
closedCh chan bool
closed bool
}
// NewChanReader creates a new ChanReader that
// rea... | Go |
package fakenet
import (
"io"
"net"
)
type listener struct {
addr net.Addr
closedCh chan bool
conns chan net.Conn
}
// NewListener creates a new net.Listener and returns a channel on which
// it reads connections and gives to callers of Accept. The Listener
// returns addr for its address (or Addr("fake... | Go |
package readlines
import (
"bufio"
"io"
"unicode/utf8"
)
// Iter reads lines from r and calls fn with each read line, not
// including the line terminator. If a line exceeds the given maximum
// size, it will be truncated and the rest of the line discarded. If fn
// returns a non-nil error, reading ends and the ... | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.