Skip to content

Commit

Permalink
Cleanup imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
brett19 committed Jan 14, 2015
1 parent 2935e2e commit e96316d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 56 deletions.
22 changes: 9 additions & 13 deletions bucket.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package gocouchbase

import "encoding/json"
import "fmt"
import "time"
import "github.com/couchbaselabs/gocouchbaseio"
import "net/http"
import "net/url"
import "math/rand"
import (
"encoding/json"
"fmt"
"github.com/couchbaselabs/gocouchbaseio"
"math/rand"
"net/http"
"time"
)

// An interface representing a single bucket within a cluster.
type Bucket struct {
Expand Down Expand Up @@ -280,12 +281,7 @@ func (e *viewError) Error() string {
func (b *Bucket) ExecuteViewQuery(q *ViewQuery, valuesPtr interface{}) (interface{}, error) {
capiEp := b.getViewEp()

urlParams := url.Values{}
for k, v := range q.options {
urlParams.Add(k, v)
}

reqUri := fmt.Sprintf("%s/_design/%s/_view/%s?%s", capiEp, q.ddoc, q.name, urlParams.Encode())
reqUri := fmt.Sprintf("%s/_design/%s/_view/%s?%s", capiEp, q.ddoc, q.name, q.options.Encode())

resp, err := b.httpCli.Get(reqUri)
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions cluster.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package gocouchbase

import "time"
import "fmt"
import "github.com/couchbaselabs/gocouchbaseio"
import "net/http"
import "crypto/tls"
import (
"crypto/tls"
"fmt"
"github.com/couchbaselabs/gocouchbaseio"
"net/http"
"time"
)

type Cluster struct {
spec connSpec
Expand Down
8 changes: 5 additions & 3 deletions connspec.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package gocouchbase

import "fmt"
import "regexp"
import "strconv"
import (
"fmt"
"regexp"
"strconv"
)

// A single address stored within a connection string
type connSpecAddr struct {
Expand Down
6 changes: 4 additions & 2 deletions transcoding.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package gocouchbase

import "encoding/json"
import "fmt"
import (
"encoding/json"
"fmt"
)

func (b *Bucket) decodeValue(bytes []byte, flags uint32, out interface{}) (interface{}, error) {
fmt.Printf("Early Flags: %08x\n", flags)
Expand Down
72 changes: 39 additions & 33 deletions viewquery.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package gocouchbase

import "strconv"
import "encoding/json"
import (
"encoding/json"
"net/url"
"strconv"
)

type StaleMode int

Expand All @@ -21,37 +24,37 @@ const (
type ViewQuery struct {
ddoc string
name string
options map[string]string
options url.Values
}

func (vq *ViewQuery) Stale(stale StaleMode) *ViewQuery {
if stale == Before {
vq.options["stale"] = "false"
vq.options.Set("stale", "false")
} else if stale == None {
vq.options["stale"] = "ok"
vq.options.Set("stale", "ok")
} else if stale == After {
vq.options["stale"] = "update_after"
vq.options.Set("stale", "update_after")
} else {
panic("Unexpected stale option")
}
return vq
}

func (vq *ViewQuery) Skip(num uint) *ViewQuery {
vq.options["skip"] = strconv.FormatUint(uint64(num), 10)
vq.options.Set("skip", strconv.FormatUint(uint64(num), 10))
return vq
}

func (vq *ViewQuery) Limit(num uint) *ViewQuery {
vq.options["limit"] = strconv.FormatUint(uint64(num), 10)
vq.options.Set("limit", strconv.FormatUint(uint64(num), 10))
return vq
}

func (vq *ViewQuery) Order(order SortOrder) *ViewQuery {
if order == Ascending {
vq.options["descending"] = "false"
vq.options.Set("descending", "false")
} else if order == Descending {
vq.options["descending"] = "true"
vq.options.Set("descending", "true")
} else {
panic("Unexpected order option")
}
Expand All @@ -60,85 +63,88 @@ func (vq *ViewQuery) Order(order SortOrder) *ViewQuery {

func (vq *ViewQuery) Reduce(reduce bool) *ViewQuery {
if reduce == true {
vq.options["reduce"] = "true"
vq.options.Set("reduce", "true")
} else {
vq.options["reduce"] = "false"
vq.options.Set("reduce", "false")
}
return vq
}

func (vq *ViewQuery) Group(level int) *ViewQuery {
if level >= 0 {
vq.options["group"] = "false"
vq.options["group_level"] = strconv.FormatInt(int64(level), 10)
func (vq *ViewQuery) Group(useGrouping bool) *ViewQuery {
if useGrouping {
vq.options.Set("group", "true")
} else {
vq.options["group"] = "true"
vq.options["group_level"] = "0"
vq.options.Set("group", "false")
}
return vq
}

func (vq *ViewQuery) GroupLevel(groupLevel uint) *ViewQuery {
vq.options.Set("group_level", strconv.FormatUint(uint64(groupLevel), 10))
return vq
}

func (vq *ViewQuery) Key(key string) *ViewQuery {
jsonKey, _ := json.Marshal(key)
vq.options["key"] = string(jsonKey)
vq.options.Set("key", string(jsonKey))
return vq
}

func (vq *ViewQuery) Keys(keys []string) *ViewQuery {
jsonKeys, _ := json.Marshal(keys)
vq.options["keys"] = string(jsonKeys)
vq.options.Set("keys", string(jsonKeys))
return vq
}

func (vq *ViewQuery) Range(start, end interface{}, inclusive_end bool) *ViewQuery {
// TODO(brett19): Not currently handling errors due to no way to return the error
if start != nil {
jsonStartKey, _ := json.Marshal(start)
vq.options["startkey"] = string(jsonStartKey)
vq.options.Set("startkey", string(jsonStartKey))
} else {
delete(vq.options, "startkey")
vq.options.Del("startkey")
}
if end != nil {
jsonEndKey, _ := json.Marshal(end)
vq.options["endkey"] = string(jsonEndKey)
vq.options.Set("endkey", string(jsonEndKey))
} else {
delete(vq.options, "endkey")
vq.options.Del("endkey")
}
if start != nil || end != nil {
if inclusive_end {
vq.options["inclusive_end"] = "true"
vq.options.Set("inclusive_end", "true")
} else {
vq.options["inclusive_end"] = "false"
vq.options.Set("inclusive_end", "false")
}
} else {
delete(vq.options, "inclusive_end")
vq.options.Del("inclusive_end")
}
return vq
}

func (vq *ViewQuery) IdRange(start, end string) *ViewQuery {
if start != "" {
vq.options["startkey_docid"] = start
vq.options.Set("startkey_docid", start)
} else {
delete(vq.options, "startkey_docid")
vq.options.Del("startkey_docid")
}
if end != "" {
vq.options["endkey_docid"] = end
vq.options.Set("endkey_docid", end)
} else {
delete(vq.options, "endkey_docid")
vq.options.Del("endkey_docid")
}
return vq
}

func (vq *ViewQuery) Custom(name, value string) *ViewQuery {
vq.options[name] = value
vq.options.Set(name, value)
return vq
}

func NewViewQuery(ddoc, name string) *ViewQuery {
return &ViewQuery{
ddoc: ddoc,
name: name,
options: make(map[string]string),
options: url.Values{},
}
}

0 comments on commit e96316d

Please sign in to comment.