Fix server error message, go fmt
This commit is contained in:
parent
ad8156210f
commit
3a166dbc9a
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type AsinkDB struct {
|
||||
db *sql.DB
|
||||
db *sql.DB
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const MIN_ERROR_WAIT = 100 // 1/10 of a second
|
||||
const MIN_ERROR_WAIT = 100 // 1/10 of a second
|
||||
const MAX_ERROR_WAIT = 10000 // 10 seconds
|
||||
|
||||
func SendEvent(globals AsinkGlobals, event *asink.Event) error {
|
||||
@ -68,7 +68,7 @@ func GetEvents(globals AsinkGlobals, events chan *asink.Event) {
|
||||
}
|
||||
|
||||
//query DB for latest remote event version number that we've seen locally
|
||||
latestEvent, err := globals.db.DatabaseLatestRemoteEvent()
|
||||
latestEvent, err := globals.db.DatabaseLatestRemoteEvent()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -77,7 +77,7 @@ func GetEvents(globals AsinkGlobals, events chan *asink.Event) {
|
||||
//query for events after latest_event
|
||||
var fullUrl string
|
||||
if latestEvent != nil {
|
||||
fullUrl = url + strconv.FormatInt(latestEvent.Id + 1, 10)
|
||||
fullUrl = url + strconv.FormatInt(latestEvent.Id+1, 10)
|
||||
} else {
|
||||
fullUrl = url + "0"
|
||||
}
|
||||
@ -110,9 +110,8 @@ func GetEvents(globals AsinkGlobals, events chan *asink.Event) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
for _, event := range apistatus.Events {
|
||||
if latestEvent != nil && event.Id != latestEvent.Id + 1 {
|
||||
if latestEvent != nil && event.Id != latestEvent.Id+1 {
|
||||
break
|
||||
}
|
||||
events <- event
|
||||
|
@ -42,7 +42,7 @@ func addPoller(uid string, channel *chan *asink.Event) {
|
||||
}
|
||||
|
||||
//set timer to call function after one minute
|
||||
timeout := time.Duration(1)*time.Minute
|
||||
timeout := time.Duration(1) * time.Minute
|
||||
time.AfterFunc(timeout, func() {
|
||||
group.lock.Lock()
|
||||
for i, c := range group.channels {
|
||||
|
@ -128,6 +128,9 @@ func putEvents(w http.ResponseWriter, r *http.Request) {
|
||||
for _, event := range events.Events {
|
||||
err = DatabaseAddEvent(db, event)
|
||||
if err != nil {
|
||||
//TODO should probably do this in a way that the caller knows how many of these have failed and doesn't re-try sending ones that succeeded
|
||||
//i.e. add this to the return codes or something
|
||||
//OR put all the DatabaseAddEvent's inside a SQL transaction, and rollback on any failure
|
||||
error_message = err.Error()
|
||||
return
|
||||
}
|
||||
@ -154,6 +157,11 @@ func eventHandler(w http.ResponseWriter, r *http.Request) {
|
||||
} else if r.Method == "POST" {
|
||||
putEvents(w, r)
|
||||
} else {
|
||||
fmt.Fprintf(w, "You f-ed up.")
|
||||
apiresponse := asink.APIResponse{
|
||||
Status: asink.ERROR,
|
||||
Explanation: "Invalid HTTP method - only GET and POST are supported on this endpoint.",
|
||||
}
|
||||
b, _ := json.Marshal(apiresponse)
|
||||
w.Write(b)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user