cloudant

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2019 License: MIT Imports: 11 Imported by: 0

README

GoCloudant

Codacy Badge An HTTP client for manage Cloudant DB among IBM Cloud

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteDocument

func DeleteDocument(token, url, databaseName, _id, _rev string) string

DeleteDocument is delegated to retrieve a specific document by the related `_id` https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-documents#delete-a-document token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance databaseName: DB that we want to retrieve the information _id: Key for retrieve the document

func GetAllDBs

func GetAllDBs(token, url string) []string

GetAllDBs is delegated to fetch and retrieve all DB(s) name from the Cloudant instance https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-databases#get-a-list-of-all-databases-in-the-account token: bearer auth header retrieved from RetrieveToken() host: URL related to the DB instance

func GetAllDocuments

func GetAllDocuments(token, url, dbName string) string

GetAllDocuments is delegated to retrieve all documents associated to the given DB https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-databases#get-documents token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance dbName: DB that we want to retrieve the information

func GetDBDetails

func GetDBDetails(token, url, dbName string) string

GetDBDetails is delegated to retrieve the information related to the given DB https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-databases#getting-database-details token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance dbName: DB that we want to retrieve the information

func GetDocument

func GetDocument(token, url, databaseName, _id string) string

GetDocument is delegated to retrieve a specific document by the related mandatory `_id` https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-documents#read-document token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance databaseName: DB that we want to retrieve the information _id: Key for retrieve the document

func InsertBulkDocument

func InsertBulkDocument(token, url, dbName string, jsons []string) string

InsertBulkDocument is delegated to insert a list of document. It will concatenate all the json in input and will insert all the document in a single request token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance dbName: DB that we want to retrieve the information jsons: list of document that we want to insert in bulk

func InsertDocument

func InsertDocument(token, url, databaseName string, json []byte) bool

InsertDocument is delegated to insert a new document into the given DB https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-documents#create-document token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance databaseName: DB that we want to retrieve the information json: document to insert

func RemoveDB

func RemoveDB(token, dbName, url string) bool

RemoveDB is delegated to delete the given DB https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-databases#deleting-a-database token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance dbName: DB that we want to retrieve the information

func UpdateDocument

func UpdateDocument(token, url, databaseName, _id string) string

UpdateDocument is delegated to update a specific document by the related mandatory '_id' parameter https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-documents#update token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance databaseName: DB that we want to retrieve the information _id: Key for retrieve the document

Types

type Auth

type Auth struct {
	// USER:PASSWORD encoded for basic auth (basic auth headers)
	BasicAuth string
	// Cookie for authenticate the session (cookie)
	SessionCookie string
	// IAM Token related to IBM Cloud service (bearer auth headers)
	IAMToken string
	// URL related to the Cloudant instance DB
	DBUrl string
}

Auth is delegated to store the necessary token for authenticate to the service Cloudant HTTP call can be made using one of authentication credential

func (Auth) CreateDB

func (auth Auth) CreateDB(dbName string, partitioned bool) bool

CreateDB is delegated to initializate a new database. https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-databases#create-database token: bearer auth header retrieved from RetrieveToken() url: URL related to the DB instance dbName: DB that we want to retrieve the information partitioned: boolean value for enabled partitioned option

func (Auth) GetSessionInfo

func (auth Auth) GetSessionInfo() string

GetSessionInfo is delegated to retrieve the information related to the current session

func (Auth) PingCloudant

func (auth Auth) PingCloudant() bool

PingCloudant is delegated to verify that the Cloudant DB instance can be reached token: bearer auth header retrieved from RetrieveToken() host: URL related to the DB instance

type Conf

type Conf struct {
	// Key used for retrieve the bearer token
	Apikey string `json:"apikey"`
	// Hostname of the cloudant instance
	Host                 string `json:"host"`
	IAMApikeyDescription string `json:"iam_apikey_description"`
	IAMApikeyName        string `json:"iam_apikey_name"`
	IAMRoleCrn           string `json:"iam_role_crn"`
	IAMServiceidCrn      string `json:"iam_serviceid_crn"`
	// Password for authenticate to the service
	Password string `json:"password"`
	// Port for reach the server
	Port int `json:"port"`
	// Url using BasicAuth, avoid using this url with basicauth for performance
	URL string `json:"url"`
	// Username related to the Cloudant instance
	Username string `json:"username"`
}

Conf is delegated to save the information related to the Cloudant account

func (Conf) GenerateCookie

func (conf Conf) GenerateCookie(URL string) string

GenerateCookie is delegated to inititialize a new session cookie based https://cloud.ibm.com/docs/services/Cloudant?topic=cloudant-authentication#cookie-authentication The method use the username and password for initialize a new Cloudant session for authenticate into IBM Cloud Cloudant instance that have to be used as Authorization token NOTE: Every request have to be sent using the token retrieved by this method as a 'Bearer Authorization"

func (Conf) GenerateIBMToken

func (conf Conf) GenerateIBMToken() string

GenerateIBMToken is delegated to retrieve the token for authenticate the HTTP request. It can be used for 3600 seconds https://cloud.ibm.com/docs/iam?topic=iam-iamtoken_from_apikey The method use the apikey related to your Cloudant instance for authenticate into the IBM Cloud, and return back the token that have to be used as Authorization token NOTE: Every request have to be sent using the token retrieved by this method as a 'Bearer Authorization"

func (Conf) InitAuth

func (conf Conf) InitAuth() Auth

InitAuth is delegated to initialize the Authentication details for authenticate every request. The method will initialize the three method for authenticate the HTTP request: - BasicAuth -> Create the header for authenticate the request - SessionCookie -> Initialize a new session cookie-based and return the cookie for authenticate the request - IAMToken -> Retrieve the IAM token that expire after 3600 seconds

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL