本文整理汇总了Golang中duov6/com/objectstore/messaging.ObjectRequest类的典型用法代码示例。如果您正苦于以下问题:Golang ObjectRequest类的具体用法?Golang ObjectRequest怎么用?Golang ObjectRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setOneRedisExcel
func setOneRedisExcel(request *messaging.ObjectRequest) RepositoryResponse {
response := RepositoryResponse{}
client, isError, errorMessage := getRedisExcelConnection(request)
if isError == true {
response.GetErrorResponse(errorMessage)
} else {
key := request.Controls.Namespace + "." + request.Controls.Class + "." + request.Controls.Id
value := getStringByObject(request, request.Body.Object)
err := client.Set(key, value, 0, 0, false, false)
if err != nil {
response.IsSuccess = false
request.Log("Error inserting/updating object in Redis : " + key + ", " + err.Error())
response.GetErrorResponse("Error inserting/updating one object in Redis" + err.Error())
} else {
response.IsSuccess = true
response.Message = "Successfully inserted/updated one object in Redis"
request.Log(response.Message)
}
}
return response
}
示例2: GetByKey
func (repository CouchRepository) GetByKey(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting GET-BY-KEY")
response := RepositoryResponse{}
bucket, errorMessage, isError := getCouchBucket(request)
if isError == true {
response.GetErrorResponse(errorMessage)
} else {
key := request.Controls.Namespace + "." + request.Controls.Class + "." + request.Controls.Id
rawBytes, err := bucket.GetRaw(key)
var returnData map[string]interface{}
returnData = make(map[string]interface{})
json.Unmarshal(rawBytes, &returnData)
if request.Controls.SendMetaData == "false" {
delete(returnData, "__osHeaders")
}
rawBytes, err = json.Marshal(returnData)
if err != nil {
response.GetErrorResponse("Error retrieving object from couchbase")
} else {
response.GetResponseWithBody(rawBytes)
}
}
return response
}
示例3: GetQuery
func (repository ElasticRepository) GetQuery(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting GET-QUERY!")
response := RepositoryResponse{}
queryType := request.Body.Query.Type
switch queryType {
case "Query":
if request.Body.Query.Parameters != "*" {
fieldsInByte := executeElasticQuery(request)
if fieldsInByte != nil {
response.IsSuccess = true
response.Message = "Successfully Retrieved Data For Custom Query"
response.GetResponseWithBody(fieldsInByte)
} else {
response.IsSuccess = false
response.Message = "Aborted! Unsuccessful Retrieving Data For Custom Query"
errorMessage := response.Message
response.GetErrorResponse(errorMessage)
}
} else {
//Check if just STAR then execute GET-SEARCH method
request.Log("Redirecting to GET-SEARCH!")
return search(request, request.Body.Query.Parameters)
}
default:
return search(request, request.Body.Query.Parameters)
}
return response
}
示例4: GetQuery
func (repository PostgresRepository) GetQuery(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting GET-QUERY")
response := RepositoryResponse{}
queryType := request.Body.Query.Type
switch queryType {
case "Query":
if request.Body.Query.Parameters != "*" {
fieldsInByte := executePostgresQuery(request)
if fieldsInByte != nil {
response.IsSuccess = true
response.Message = "Successfully Retrieved Data For Custom Query"
response.GetResponseWithBody(fieldsInByte)
} else {
response.IsSuccess = false
response.Message = "Aborted! Unsuccessful Retrieving Data For Custom Query"
errorMessage := response.Message
response.GetErrorResponse(errorMessage)
}
} else {
return repository.GetAll(request)
}
default:
request.Log(queryType + " not implemented in Postgres_SQL Db repository")
return getDefaultNotImplemented()
}
return response
}
示例5: setOneRedis
func setOneRedis(request *messaging.ObjectRequest) RepositoryResponse {
response := RepositoryResponse{}
client, isError, errorMessage := getRedisConnection(request)
keyValue := getRedisRecordID(request, nil)
if isError == true {
response.GetErrorResponse(errorMessage)
} else if keyValue != "" {
key := request.Controls.Namespace + "." + request.Controls.Class + "." + keyValue
request.Body.Object[request.Body.Parameters.KeyProperty] = keyValue
value := getStringByObject(request.Body.Object)
err := client.Set(key, value, 0, 0, false, false)
if err != nil {
response.IsSuccess = false
request.Log("Error inserting/updating object in Redis : " + key + ", " + err.Error())
response.GetErrorResponse("Error inserting/updating one object in Redis" + err.Error())
} else {
response.IsSuccess = true
response.Message = "Successfully inserted/updated one object in Redis"
request.Log(response.Message)
}
}
//Update Response
var Data []map[string]interface{}
Data = make([]map[string]interface{}, 1)
var actualData map[string]interface{}
actualData = make(map[string]interface{})
actualData["ID"] = keyValue
Data[0] = actualData
response.Data = Data
return response
}
示例6: InsertSingle
func (repository MongoRepository) InsertSingle(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting INSERT-SINGLE")
response := RepositoryResponse{}
collection, isError, errorMessage := getMongoConnection(request)
key := getMongoDBRecordID(request, nil)
if isError == true {
response.GetErrorResponse(errorMessage)
} else if key != "" {
request.Body.Object[request.Body.Parameters.KeyProperty] = key
request.Body.Object["_id"] = request.Controls.Namespace + "." + request.Controls.Class + "." + key
err := collection.Insert(bson.M(request.Body.Object))
if err != nil {
response.IsSuccess = false
response.GetErrorResponse("Error inserting one object in mongo" + err.Error())
} else {
response.IsSuccess = true
response.Message = "Successfully inserted one object in Mongo"
request.Log(response.Message)
}
}
var Data []map[string]interface{}
Data = make([]map[string]interface{}, 1)
var actualData map[string]interface{}
actualData = make(map[string]interface{})
actualData["ID"] = key
Data[0] = actualData
response.Data = Data
return response
}
示例7: GetByKey
func (repository CassandraRepository) GetByKey(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting Get-BY-KEY!")
response := RepositoryResponse{}
session, isError, errorMessage := getCassandraConnection(request)
if isError == true {
response.GetErrorResponse(errorMessage)
} else {
isError = false
//get primary key field name
iter := session.Query("select type, column_name from system.schema_columns WHERE keyspace_name='" + getSQLnamespace(request) + "' AND columnfamily_name='" + request.Controls.Class + "'").Iter()
my1, _ := iter.SliceMap()
iter.Close()
fieldName := ""
for _, value := range my1 {
if value["type"].(string) == "partition_key" {
fieldName = value["column_name"].(string)
break
}
}
parameter := request.Controls.Id
iter2 := session.Query("SELECT * FROM " + request.Controls.Class + " where " + fieldName + " = '" + parameter + "'").Iter()
my, isErr := iter2.SliceMap()
iter2.Close()
if request.Controls.SendMetaData == "false" {
for index, arrVal := range my {
for key, _ := range arrVal {
if key == "osheaders" {
delete(my[index], key)
}
}
}
}
byteValue, errMarshal := json.Marshal(my)
if errMarshal != nil {
response.IsSuccess = false
response.GetErrorResponse("Error getting values for one object in Cassandra" + isErr.Error())
} else {
response.IsSuccess = true
response.GetResponseWithBody(byteValue)
response.Message = "Successfully retrieved values for one object in Cassandra"
request.Log(response.Message)
}
}
return response
}
示例8: GetAll
func (repository CassandraRepository) GetAll(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting GET-ALL!")
response := RepositoryResponse{}
session, isError, errorMessage := getCassandraConnection(request)
if isError == true {
response.GetErrorResponse(errorMessage)
} else {
isError = false
iter2 := session.Query("SELECT * FROM " + request.Controls.Class).Iter()
my, isErr := iter2.SliceMap()
iter2.Close()
skip := 0
if request.Extras["skip"] != nil {
skip, _ = strconv.Atoi(request.Extras["skip"].(string))
}
take := len(my)
if request.Extras["take"] != nil {
take, _ = strconv.Atoi(request.Extras["take"].(string))
}
fmt.Println(reflect.TypeOf(my))
if request.Controls.SendMetaData == "false" {
for index, arrVal := range my {
for key, _ := range arrVal {
if key == "osheaders" {
delete(my[index], key)
}
}
}
}
byteValue, errMarshal := json.Marshal(my[skip:(skip + take)])
if errMarshal != nil {
response.IsSuccess = false
response.GetErrorResponse("Error getting values for all objects in Cassandra" + isErr.Error())
} else {
response.IsSuccess = true
response.GetResponseWithBody(byteValue)
response.Message = "Successfully retrieved values for all objects in Cassandra"
request.Log(response.Message)
}
}
return response
}
示例9: Store
func (r QueuedStorageEngine) Store(request *messaging.ObjectRequest) (response repositories.RepositoryResponse) {
conn, err := amqp.Dial("amqp://guest:[email protected]:5672/")
failOnError(err, "Failed to connect to RabbitMQ")
defer conn.Close()
ch, err := conn.Channel()
failOnError(err, "Failed to open a channel")
defer ch.Close()
err = ch.ExchangeDeclare(
"publisher_01", // name
"direct", // type
true, // durable
false, // auto-deleted
false, // internal
false, // no-wait
nil, // arguments
)
failOnError(err, "Failed to declare an exchange")
body, errMarshal := json.Marshal(request)
if errMarshal != nil {
response.Message = "Conversion to JSON failed!"
request.Log(response.Message)
} else {
response.Message = "Conversion to JSON Success!"
request.Log(response.Message)
log.Printf(" [x] Sent %s", body)
}
err = ch.Publish(
"publisher_01", // exchange
"Queued", // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
// ContentType: "text/plain",
ContentType: "*messaging.ObjectRequest",
Body: body,
})
failOnError(err, "Failed to publish a message")
if err == nil {
response.IsSuccess = true
}
//log.Printf(" [x] Sent %s", body)
return response
}
示例10: getRedisConnection
func getRedisConnection(request *messaging.ObjectRequest) (client *goredis.Redis, isError bool, errorMessage string) {
isError = false
client, err := goredis.DialURL("tcp://@" + request.Configuration.ServerConfiguration["REDIS"]["Host"] + ":" + request.Configuration.ServerConfiguration["REDIS"]["Port"] + "/0?timeout=10s&maxidle=1")
if err != nil {
isError = true
errorMessage = err.Error()
request.Log("Error! Can't connect to server!error")
}
request.Log("Reusing existing GoRedis connection")
return
}
示例11: DeleteMultiple
func (repository ElasticRepository) DeleteMultiple(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting DELETE-MULTIPLE")
response := RepositoryResponse{}
conn := getConnection()(request)
for _, object := range request.Body.Objects {
key := getNoSqlKeyById(request, object)
request.Log("Deleting single object from Elastic Search : " + key)
_, err := conn.Delete(request.Controls.Namespace, request.Controls.Class, key, nil)
_, err = conn.Delete(getKibanaElasticName(request), getKibanaElasticName(request), key, nil)
if err != nil {
errorMessage := "Elastic Search single delete error : " + err.Error()
request.Log(errorMessage)
response.GetErrorResponse(errorMessage)
} else {
response.IsSuccess = true
response.Message = "Successfully deleted one in elastic search"
request.Log(response.Message)
}
}
return response
}
示例12: DeleteSingle
func (repository CouchRepository) DeleteSingle(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting DELETE-SINGLE")
response := RepositoryResponse{}
bucket, errorMessage, isError := getCouchBucket(request)
if isError == true {
response.GetErrorResponse(errorMessage)
} else {
key := request.Controls.Namespace + "." + request.Controls.Class + "." + request.Controls.Id
request.Log("Deleting object from couchbase : " + key)
err := bucket.Delete(key)
if err != nil {
response.IsSuccess = false
request.Log("Error deleting object from couchbase : " + key + ", " + err.Error())
response.GetErrorResponse("Error deleting one object in Couchbase" + err.Error())
} else {
response.IsSuccess = true
response.Message = "Successfully deleted one object in Coucahbase"
request.Log(response.Message)
}
}
return response
}
示例13: UpdateMultiple
func (repository MysqlRepository) UpdateMultiple(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting UPDATE-MULTIPLE")
response := RepositoryResponse{}
session, isError, errorMessage := getMysqlConnection(request)
if isError == true {
response.GetErrorResponse(errorMessage)
} else {
for i := 0; i < len(request.Body.Objects); i++ {
noOfElements := len(request.Body.Objects[i]) - 1
var keyUpdate = make([]string, noOfElements)
var valueUpdate = make([]string, noOfElements)
var startIndex = 0
for key, value := range request.Body.Objects[i] {
if key != request.Body.Parameters.KeyProperty {
if key != "__osHeaders" {
keyUpdate[startIndex] = key
valueUpdate[startIndex] = value.(string)
startIndex = startIndex + 1
} else {
keyUpdate[startIndex] = "osHeaders"
valueUpdate[startIndex] = ConvertOsheaders(value.(messaging.ControlHeaders))
startIndex = startIndex + 1
}
}
}
var argValueList string
//Build the query string
for i := 0; i < noOfElements; i++ {
if i != noOfElements-1 {
argValueList = argValueList + keyUpdate[i] + " = " + "'" + valueUpdate[i] + "'" + ", "
} else {
argValueList = argValueList + keyUpdate[i] + " = " + "'" + valueUpdate[i] + "'"
}
}
//DEBUG USE : Display Query information
// fmt.Println("Table Name : " + request.Controls.Class)
// fmt.Println("Value list : " + argValueList)
request.Log("UPDATE " + getSQLnamespace(request) + "." + request.Controls.Class + " SET " + argValueList + " WHERE " + request.Body.Parameters.KeyProperty + " =" + "'" + request.Body.Objects[i][request.Body.Parameters.KeyProperty].(string) + "'")
_, err := session.Query("UPDATE " + getSQLnamespace(request) + "." + request.Controls.Class + " SET " + argValueList + " WHERE " + request.Body.Parameters.KeyProperty + " =" + "'" + request.Body.Objects[i][request.Body.Parameters.KeyProperty].(string) + "'")
if err != nil {
response.IsSuccess = false
request.Log("Error updating object in MySQL : " + getNoSqlKey(request) + ", " + err.Error())
response.GetErrorResponse("Error updating one object in MySQL because no match was found!" + err.Error())
} else {
response.IsSuccess = true
response.Message = "Successfully updating one object in MySQL "
request.Log(response.Message)
}
}
}
return response
}
示例14: DeleteMultiple
func (repository CouchRepository) DeleteMultiple(request *messaging.ObjectRequest) RepositoryResponse {
request.Log("Starting DELETE_MULTIPLE")
response := RepositoryResponse{}
bucket, errorMessage, isError := getCouchBucket(request)
if isError == true {
response.GetErrorResponse(errorMessage)
} else {
for _, obj := range request.Body.Objects {
key := getNoSqlKeyById(request, obj)
request.Log("Deleting object from couchbase : " + key)
err := bucket.Delete(key)
if err != nil {
response.IsSuccess = false
request.Log("Error deleting object from couchbase : " + key + ", " + err.Error())
response.GetErrorResponse("Error deleting Multiple objects in Couchbase" + err.Error())
} else {
response.IsSuccess = true
response.Message = "Successfully deleted Multiple objects in Coucahbase"
request.Log(response.Message)
}
}
}
return response
}
示例15: getRedisExcelConnection
func getRedisExcelConnection(request *messaging.ObjectRequest) (client *goredis.Redis, isError bool, errorMessage string) {
isError = false
client, err := goredis.DialURL("tcp://@127.0.0.1:6379/0?timeout=10s&maxidle=1")
if err != nil {
isError = true
errorMessage = err.Error()
request.Log("Error! Can't connect to server!error")
}
request.Log("Reusing existing GoRedis connection")
return
}