1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/EdgexFoundry-core-data-go

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
event.go 23 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Jim White Отправлено 05.01.2018 02:31 94f698a
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
/*******************************************************************************
* Copyright 2017 Dell Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*
* @microservice: core-data-go library
* @author: Ryan Comer, Dell
* @version: 0.5.0
*******************************************************************************/
package main
import (
"encoding/json"
"net/http"
"net/url"
"strconv"
"time"
"github.com/edgexfoundry/core-data-go/clients"
"github.com/edgexfoundry/core-domain-go/models"
"github.com/gorilla/mux"
)
// Put event on the message queue to be processed by the rules engine
func putEventOnQueue(e models.Event) {
loggingClient.Info("Putting event on message queue", "")
// Have multiple implementations (start with ZeroMQ)
err := ep.SendEventMessage(e)
if err != nil {
loggingClient.Error("Unable to send message for event: " + e.String())
}
}
// Update when the device was last reported connected
func updateDeviceLastReportedConnected(device string) {
// Config set to skip update last reported
if !configuration.Deviceupdatelastconnected {
loggingClient.Debug("Skipping update of device connected/reported times for: " + device)
return
}
t := time.Now().UnixNano() / int64(time.Millisecond)
// Get the device by name
d, err := mdc.DeviceForName(device)
if err != nil {
loggingClient.Error("Error getting device " + device + ": " + err.Error())
return
}
// Couldn't find by name
if &d == nil {
// Get the device by ID
d, err = mdc.Device(device)
if err != nil {
loggingClient.Error("Error getting device " + device + ": " + err.Error())
return
}
// Couldn't find device
if &d == nil {
loggingClient.Error("Error updating device connected/reported times. Unknown device with identifier of: " + device)
return
}
// Got device by ID, now update lastReported/Connected by ID
err = mdc.UpdateLastConnected(d.Id.Hex(), t)
if err != nil {
loggingClient.Error("Problems updating last connected value for device: " + d.Id.Hex())
return
}
err = mdc.UpdateLastReported(d.Id.Hex(), t)
if err != nil {
loggingClient.Error("Problems updating last reported value for device: " + d.Id.Hex())
}
return
}
// Found by name, now update lastReported
err = mdc.UpdateLastConnectedByName(d.Name, t)
if err != nil {
loggingClient.Error("Problems updating last connected value for device: " + d.Name)
return
}
err = mdc.UpdateLastReportedByName(d.Name, t)
if err != nil {
loggingClient.Error("Problems updating last reported value for device: " + d.Name)
}
return
}
// Update when the device service was last reported connected
func updateDeviceServiceLastReportedConnected(device string) {
if !configuration.Serviceupdatelastconnected {
loggingClient.Debug("Skipping update of device service connected/reported times for: " + device)
return
}
t := time.Now().UnixNano() / int64(time.Millisecond)
// Get the device
d, err := mdc.DeviceForName(device)
if err != nil {
loggingClient.Error("Error getting device " + device + ": " + err.Error())
return
}
// Couldn't find by name
if &d == nil {
d, err = mdc.Device(device)
if err != nil {
loggingClient.Error("Error getting device " + device + ": " + err.Error())
return
}
// Couldn't find device
if &d == nil {
loggingClient.Error("Error updating device connected/reported times. Unknown device with identifier of: " + device)
return
}
}
// Get the device service
s := d.Service
if &s == nil {
loggingClient.Error("Error updating device service connected/reported times. Unknown device service in device: " + d.Id.Hex())
return
}
msc.UpdateLastConnected(s.Service.Id.Hex(), t)
msc.UpdateLastReported(s.Service.Id.Hex(), t)
}
// Delete the event and readings
func deleteEvent(e models.Event) error {
for _, reading := range e.Readings {
if err := dbc.DeleteReadingById(reading.Id.Hex()); err != nil {
return err
}
}
if err := dbc.DeleteEventById(e.ID.Hex()); err != nil {
return err
}
return nil
}
// Undocumented feature to remove all readings and events from the database
// This should primarily be used for debugging purposes
func scrubAllHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
switch r.Method {
case "DELETE":
loggingClient.Info("Deleting all events from database")
err := dbc.ScrubAllEvents()
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Error scrubbing all events/readings: " + err.Error())
return
}
encode(true, w)
}
}
/*
Handler for the event API
Status code 404 - event not found
Status code 413 - number of events exceeds limit
Status code 503 - unanticipated issues
api/v1/event
*/
func eventHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
switch r.Method {
// Get all events
case "GET":
events, err := dbc.Events()
if err != nil {
loggingClient.Error(err.Error())
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
}
// Check max limit
if len(events) > configuration.Readmaxlimit {
http.Error(w, maxExceededString, http.StatusRequestEntityTooLarge)
loggingClient.Error(maxExceededString)
return
}
encode(events, w)
break
// Post a new event
case "POST":
var e models.Event
dec := json.NewDecoder(r.Body)
err := dec.Decode(&e)
// Problem Decoding Event
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Error decoding event: " + err.Error())
return
}
loggingClient.Info("Posting Event: " + e.String())
// Get device from metadata
deviceFound := true
// Try by ID
d, err := mdc.Device(e.Device)
if err != nil {
// Try by name
d, err = mdc.DeviceForName(e.Device)
if err != nil {
deviceFound = false
}
}
// Make sure the identifier is the device name
if deviceFound {
e.Device = d.Name
}
// See if metadata checking is enabled
if configuration.Metadatacheck && !deviceFound {
loggingClient.Error("Device not found for event: "+err.Error(), "")
http.Error(w, err.Error(), http.StatusNotFound)
return
}
// Add the readings to the database
if configuration.Persistdata {
for i, reading := range e.Readings {
// Check value descriptor
_, err := dbc.ValueDescriptorByName(reading.Name)
if err != nil {
if err == clients.ErrNotFound {
http.Error(w, "Value descriptor for a reading not found", http.StatusNotFound)
} else {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
}
loggingClient.Error(err.Error())
return
}
reading.Device = e.Device // Update the device for the reading
// Add the reading
id, err := dbc.AddReading(reading)
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
e.Readings[i].Id = id // Set the ID for referencing later
}
// Add the event to the database
id, err := dbc.AddEvent(&e)
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte(id.Hex()))
} else {
encode("unsaved", w)
}
putEventOnQueue(e) // Push the aux struct to export service (It has the actual readings)
updateDeviceLastReportedConnected(e.Device) // update last reported connected (device)
updateDeviceServiceLastReportedConnected(e.Device) // update last reported connected (device service)
break
// Do not update the readings
case "PUT":
var from models.Event
dec := json.NewDecoder(r.Body)
err := dec.Decode(&from)
// Problem decoding event
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Error decoding the event: " + err.Error())
return
}
// Check if the event exists
to, err := dbc.EventById(from.ID.Hex())
if err != nil {
if err == clients.ErrNotFound {
http.Error(w, "Event not found", http.StatusNotFound)
} else {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
}
loggingClient.Error(err.Error())
return
}
loggingClient.Info("Updating event: " + from.ID.Hex())
// Update the fields
if from.Device != "" {
deviceFound := true
d, err := mdc.Device(from.Device)
if err != nil {
d, err = mdc.DeviceForName(from.Device)
if err != nil {
deviceFound = false
}
}
// See if we need to check metadata
if configuration.Metadatacheck && !deviceFound {
http.Error(w, "Error updating event: Device "+from.Device+" doesn't exist", http.StatusNotFound)
loggingClient.Error("Error updating device, device " + from.Device + " doesn't exist")
return
}
if deviceFound {
to.Device = d.Name
} else {
to.Device = from.Device
}
}
if from.Pushed != 0 {
to.Pushed = from.Pushed
}
if from.Origin != 0 {
to.Origin = from.Origin
}
// Update
if err = dbc.UpdateEvent(to); err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte("true"))
//encode(true, w)
}
}
//GET
//Return the event specified by the event ID
///api/v1/event/{id}
//id - ID of the event to return
func getEventByIdHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
switch r.Method {
case "GET":
// URL parameters
vars := mux.Vars(r)
id := vars["id"]
// Get the event
e, err := dbc.EventById(id)
if err != nil {
if err == clients.ErrNotFound {
http.Error(w, "Event not found", http.StatusNotFound)
} else {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
}
loggingClient.Error(err.Error())
return
}
// Return the result
encode(e, w)
}
}
/*
Return number of events in Core Data
/api/v1/event/count
*/
func eventCountHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
switch r.Method {
case "GET":
count, err := dbc.EventCount()
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error(), "")
return
}
// Return result
w.WriteHeader(http.StatusOK)
_, err = w.Write([]byte(strconv.Itoa(count)))
if err != nil {
loggingClient.Error(err.Error(), "")
}
}
}
/*
Return number of events for a given device in Core Data
deviceID - ID of the device to get count for
/api/v1/event/count/{deviceId}
*/
func eventCountByDeviceIdHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
vars := mux.Vars(r)
id, err := url.QueryUnescape(vars["deviceId"])
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Problem unescaping URL: " + err.Error())
return
}
switch r.Method {
case "GET":
// Get the device
// Try by ID
d, err := mdc.Device(id)
if err != nil {
// Try by Name
d, err = mdc.DeviceForName(id)
if err != nil {
loggingClient.Error("Device not found for event: "+err.Error(), "")
http.Error(w, err.Error(), http.StatusNotFound)
return
}
}
count, err := dbc.EventCountByDeviceId(d.Name)
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
// Return result
w.WriteHeader(http.StatusOK)
w.Write([]byte(strconv.Itoa(count)))
break
}
}
/*
DELETE, PUT
Handle events specified by an ID
/api/v1/event/id/{id}
404 - ID not found
*/
func eventIdHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
vars := mux.Vars(r)
id := vars["id"]
switch r.Method {
// Set the 'pushed' timestamp for the event to the current time - event is going to another (not fuse) service
case "PUT":
// Check if the event exists
e, err := dbc.EventById(id)
if err != nil {
if err == clients.ErrNotFound {
http.Error(w, "Event not found", http.StatusNotFound)
} else {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
}
loggingClient.Error(err.Error())
return
}
loggingClient.Info("Updating event: " + e.ID.Hex())
e.Pushed = time.Now().UnixNano() / int64(time.Millisecond)
err = dbc.UpdateEvent(e)
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte("true"))
//encode(true, w)
break
// Delete the event and all of it's readings
case "DELETE":
// Check if the event exists
e, err := dbc.EventById(id)
if err != nil {
if err == clients.ErrNotFound {
http.Error(w, "Event not found", http.StatusNotFound)
} else {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
}
loggingClient.Error(err.Error())
return
}
loggingClient.Info("Deleting event: " + e.ID.Hex())
if err = deleteEvent(e); err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte("true"))
//encode(true, w)
}
}
// Get event by device id
// Returns the events for the given device sorted by creation date and limited by 'limit'
// {deviceId} - the device that the events are for
// {limit} - the limit of events
// api/v1/event/device/{deviceId}/{limit}
func getEventByDeviceHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
vars := mux.Vars(r)
limit := vars["limit"]
deviceId, err := url.QueryUnescape(vars["deviceId"])
// Problems unescaping URL
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Error unescaping URL: " + err.Error())
return
}
// Convert limit to int
limitNum, err := strconv.Atoi(limit)
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Error converting to integer: " + err.Error())
return
}
// Get the device
deviceFound := true
// Try by ID
d, err := mdc.Device(deviceId)
if err != nil {
// Try by Name
d, err = mdc.DeviceForName(deviceId)
if err != nil {
deviceFound = false
}
}
if deviceFound {
deviceId = d.Name
}
// See if you need to check metadata for the device
if configuration.Metadatacheck && !deviceFound {
http.Error(w, "Error getting events for a device: The device '"+deviceId+"' doesn't exist", http.StatusNotFound)
loggingClient.Error("Error getting readings for a device: The device doesn't exist")
return
}
switch r.Method {
case "GET":
if limitNum > configuration.Readmaxlimit {
http.Error(w, maxExceededString, http.StatusRequestEntityTooLarge)
loggingClient.Error(maxExceededString)
return
}
eventList, err := dbc.EventsForDeviceLimit(deviceId, limitNum)
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
encode(eventList, w)
}
}
// Delete all of the events associated with a device
// api/v1/event/device/{deviceId}
// 404 - device ID not found in metadata
// 503 - service unavailable
func deleteByDeviceIdHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
vars := mux.Vars(r)
deviceId, err := url.QueryUnescape(vars["deviceId"])
// Problems unescaping URL
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Error unescaping the URL: " + err.Error())
return
}
// Get the device
deviceFound := true
d, err := mdc.Device(deviceId)
if err != nil {
d, err = mdc.DeviceForName(deviceId)
if err != nil {
deviceFound = false
}
}
if deviceFound {
deviceId = d.Name
}
// See if you need to check metadata
if configuration.Metadatacheck && !deviceFound {
loggingClient.Error("Device not found for event: "+err.Error(), "")
http.Error(w, err.Error(), http.StatusNotFound)
return
}
switch r.Method {
case "DELETE":
// Get the events by the device name
events, err := dbc.EventsForDevice(deviceId)
if err != nil {
loggingClient.Error(err.Error())
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
}
loggingClient.Info("Deleting the events for device: " + deviceId)
// Delete the events
count := len(events)
for _, event := range events {
if err = deleteEvent(event); err != nil {
loggingClient.Error(err.Error())
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
}
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(strconv.Itoa(count)))
}
}
// Get events by creation time
// {start} - start time, {end} - end time, {limit} - max number of results
// Sort the events by creation date
// 413 - number of results exceeds limit
// 503 - service unavailable
// api/v1/event/{start}/{end}/{limit}
func eventByCreationTimeHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
vars := mux.Vars(r)
start, err := strconv.ParseInt(vars["start"], 10, 64)
// Problems converting start time
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Problem converting start time: " + err.Error())
return
}
end, err := strconv.ParseInt(vars["end"], 10, 64)
// Problems converting end time
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Problem converting end time: " + err.Error())
return
}
limit, err := strconv.Atoi(vars["limit"])
// Problems converting limit
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Problem converting limit: " + strconv.Itoa(limit))
return
}
switch r.Method {
case "GET":
if limit > configuration.Readmaxlimit {
http.Error(w, maxExceededString, http.StatusRequestEntityTooLarge)
loggingClient.Error(maxExceededString)
return
}
e, err := dbc.EventsByCreationTime(start, end, limit)
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
encode(e, w)
}
}
// Get the readings for a device and filter them based on the value descriptor
// Only those readings whos name is the value descriptor should get through
// /event/device/{deviceId}/valuedescriptor/{valueDescriptor}/{limit}
// 413 - number exceeds limit
func readingByDeviceFilteredValueDescriptor(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
vars := mux.Vars(r)
limit := vars["limit"]
valueDescriptor, err := url.QueryUnescape(vars["valueDescriptor"])
// Problems unescaping URL
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Problem unescaping value descriptor: " + err.Error())
return
}
deviceId, err := url.QueryUnescape(vars["deviceId"])
// Problems unescaping URL
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Problem unescaping device ID: " + err.Error())
return
}
limitNum, err := strconv.Atoi(limit)
// Problem converting the limit
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Problem converting limit to integer: " + err.Error())
return
}
switch r.Method {
case "GET":
if limitNum > configuration.Readmaxlimit {
http.Error(w, maxExceededString, http.StatusRequestEntityTooLarge)
loggingClient.Error(maxExceededString)
return
}
// Get the device
deviceFound := true
// Try by id
d, err := mdc.Device(deviceId)
if err != nil {
// Try by name
d, err = mdc.DeviceForName(deviceId)
if err != nil {
deviceFound = false
}
}
if deviceFound {
deviceId = d.Name
}
// See if you need to check metadata
if configuration.Metadatacheck && !deviceFound {
loggingClient.Error("Device not found for event: "+err.Error(), "")
http.Error(w, err.Error(), http.StatusNotFound)
return
}
// Get all the events for the device
e, err := dbc.EventsForDevice(deviceId)
if err != nil {
loggingClient.Error(err.Error())
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
}
// Only pick the readings who match the value descriptor
readings := []models.Reading{}
count := 0 // Make sure we stay below the limit
for _, event := range e {
if count >= limitNum {
break
}
for _, reading := range event.Readings {
if count >= limitNum {
break
}
if reading.Name == valueDescriptor {
readings = append(readings, reading)
count += 1
}
}
}
encode(readings, w)
}
}
// Remove all the old events and associated readings (by age)
// event/removeold/age/{age}
func eventByAgeHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
vars := mux.Vars(r)
age, err := strconv.ParseInt(vars["age"], 10, 64)
// Problem converting age
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error("Error converting the age to an integer")
return
}
switch r.Method {
case "DELETE":
// Get the events
events, err := dbc.EventsOlderThanAge(age)
if err != nil {
loggingClient.Error(err.Error())
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
}
// Delete all the events
count := len(events)
for _, event := range events {
if err = deleteEvent(event); err != nil {
loggingClient.Error(err.Error())
http.Error(w, err.Error(), http.StatusServiceUnavailable)
return
}
}
loggingClient.Info("Deleting events by age: " + vars["age"])
// Return the count
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(strconv.Itoa(count)))
}
}
// Scrub all the events that have been pushed
// Also remove the readings associated with the events
// api/v1/event/scrub
func scrubHandler(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
switch r.Method {
case "DELETE":
loggingClient.Info("Scrubbing events. Deleting all events that have been pushed")
// Get the events
events, err := dbc.EventsPushed()
if err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
// Delete all the events
count := len(events)
for _, event := range events {
if err = deleteEvent(event); err != nil {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
loggingClient.Error(err.Error())
return
}
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(strconv.Itoa(count)))
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/EdgexFoundry-core-data-go.git
git@api.gitlife.ru:oschina-mirror/EdgexFoundry-core-data-go.git
oschina-mirror
EdgexFoundry-core-data-go
EdgexFoundry-core-data-go
master