Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "github.com/rhinoman/couchdb-go"
- "time"
- )
- type APICall struct {
- AppId string `json:"appId"`
- Total int `json:"total"`
- Remaining int `json:"remaining"`
- Date string `json:"date"`
- Type string `json:"type"`
- }
- func upsert() {
- var timeout = time.Duration(500 * time.Millisecond)
- conn, err := couchdb.NewConnection("127.0.0.1", 5984, timeout)
- fmt.Println(err)
- // auth := couchdb.BasicAuth{Username: "user", Password: "password"}
- db := conn.SelectDB("apicalls", nil)
- appID := "wawan"
- t := time.Now()
- fulldate := t.Format("2006-01-02")
- apiCall := APICall{
- AppId: appID,
- Total: 3000,
- Remaining: 2900,
- Date: fulldate,
- Type: "REST",
- }
- theId := fmt.Sprintf("%s%sREST", appID, fulldate)
- var docs interface{}
- rev, err := db.Read(theId, &docs, nil)
- if err != nil {
- rev, err := db.Save(apiCall, theId, "")
- fmt.Println(rev)
- fmt.Println(err)
- } else {
- rev, err := db.Save(apiCall, theId, rev)
- fmt.Println(rev)
- fmt.Println(err)
- }
- }
- func main() {
- go upsert()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement