Permalink
Browse files

More doc/golint cleanup

  • Loading branch information...
1 parent 88b6e00 commit 98eaf35063695a7ed37c4113865f0ce30c6f4aac @dustin dustin committed Feb 3, 2014
Showing with 65 additions and 49 deletions.
  1. +4 −4 ddocs.go
  2. +35 −25 pools.go
  3. +4 −3 populate/populate.go
  4. +14 −11 tap.go
  5. +2 −2 tools/loadfile/loadfile.go
  6. +5 −3 util/viewmgmt.go
  7. +1 −1 views.go
View
@@ -26,7 +26,7 @@ type DDocsResult struct {
Rows []struct {
DDoc struct {
Meta map[string]interface{}
- Json DDoc
+ JSON DDoc
} `json:"doc"`
} `json:"rows"`
}
@@ -69,7 +69,7 @@ func (b *Bucket) PutDDoc(docname string, value interface{}) error {
req.Header.Set("Content-Type", "application/json")
maybeAddAuth(req, b.authHandler())
- res, err := HttpClient.Do(req)
+ res, err := HTTPClient.Do(req)
if err != nil {
return err
}
@@ -97,7 +97,7 @@ func (b *Bucket) GetDDoc(docname string, into interface{}) error {
req.Header.Set("Content-Type", "application/json")
maybeAddAuth(req, b.authHandler())
- res, err := HttpClient.Do(req)
+ res, err := HTTPClient.Do(req)
if err != nil {
return err
}
@@ -126,7 +126,7 @@ func (b *Bucket) DeleteDDoc(docname string) error {
req.Header.Set("Content-Type", "application/json")
maybeAddAuth(req, b.authHandler())
- res, err := HttpClient.Do(req)
+ res, err := HTTPClient.Do(req)
if err != nil {
return err
}
View
@@ -18,13 +18,14 @@ import (
"unsafe"
)
-// The HTTP Client To Use
-var HttpClient = http.DefaultClient
+// HTTPClient to use for REST and view operations.
+var HTTPClient = http.DefaultClient
-// Size of the connection pools (per host).
+// PoolSize is the size of each connection pool (per host).
var PoolSize = 4
-// Number of overflow connections allowed in a pool.
+// PoolOverflow is the number of overflow connections allowed in a
+// pool.
var PoolOverflow = PoolSize
// AuthHandler is a callback that gets the auth username and password
@@ -40,6 +41,7 @@ type RestPool struct {
URI string `json:"uri"`
}
+// Pools represents the collection of pools as returned from the REST API.
type Pools struct {
ComponentsVersion map[string]string `json:"componentsVersion,omitempty"`
ImplementationVersion string `json:"implementationVersion"`
@@ -48,7 +50,7 @@ type Pools struct {
Pools []RestPool `json:"pools"`
}
-// A computer in a cluster running the couchbase software.
+// A Node is a computer in a cluster running the couchbase software.
type Node struct {
ClusterCompatibility int `json:"clusterCompatibility"`
ClusterMembership string `json:"clusterMembership"`
@@ -67,7 +69,7 @@ type Node struct {
ThisNode bool `json:"thisNode,omitempty"`
}
-// A pool of nodes and buckets.
+// A Pool of nodes and buckets.
type Pool struct {
BucketMap map[string]Bucket
Nodes []Node
@@ -77,14 +79,15 @@ type Pool struct {
client Client
}
+// VBucketServerMap is the a mapping of vbuckets to nodes.
type VBucketServerMap struct {
HashAlgorithm string `json:"hashAlgorithm"`
NumReplicas int `json:"numReplicas"`
ServerList []string `json:"serverList"`
VBucketMap [][]int `json:"vBucketMap"`
}
-// An individual bucket. Herein lives the most useful stuff.
+// Bucket is the primary entry point for most data operations.
type Bucket struct {
AuthType string `json:"authType"`
Capabilities []string `json:"bucketCapabilities"`
@@ -108,7 +111,7 @@ type Bucket struct {
// These are used for JSON IO, but isn't used for processing
// since it needs to be swapped out safely.
VBSMJson VBucketServerMap `json:"vBucketServerMap"`
- NodesJson []Node `json:"nodes"`
+ NodesJSON []Node `json:"nodes"`
pool *Pool
connPools unsafe.Pointer // *[]*connectionPool
@@ -117,11 +120,12 @@ type Bucket struct {
commonSufix string
}
-// Get the current vbucket server map
+// VBServerMap returns the current VBucketServerMap.
func (b Bucket) VBServerMap() *VBucketServerMap {
return (*VBucketServerMap)(atomic.LoadPointer(&b.vBucketServerMap))
}
+// Nodes returns teh current list of nodes servicing this bucket.
func (b Bucket) Nodes() []Node {
return *(*[]Node)(atomic.LoadPointer(&b.nodeList))
}
@@ -162,7 +166,8 @@ func (b Bucket) authHandler() (ah AuthHandler) {
return
}
-// Get the (sorted) list of memcached node addresses (hostname:port).
+// NodeAddresses gets the (sorted) list of memcached node addresses
+// (hostname:port).
func (b Bucket) NodeAddresses() []string {
vsm := b.VBServerMap()
rv := make([]string, len(vsm.ServerList))
@@ -171,7 +176,8 @@ func (b Bucket) NodeAddresses() []string {
return rv
}
-// Get the longest common suffix of all host:port strings in the node list.
+// CommonAddressSuffix finds the longest common suffix of all
+// host:port strings in the node list.
func (b Bucket) CommonAddressSuffix() string {
input := []string{}
for _, n := range b.Nodes() {
@@ -180,7 +186,8 @@ func (b Bucket) CommonAddressSuffix() string {
return FindCommonSuffix(input)
}
-// The couchbase client gives access to all the things.
+// A Client is the starting point for all services across all buckets
+// in a Couchbase cluster.
type Client struct {
BaseURL *url.URL
ah AuthHandler
@@ -196,11 +203,11 @@ func maybeAddAuth(req *http.Request, ah AuthHandler) {
}
func queryRestAPI(
- baseUrl *url.URL,
+ baseURL *url.URL,
path string,
authHandler AuthHandler,
out interface{}) error {
- u := *baseUrl
+ u := *baseURL
u.User = nil
if q := strings.Index(path, "?"); q > 0 {
u.Path = path[:q]
@@ -215,7 +222,7 @@ func queryRestAPI(
}
maybeAddAuth(req, authHandler)
- res, err := HttpClient.Do(req)
+ res, err := HTTPClient.Do(req)
if err != nil {
return err
}
@@ -319,7 +326,7 @@ func (b *Bucket) refresh() error {
}
b.replaceConnPools(newcps)
atomic.StorePointer(&b.vBucketServerMap, unsafe.Pointer(&tmpb.VBSMJson))
- atomic.StorePointer(&b.nodeList, unsafe.Pointer(&tmpb.NodesJson))
+ atomic.StorePointer(&b.nodeList, unsafe.Pointer(&tmpb.NodesJSON))
return nil
}
@@ -333,15 +340,16 @@ func (p *Pool) refresh() (err error) {
}
for _, b := range buckets {
b.pool = p
- b.nodeList = unsafe.Pointer(&b.NodesJson)
+ b.nodeList = unsafe.Pointer(&b.NodesJSON)
b.replaceConnPools(make([]*connectionPool, len(b.VBSMJson.ServerList)))
p.BucketMap[b.Name] = b
}
return nil
}
-// Get a pool from within the couchbase cluster (usually "default").
+// GetPool gets a pool from within the couchbase cluster (usually
+// "default").
func (c *Client) GetPool(name string) (p Pool, err error) {
var poolURI string
for _, p := range c.Info.Pools {
@@ -361,7 +369,8 @@ func (c *Client) GetPool(name string) (p Pool, err error) {
return
}
-// Mark this bucket as no longer needed, closing connections it may have open.
+// Close marks this bucket as no longer needed, closing connections it
+// may have open.
func (b *Bucket) Close() {
if b.connPools != nil {
for _, c := range b.getConnPools() {
@@ -373,37 +382,38 @@ func (b *Bucket) Close() {
}
}
-func bucket_finalizer(b *Bucket) {
+func bucketFinalizer(b *Bucket) {
if b.connPools != nil {
log.Printf("Warning: Finalizing a bucket with active connections.")
}
}
-// Get a bucket from within this pool.
+// GetBucket gets a bucket from within this pool.
func (p *Pool) GetBucket(name string) (*Bucket, error) {
rv, ok := p.BucketMap[name]
if !ok {
return nil, errors.New("No bucket named " + name)
}
- runtime.SetFinalizer(&rv, bucket_finalizer)
+ runtime.SetFinalizer(&rv, bucketFinalizer)
err := rv.refresh()
if err != nil {
return nil, err
}
return &rv, nil
}
-// Get the pool to which this bucket belongs.
+// GetPool gets the pool to which this bucket belongs.
func (b *Bucket) GetPool() *Pool {
return b.pool
}
-// Get the client from which we got this pool.
+// GetClient gets the client from which we got this pool.
func (p *Pool) GetClient() *Client {
return &p.client
}
-// Convenience function for getting a named bucket from a URL
+// GetBucket is a convenience function for getting a named bucket from
+// a URL
func GetBucket(endpoint, poolname, bucketname string) (*Bucket, error) {
var err error
client, err := Connect(endpoint)
@@ -3,12 +3,13 @@ package main
import (
"flag"
"fmt"
- "github.com/couchbaselabs/go-couchbase"
"log"
"math/rand"
"os"
"text/tabwriter"
"time"
+
+ "github.com/couchbaselabs/go-couchbase"
)
var poolName = flag.String("pool", "default", "Pool to connect to")
@@ -45,7 +46,7 @@ var projects = []string{
"ep-engine", "couchdb", "ns_server", "moxi", "libcouchbase",
}
-type Record struct {
+type record struct {
Author string `json:"author"`
Reviewer string `json:"reviewer"`
Action string `json:"action"`
@@ -87,7 +88,7 @@ func harass(c *couchbase.Client, b *couchbase.Bucket) {
}()
for {
- r := Record{
+ r := record{
Author: names[rand.Intn(len(names))],
Reviewer: names[rand.Intn(len(names))],
Action: actions[rand.Intn(len(actions))],
View
@@ -7,11 +7,14 @@ import (
"github.com/dustin/gomemcached/client"
)
-const kInitialRetryInterval = 1 * time.Second
-const kMaximumRetryInterval = 30 * time.Second
-
-// A Tap feed. Events from the bucket can be read from the channel 'C'.
-// Remember to call Close() on it when you're done, unless its channel has closed itself already.
+const initialRetryInterval = 1 * time.Second
+const maximumRetryInterval = 30 * time.Second
+
+// A TapFeed streams mutation events from a bucket.
+//
+// Events from the bucket can be read from the channel 'C'. Remember
+// to call Close() on it when you're done, unless its channel has
+// closed itself already.
type TapFeed struct {
C <-chan memcached.TapEvent
@@ -22,7 +25,7 @@ type TapFeed struct {
quit chan bool
}
-// Creates and starts a new Tap feed
+// StartTapFeed creates and starts a new Tap feed
func (b *Bucket) StartTapFeed(args *memcached.TapArguments) (*TapFeed, error) {
if args == nil {
defaultArgs := memcached.DefaultTapArguments()
@@ -44,7 +47,7 @@ func (b *Bucket) StartTapFeed(args *memcached.TapArguments) (*TapFeed, error) {
// Goroutine that runs the feed
func (feed *TapFeed) run() {
- retryInterval := kInitialRetryInterval
+ retryInterval := initialRetryInterval
bucketOK := true
for {
// Connect to the TAP feed of each server node:
@@ -58,7 +61,7 @@ func (feed *TapFeed) run() {
return
}
feed.closeNodeFeeds()
- retryInterval = kInitialRetryInterval
+ retryInterval = initialRetryInterval
}
}
@@ -73,8 +76,8 @@ func (feed *TapFeed) run() {
case <-feed.quit:
return
}
- if retryInterval *= 2; retryInterval > kMaximumRetryInterval {
- retryInterval = kMaximumRetryInterval
+ if retryInterval *= 2; retryInterval > maximumRetryInterval {
+ retryInterval = maximumRetryInterval
}
}
}
@@ -121,7 +124,7 @@ func (feed *TapFeed) closeNodeFeeds() {
feed.nodeFeeds = nil
}
-// Closes a Tap feed.
+// Close a Tap feed.
func (feed *TapFeed) Close() error {
select {
case <-feed.quit:
@@ -30,7 +30,7 @@ func main() {
maybeFatal(err, "Error connecting to couchbase: %v\n", err)
for _, filename := range flag.Args() {
- key := pathToId(filename, *includeExt)
+ key := pathToID(filename, *includeExt)
bytes, err := ioutil.ReadFile(filename)
maybeFatal(err, "Error reading file contents: %v\n", err)
b.SetRaw(key, 0, bytes)
@@ -43,7 +43,7 @@ func main() {
}
}
-func pathToId(p string, includeExt bool) string {
+func pathToID(p string, includeExt bool) string {
_, file := path.Split(p)
if includeExt {
return file
View
@@ -1,4 +1,5 @@
-// Utilities for working with Couchbase
+// Package couchbaseutil offers some convenience functions for apps
+// that use couchbase.
package couchbaseutil
import (
@@ -9,14 +10,15 @@ import (
"github.com/couchbaselabs/go-couchbase"
)
-// A marker stored in your DB to mark a particular view version.
+// A ViewMarker is stored in your DB to mark a particular view
+// version.
type ViewMarker struct {
Version int `json:"version"`
Timestamp time.Time `json:"timestamp"`
Type string `json:"type"`
}
-// Install or update a view.
+// UpdateView installs or updates a view.
//
// This creates a document that tracks the version of design document
// in couchbase and updates it if it's behind the version specified.
Oops, something went wrong. Retry.

0 comments on commit 98eaf35

Please sign in to comment.