Advertisement
Guest User

Untitled

a guest
Jan 9th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "github.com/rhinoman/couchdb-go"
  6. "time"
  7. )
  8.  
  9. type APICall struct {
  10. AppId string `json:"appId"`
  11. Total int `json:"total"`
  12. Remaining int `json:"remaining"`
  13. Date string `json:"date"`
  14. Type string `json:"type"`
  15. }
  16.  
  17. func upsert() {
  18.  
  19. var timeout = time.Duration(500 * time.Millisecond)
  20. conn, err := couchdb.NewConnection("127.0.0.1", 5984, timeout)
  21. fmt.Println(err)
  22. // auth := couchdb.BasicAuth{Username: "user", Password: "password"}
  23. db := conn.SelectDB("apicalls", nil)
  24. appID := "wawan"
  25. t := time.Now()
  26. fulldate := t.Format("2006-01-02")
  27.  
  28. apiCall := APICall{
  29. AppId: appID,
  30. Total: 3000,
  31. Remaining: 2900,
  32. Date: fulldate,
  33. Type: "REST",
  34. }
  35.  
  36. theId := fmt.Sprintf("%s%sREST", appID, fulldate)
  37.  
  38. var docs interface{}
  39. rev, err := db.Read(theId, &docs, nil)
  40. if err != nil {
  41. rev, err := db.Save(apiCall, theId, "")
  42. fmt.Println(rev)
  43. fmt.Println(err)
  44. } else {
  45. rev, err := db.Save(apiCall, theId, rev)
  46. fmt.Println(rev)
  47. fmt.Println(err)
  48. }
  49.  
  50. }
  51.  
  52. func main() {
  53.  
  54. go upsert()
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement