code stringlengths 10 1.34M | language stringclasses 1
value |
|---|---|
// 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 sqlite provides access to the SQLite library, version 3.
package sqlite
/*
#cgo LDFLAGS: -lsqlite3
#include <sqlite3.h>
#include <stdlib.h>
// The... | 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 sqlite3 provides access to the SQLite library, version 3.
//
// The package has no exported API.
// It registers a driver for the standard Go databas... | Go |
package rand
/*
#include <stdlib.h>
*/
import "C"
func Random() int {
return int(C.rand())
}
func Seed(i int) {
C.srand(C.uint(i))
}
| Go |
// +build ignore
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributio... | 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.
/*
An example of wrapping a C library in Go. This is the GNU
multiprecision library gmp's integer type mpz_t wrapped to look like
the Go package big's integer ... | 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 ignore
// Compute Fibonacci numbers with two goroutines
// that pass integers back and forth. No actual
// concurrency, just threads and synchroniz... | Go |
/*
Copyright 2013 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
di... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2013 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
// Go MySQL Driver - A MySQ... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2013 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2013 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2012 Julien Schmidt. All rights reserved.
// http://www.julienschmidt.com
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can ob... | Go |
package simplejson
import (
"encoding/json"
"errors"
"log"
)
// returns the current implementation version
func Version() string {
return "0.4.2"
}
type Json struct {
data interface{}
}
// NewJson returns a pointer to a new `Json` object
// after unmarshaling `body` bytes
func NewJson(body []byte) (*Json, erro... | Go |
package main
import (
"flag"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"log"
"net"
"os"
"os/signal"
"time"
)
##
var (
showVersion = flag.Bool("version", false, "print version string")
tcpAddress = flag.String("tcp-address", "0.0.0.0:4160", "<addr>:<port> to lis... | Go |
package main
import (
"github.com/bitly/nsq/util"
"log"
"net"
"time"
)
type NSQLookupd struct {
tcpAddr *net.TCPAddr
httpAddr *net.TCPAddr
tcpListener net.Listener
httpListener net.Listener
broadcastAddress string
waitGroup util.Wait... | Go |
package main
import (
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
)
type TcpProtocol struct {
util.TcpHandler
protocols map[string]nsq.Protocol
}
func (p *TcpProtocol) Handle(clientConn net.Conn) {
log.Printf("TCP: new client(%s)", clientConn.RemoteAddr())
// The client should i... | Go |
package main
import (
"bufio"
"encoding/binary"
"encoding/json"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
"os"
"strings"
"time"
)
type LookupProtocolV1 struct {
nsq.Protocol
}
func init() {
protocols[string(nsq.MagicV1)] = &LookupProtocolV1{}
}
func (p *LookupProtoc... | Go |
package main
import (
"net"
)
type ClientV1 struct {
net.Conn
peerInfo *PeerInfo
}
func NewClientV1(conn net.Conn) *ClientV1 {
return &ClientV1{
Conn: conn,
}
}
func (c *ClientV1) String() string {
return c.RemoteAddr().String()
}
| Go |
package main
import (
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
"net/http"
"strings"
)
func httpServer(listener net.Listener) {
log.Printf("HTTP: listening on %s", listener.Addr().String())
handler := http.NewServeMux()
handler.HandleFunc("/info", infoHandler)
handler.... | Go |
package main
import (
"fmt"
"sync"
"time"
)
type RegistrationDB struct {
sync.RWMutex
registrationMap map[Registration]Producers
}
type Registration struct {
Category string
Key string
SubKey string
}
type Registrations []*Registration
type PeerInfo struct {
id string
RemoteAddress ... | Go |
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/bitly/go-simplejson"
"github.com/bitly/nsq/util"
"html/template"
"log"
"net"
"net/http"
"net/url"
"time"
)
type GraphTarget interface {
Target(key string) (string, string)
}
type Topic struct {
TopicName string
}
type Topics []*Topic
fun... | Go |
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"github.com/bitly/nsq/nsq"
"log"
"net/http"
"strings"
"time"
)
type AdminAction struct {
Action string `json:"action"`
Topic string `json:"topic"`
Channel string `json:"channel"`
Timestamp int64 `json:"timestamp"`
User string ... | Go |
package main
import (
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"github.com/bitly/nsq/util/lookupd"
"html/template"
"io"
"io/ioutil"
"log"
"net"
"net/http"
"net/http/httputil"
"net/url"
"regexp"
"strings"
"time"
)
var templates *template.Template
func loadTemplates() {
var err erro... | Go |
package main
import (
"flag"
"fmt"
"github.com/bitly/nsq/util"
"log"
"net"
"os"
"os/signal"
"time"
)
var (
showVersion = flag.Bool("version", false, "print version string")
httpAddress = flag.String("http-address", "0.0.0.0:4171", "<addr>:<port> to listen on for HTTP clients")
tem... | Go |
// This is an NSQ client that reads the specified topic/channel
// and performs HTTP requests (GET/POST) to the specified endpoints
package main
import (
"bytes"
"errors"
"flag"
"fmt"
"github.com/bitly/go-hostpool"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"log"
"math"
"math/rand"
"net/url"
"... | Go |
package main
import (
"bytes"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"net/http"
"time"
)
var httpclient *http.Client
var userAgent string
func init() {
httpclient = &http.Client{Transport: nsq.NewDeadlineTransport(time.Duration(*httpTimeoutMs) * time.Millisecond)}
userAgent = fmt.Sprint... | Go |
// This is a utility application that polls /stats for all the producers
// of the specified topic/channel and displays aggregate stats
package main
import (
"errors"
"flag"
"fmt"
"github.com/bitly/nsq/util"
"github.com/bitly/nsq/util/lookupd"
"io/ioutil"
"log"
"os"
"os/signal"
"strings"
"syscall"
"time"
... | Go |
package main
import (
"flag"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"log"
"math/rand"
"os"
"os/signal"
"syscall"
"time"
)
var (
showVersion = flag.Bool("version", false, "print version string")
topic = flag.String("topic", "", "nsq topic")
channel = flag.Str... | Go |
package main
import (
"bufio"
"bytes"
"flag"
"github.com/bitly/nsq/nsq"
"log"
"net"
"runtime"
"sync"
"time"
)
var (
num = flag.Int("num", 1000000, "num messages")
tcpAddress = flag.String("nsqd-tcp-address", "127.0.0.1:4150", "<addr>:<port> to connect to nsqd")
topic = flag.String("topic", "su... | Go |
package main
import (
"bufio"
"flag"
"github.com/bitly/nsq/nsq"
"log"
"math"
"net"
"runtime"
"sync"
"time"
)
var (
num = flag.Int("num", 1000000, "num messages")
tcpAddress = flag.String("nsqd-tcp-address", "127.0.0.1:4150", "<addr>:<port> to connect to nsqd")
topic = flag.String("topic", "sub... | Go |
// This is a client that writes out to a file, and optionally rolls the file
package main
import (
"compress/gzip"
"errors"
"flag"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"log"
"os"
"os/signal"
"path"
"strings"
"syscall"
"time"
)
var (
datetimeFormat = flag.String("datetime-forma... | Go |
// COPIED FROM https://github.com/jehiah/go-strftime
package main
import (
"time"
)
// taken from time/format.go
var conversion = map[string]string{
/*stdLongMonth */ "B": "January",
/*stdMonth */ "b": "Jan",
// stdNumMonth */ "m": "1",
/*stdZeroMonth */ "m": "01",
/*stdLongWeekDay *... | Go |
// This is a client exposes a HTTP streaming interface to NSQ channels
package main
import (
"bufio"
"flag"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
"net/http"
"strings"
"sync"
"sync/atomic"
"time"
)
var (
showVersion = flag.Bool("version", false, "print versio... | Go |
package util
import (
"fmt"
"runtime"
)
const BINARY_VERSION = "0.2.21"
func Version(app string) string {
return fmt.Sprintf("%s v%s (built w/%s)", app, BINARY_VERSION, runtime.Version())
}
| Go |
package util
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
)
func ApiResponse(w http.ResponseWriter, statusCode int, statusTxt string, data interface{}) {
response, err := json.Marshal(struct {
StatusCode int `json:"status_code"`
StatusTxt string `json:"status_txt"`
Data interface... | Go |
package util
import (
"errors"
)
func ByteToBase10(b []byte) (n uint64, err error) {
base := uint64(10)
n = 0
for i := 0; i < len(b); i++ {
var v byte
d := b[i]
switch {
case '0' <= d && d <= '9':
v = d - '0'
default:
n = 0
err = errors.New("failed to convert to Base10")
break
}
n *= ba... | Go |
package util
import (
"sync"
)
/**同步锁的接口*/
type WaitGroupWrapper struct {
sync.WaitGroup
}
func (w *WaitGroupWrapper) Wrap(cb func()) {
w.Add(1)
go func() {
cb()
w.Done()
}()
}
| Go |
package util
import (
"errors"
"fmt"
"net"
"time"
)
type StatsdClient struct {
conn net.Conn
addr string
prefix string
}
func NewStatsdClient(addr string, prefix string) *StatsdClient {
return &StatsdClient{
addr: addr,
prefix: prefix,
}
}
func (c *StatsdClient) String() string {
return c.addr
}... | Go |
package util
import (
"fmt"
)
func Commafy(i interface{}) string {
var n int64
switch i.(type) {
case int:
n = int64(i.(int))
case int64:
n = i.(int64)
case int32:
n = int64(i.(int32))
}
if n > 1000 {
r := n % 1000
n = n / 1000
return fmt.Sprintf("%s,%03d", Commafy(n), r)
}
return fmt.Sprintf("%... | Go |
package util
import (
"log"
"net"
"runtime"
"strings"
)
type TcpHandler interface {
Handle(net.Conn)
}
func TcpServer(listener net.Listener, handler TcpHandler) {
log.Printf("TCP: listening on %s", listener.Addr().String())
for {
clientConn, err := listener.Accept()
if err != nil {
if nerr, ok := err.... | Go |
// COPIED FROM http://code.google.com/p/go-semver/
//
// The version package implements semantic versions as described
// at http://semver.org/
package semver
import (
"fmt"
"regexp"
"strconv"
"strings"
)
// Version represents a parsed version. See http://semver.org/ for
// detailed description of the various com... | Go |
package util
import (
"errors"
"io/ioutil"
"net/http"
"net/url"
)
type ReqParams struct {
url.Values
Body []byte
}
func NewReqParams(req *http.Request) (*ReqParams, error) {
reqParams, err := url.ParseQuery(req.URL.RawQuery)
if err != nil {
return nil, err
}
data, err := ioutil.ReadAll(req.Body)
if err... | Go |
package lookupd
import (
"errors"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"github.com/bitly/nsq/util/semver"
"log"
"net/url"
"sort"
"strings"
"sync"
"time"
)
// GetLookupdTopics returns a []string containing a union of all the topics
// from all the given lookupd
func GetLookupdTopics(... | Go |
package lookupd
import (
"fmt"
"github.com/bitly/nsq/util/semver"
"sort"
"strings"
"time"
)
type Producer struct {
RemoteAddresses []string `json:"remote_addresses"`
Address string `json:"address"` //TODO: remove for 1.0
Hostname string `json:"hostname"`
BroadcastAd... | Go |
package util
func StringAdd(s []string, a string) []string {
o := s
found := false
for _, existing := range s {
if a == existing {
found = true
return s
}
}
if found == false {
o = append(o, a)
}
return o
}
func StringUnion(s []string, a []interface{}) []string {
o := s
for _, entry := range a {... | Go |
package pqueue
import (
"container/heap"
)
type Item struct {
Value interface{}
Priority int64
Index int
}
// this is a priority queue as implemented by a min heap
// ie. the 0th element is the *lowest* value
type PriorityQueue []*Item
func New(capacity int) PriorityQueue {
return make(PriorityQueue, 0, ... | Go |
package util
import (
"errors"
"github.com/bitly/nsq/nsq"
)
/**参见 req_params.go ReqParams 和 PostParams*/
type Getter interface {
Get(key string) (string, error)
}
func GetTopicChannelArgs(rp Getter) (string, string, error) {
topicName, err := rp.Get("topic")
if err != nil {
return "", "", errors.New("MISSING_... | Go |
package util
import (
"io"
"net"
"time"
)
type MockConn struct {
io.ReadWriter
}
func (c MockConn) Close() error {
return nil
}
func (c MockConn) LocalAddr() net.Addr {
return &net.TCPAddr{IP: net.IPv4zero}
}
func (c MockConn) RemoteAddr() net.Addr {
return &net.TCPAddr{IP: net.IPv4zero}
}
func (c MockConn... | Go |
package util
import (
"fmt"
)
type StringArray []string
func (a *StringArray) Set(s string) error {
*a = append(*a, s)
return nil
}
func (a *StringArray) String() string {
return fmt.Sprint(*a)
}
| Go |
package main
import (
"crypto/md5"
"flag"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"hash/crc32"
"io"
"log"
"net"
"os"
"os/signal"
"regexp"
"strconv"
"strings"
"syscall"
"time"
)
var (
// basic options
showVersion = flag.Bool("version", false, "print version string")
verbose... | Go |
package main
import (
"bufio"
"errors"
"fmt"
"github.com/bitly/nsq/nsq"
"log"
"net"
"sync"
"sync/atomic"
"time"
)
type IdentifyDataV2 struct {
ShortId string `json:"short_id"`
LongId string `json:"long_id"`
HeartbeatInterval int `json:"heartbeat_interval"`
OutputBufferSize ... | Go |
package main
import (
"fmt"
"github.com/bitly/nsq/util"
"log"
"time"
)
func statsdLoop(addr string, prefix string, interval time.Duration) {
lastStats := make([]TopicStats, 0)
ticker := time.NewTicker(interval)
for {
select {
case <-ticker.C:
statsd := util.NewStatsdClient(addr, prefix)
err := statsd... | Go |
package main
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
"sync/atomic"
"time"
"unsafe"
)
const maxTimeout = time.Hour
var separatorBytes = []byte(" ")
var heartbeatBytes = []byte("_heartbeat_")
var okBytes = []byte("OK")... | Go |
package main
// the core algorithm here was borrowed from:
// Blake Mizerany's `noeqd` https://github.com/bmizerany/noeqd
// and indirectly:
// Twitter's `snowflake` https://github.com/twitter/snowflake
// only minor cleanup and changes to introduce a type, combine the concept
// of workerId + datacenterId into a sin... | Go |
package main
import (
"bytes"
"encoding/json"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"log"
"net"
"os"
"strconv"
"time"
)
/**
1. 容器启动后, 将与初始化与nsqlookup server 的连接, 并且将容器中的 topic 和 channel 信息,注册到 nsqlookup server
2. topic 和 channel 创建 或者 销毁, 发送 注册或者取消注册命令到所有的nsqlookup server
3. 每隔15秒, 发送心跳包到所有的... | Go |
package main
import (
"bytes"
"github.com/bitly/nsq/nsq"
)
// BackendQueue represents the behavior for the secondary message
// storage system
type BackendQueue interface {
Put([]byte) error
ReadChan() chan []byte // this is expected to be an *unbuffered* channel
Close() error
Delete() error
Depth() int64
Emp... | Go |
package main
import (
"bytes"
"errors"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"log"
"sync"
"sync/atomic"
)
type Topic struct {
sync.RWMutex
name string
channelMap map[string]*Channel
// 备份消息
backend BackendQueue
//新put进来的消息存放于此, 通过 topic.router() 线程将会监听该 chan,
incomingMsgChan cha... | Go |
package main
import (
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
)
type TcpProtocol struct {
util.TcpHandler
protocols map[string]nsq.Protocol
}
func (p *TcpProtocol) Handle(clientConn net.Conn) {
log.Printf("TCP: new client(%s)", clientConn.RemoteAddr())
// The client should i... | Go |
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/bitly/go-simplejson"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"github.com/bitly/nsq/util/lookupd"
"io/ioutil"
"log"
"net"
"os"
"path"
"runtime"
"sync"
"time"
)
type Notifier interface {
Notify(v interface{})
}
/** NSQd 结构体... | Go |
package main
import (
"bufio"
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"log"
"os"
"path"
"sync"
"sync/atomic"
"time"
)
// DiskQueue implements the BackendQueue interface
// providing a filesystem backed FIFO queue
type DiskQueue struct {
sync.RWMutex
// instantiation time metadata
name ... | Go |
package main
import (
"bytes"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
"net/http"
"os"
"runtime/pprof"
"strings"
"time"
)
import httpprof "net/http/pprof"
func httpServer(listener net.Listener) {
log.Printf("HTTP: listening on %s", listener.Addr().String())
handler... | Go |
package main
import (
"bytes"
"container/heap"
"errors"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"github.com/bitly/nsq/util/pqueue"
"log"
"math"
"strings"
"sync"
"sync/atomic"
"time"
)
// the amount of time a worker will wait when idle
const defaultWorkerWait = 100 * time.Millisecond
type C... | Go |
package main
import (
"sort"
)
type TopicStats struct {
TopicName string `json:"topic_name"`
Channels []ChannelStats `json:"channels"`
Depth int64 `json:"depth"`
BackendDepth int64 `json:"backend_depth"`
MessageCount uint64 `json:"message_count"`
}
func NewTopicS... | Go |
package main
import (
"flag"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"log"
"net"
"os"
"os/signal"
"time"
)
var (
showVersion = flag.Bool("version", false, "print version string")
tcpAddress = flag.String("tcp-address", "0.0.0.0:4160", "<addr>:<port> to listen o... | Go |
package main
import (
"github.com/bitly/nsq/util"
"log"
"net"
"time"
)
type NSQLookupd struct {
tcpAddr *net.TCPAddr
httpAddr *net.TCPAddr
tcpListener net.Listener
httpListener net.Listener
broadcastAddress string
waitGroup util.Wait... | Go |
package main
import (
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
)
type TcpProtocol struct {
util.TcpHandler
protocols map[string]nsq.Protocol
}
func (p *TcpProtocol) Handle(clientConn net.Conn) {
log.Printf("TCP: new client(%s)", clientConn.RemoteAddr())
// The client should i... | Go |
package main
import (
"bufio"
"encoding/binary"
"encoding/json"
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
"os"
"strings"
"time"
)
type LookupProtocolV1 struct {
nsq.Protocol
}
func init() {
protocols[string(nsq.MagicV1)] = &LookupProtocolV1{}
}
func (p *LookupProtoc... | Go |
package main
import (
"net"
)
type ClientV1 struct {
net.Conn
peerInfo *PeerInfo
}
func NewClientV1(conn net.Conn) *ClientV1 {
return &ClientV1{
Conn: conn,
}
}
func (c *ClientV1) String() string {
return c.RemoteAddr().String()
}
| Go |
package main
import (
"fmt"
"github.com/bitly/nsq/nsq"
"github.com/bitly/nsq/util"
"io"
"log"
"net"
"net/http"
"strings"
)
func httpServer(listener net.Listener) {
log.Printf("HTTP: listening on %s", listener.Addr().String())
handler := http.NewServeMux()
handler.HandleFunc("/info", infoHandler)
handler.... | Go |
package main
import (
"fmt"
"sync"
"time"
)
type RegistrationDB struct {
sync.RWMutex
registrationMap map[Registration]Producers
}
type Registration struct {
Category string
Key string
SubKey string
}
type Registrations []*Registration
//
type PeerInfo struct {
// 客户端id,此处使用的是客户端的ip地址
id ... | Go |
package nsq
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"time"
)
// The number of bytes for a Message.Id
const MsgIdLength = 16
type MessageID [MsgIdLength]byte
// Message is the fundamental data type containing
// the id, body, and metadata
type Message struct {
Id MessageID
Body ... | Go |
// nsq is the official Go package for https://github.com/bitly/nsq
//
// It provides the building blocks for developing applications on the NSQ platform in Go.
//
// Low-level functions and types are provided to communicate over the NSQ protocol as well
// as a high-level Reader library to implement robust consumers.
p... | Go |
package nsq
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"io"
"strconv"
)
var byteSpace = []byte(" ")
var byteNewLine = []byte("\n")
// Command represents a command from a client to an NSQ daemon
type Command struct {
Name []byte
Params [][]byte
Body []byte
}
// String returns the name and ... | Go |
package nsq
import (
"errors"
"fmt"
"github.com/bitly/go-simplejson"
"io/ioutil"
"net"
"net/http"
"time"
)
type deadlinedConn struct {
Timeout time.Duration
net.Conn
}
func (c *deadlinedConn) Read(b []byte) (n int, err error) {
c.Conn.SetReadDeadline(time.Now().Add(c.Timeout))
return c.Conn.Read(b)
}
fun... | Go |
package nsq
import (
"bufio"
"bytes"
"errors"
"fmt"
"log"
"net"
"os"
"strings"
"sync/atomic"
"time"
)
type Writer struct {
net.Conn
transactionChan chan *writerTransaction
dataChan chan []byte
WriteTimeout time.Duration
transactions []*writerTransaction
state int32
st... | Go |
package nsq
const (
StateInit = iota
StateDisconnected
StateConnected
StateSubscribed
// close has started. responses are ok, but no new messages will be sent
StateClosing
)
| Go |
package nsq
import (
"encoding/binary"
"errors"
"io"
"net"
"regexp"
"time"
)
var MagicV1 = []byte(" V1")
var MagicV2 = []byte(" V2")
const (
// when successful
FrameTypeResponse int32 = 0
// when an error occurred
FrameTypeError int32 = 1
// when it's a serialized message
FrameTypeMessage int32 = 2
)
... | Go |
package nsq
type ChildError interface {
Parent() error
}
// ClientErr provides a way for NSQ daemons to log a human reabable
// error string and return a machine readable string to the client.
//
// see docs/protocol.md for error codes by command
type ClientErr struct {
ParentErr error
Code string
Desc ... | Go |
package nsq
import (
"log"
"net"
"time"
)
// LookupPeer is a low-level type for connecting/reading/writing to nsqlookupd
//
// A LookupPeer instance is designed to connect lazily to nsqlookupd and reconnect
// gracefully (i.e. it is all handled by the library). Clients can simply use the
// Command interface to p... | Go |
package nsq
import (
"bufio"
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
"math"
"math/rand"
"net"
"net/url"
"os"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
)
// returned from ConnectToNSQ() when already connected
var ErrAlreadyConnected = errors.New("already connected")
// Handler is the synchr... | Go |
package hostpool
import (
"time"
)
// --- hostEntry - this is due to get upgraded
type hostEntry struct {
host string
nextRetry time.Time
retryCount int16
retryDelay time.Duration
dead bool
epsilonCounts []int64
epsilonValues []int64
epsilonIndex ... | Go |
package hostpool
import (
"log"
"math/rand"
"time"
)
type epsilonHostPoolResponse struct {
standardHostPoolResponse
started time.Time
ended time.Time
}
func (r *epsilonHostPoolResponse) Mark(err error) {
r.Do(func() {
r.ended = time.Now()
doMark(err, r)
})
}
type epsilonGreedyHostPool struct {
stand... | Go |
package hostpool
// --- Value Calculators -----------------
import (
"math"
)
// --- Definitions -----------------------
// Structs implementing this interface are used to convert the average response time for a host
// into a score that can be used to weight hosts in the epsilon greedy hostpool. Lower response
//... | Go |
// A Go package to intelligently and flexibly pool among multiple hosts from your Go application.
// Host selection can operate in round robin or epsilon greedy mode, and unresponsive hosts are
// avoided. A good overview of Epsilon Greedy is here http://stevehanov.ca/blog/index.php?id=132
package hostpool
import (
"... | Go |
package assert
// Testing helpers for doozer.
import (
"github.com/kr/pretty"
"reflect"
"testing"
"runtime"
"fmt"
)
func assert(t *testing.T, result bool, f func(), cd int) {
if !result {
_, file, line, _ := runtime.Caller(cd + 1)
t.Errorf("%s:%d", file, line)
f()
t.FailNow()
}
}
func equal(t *testing... | Go |
package point
type Point struct {
X, Y int
}
| Go |
package pretty
import (
"fmt"
"github.com/kr/text"
"io"
"reflect"
"strconv"
"text/tabwriter"
)
const (
limit = 50
)
type formatter struct {
x interface{}
force bool
quote bool
}
// Formatter makes a wrapper, f, that will format x as go source with line
// breaks and tabs. Object f responds to the "%v"... | Go |
package pretty
import (
"reflect"
)
func nonzero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Bool:
return v.Bool()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return v.Int() != 0
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, refl... | Go |
package pretty
import (
"fmt"
"io"
"reflect"
)
type sbuf []string
func (s *sbuf) Write(b []byte) (int, error) {
*s = append(*s, string(b))
return len(b), nil
}
// Diff returns a slice where each element describes
// a difference between a and b.
func Diff(a, b interface{}) (desc []string) {
Fdiff((*sbuf)(&des... | Go |
// Package pretty provides pretty-printing for Go values. This is
// useful during debugging, to avoid wrapping long output lines in
// the terminal.
//
// It provides a function, Formatter, that can be used with any
// function that accepts a format string. It also provides
// convenience wrappers for functions in pac... | Go |
package text
import (
"bytes"
"math"
)
var (
nl = []byte{'\n'}
sp = []byte{' '}
)
const defaultPenalty = 1e5
// Wrap wraps s into a paragraph of lines of length lim, with minimal
// raggedness.
func Wrap(s string, lim int) string {
return string(WrapBytes([]byte(s), lim))
}
// WrapBytes wraps b into a paragra... | Go |
// Package colwriter provides a write filter that formats
// input lines in multiple columns.
//
// The package is a straightforward translation from
// /src/cmd/draw/mc.c in Plan 9 from User Space.
package colwriter
import (
"bytes"
"io"
"unicode/utf8"
)
const (
tab = 4
)
const (
// Print each input line endin... | Go |
// Command mc prints in multiple columns.
//
// Usage: mc [-] [-N] [file...]
//
// Mc splits the input into as many columns as will fit in N
// print positions. If the output is a tty, the default N is
// the number of characters in a terminal line; otherwise the
// default N is 80. Under option - each input line end... | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.