err:=conn.QueryRow("SELECT creator, created, edited, content, title FROM notes WHERE id = ? LIMIT 1",id).Scan(&creator,&created,&edited,&content,&title)
iferr!=nil{
return0,"","","","",err
}
returncreator,created,edited,content,title,err
}
funcgetSpace(idint)(int,error){
varspaceint
err:=conn.QueryRow("SELECT COALESCE(SUM(LENGTH(content) + LENGTH(title)), 0) FROM notes WHERE creator = ?",id).Scan(&space)
iferr!=nil{
return0,err
}
returnspace,nil
}
funcgetNoteCount(idint)(int,error){
varcountint
err:=conn.QueryRow("SELECT COUNT(*) FROM notes WHERE creator = ?",id).Scan(&count)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SIGNUP-VERSIONCHECK"})
c.JSON(422,gin.H{"error":"Invalid username or password"})
return
}
_,taken,err:=checkUsernameTaken(username)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/signup checkUsernameTaken() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SIGNUP-USERTAKEN"})
return
}
iftaken{
c.JSON(409,gin.H{"error":"Username is taken"})
return
}
salt,err:=genSalt(16)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/signup genSalt() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SIGNUP-SALT"})
return
}
hashedPasswd,err:=hash(password,salt)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/signup hash() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SIGNUP-HASH"})
log.Println("[ERROR] Unknown in /api/signup Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SIGNUP-DBINSERT"})
return
}
log.Println("[INFO] Added new user at",time.Now().Unix())
userid,taken,err:=checkUsernameTaken(username)
if!taken{
log.Println("[CRITICAL] Something is very wrong! A user was created but could not be found in the database at",time.Now().Unix())
log.Println("[INFO] This should not be possible. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes with the error code: UNKNOWN-API-SIGNUP-POSTTAKEN")
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SIGNUP-POSTTAKEN"})
return
}
token,err:=genSalt(512)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/signup token genSalt() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SIGNUP-SESSIONSALT"})
return
}
_,err=conn.Exec("INSERT INTO sessions (session, id, device) VALUES (?, ?, ?)",token,userid,c.Request.Header.Get("User-Agent"))
iferr!=nil{
log.Println("[ERROR] Unknown in /api/signup session Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SIGNUP-SESSIONINSERT"})
log.Println("[ERROR] Unknown in /api/login versionCheck at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-VERSIONCHECK"})
log.Println("[ERROR] Unknown in /api/login checkUsernameTaken() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-USERTAKEN"})
log.Println("[ERROR] Unknown in /api/login getUser() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-GETUSER"})
log.Println("[ERROR] Unknown in /api/login verifyHash() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-VERIFYHASH"})
return
}
}
if!correctPassword{
c.JSON(401,gin.H{"error":"Incorrect password"})
return
}
}else{
varlegacyPasswordstring
err=conn.QueryRow("SELECT versionTwoLegacyPassword FROM users WHERE id = ?",userid).Scan(&legacyPassword)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/login legacyPassword query at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-LEGACYQUERY"})
log.Println("[ERROR] Unknown in /api/login verifyHash() legacy at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-VERIFYHASH"})
log.Println("[ERROR] Unknown in /api/login genSalt() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-SALT"})
log.Println("[ERROR] Unknown in /api/login hash() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-HASH"})
return
}
_,err=conn.Exec("UPDATE users SET password = ? WHERE id = ?",hashedPassword,userid)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/login Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-DBUPDATE"})
log.Println("[ERROR] Unknown in /api/login token genSalt() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-SESSIONSALT"})
return
}
_,err=conn.Exec("INSERT INTO sessions (session, id, device) VALUES (?, ?, ?)",token,userid,c.Request.Header.Get("User-Agent"))
iferr!=nil{
log.Println("[ERROR] Unknown in /api/login session Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-SESSIONINSERT"})
err=conn.QueryRow("SELECT versionTwoLegacyPassword FROM users WHERE id = ?",userid).Scan(&legacyPassword)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/login legacyPassword query at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-LEGACYQUERY"})
log.Println("[ERROR] Unknown in /api/login versionCheck at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-ADDLEGACYPASSWORD-VERSIONCHECK"})
return
}
ifversionCheckInt<200{
c.JSON(400,gin.H{"error":"This API can only be accessed by Burgernotes 2.0 and above"})
return
}
}else{
c.JSON(400,gin.H{"error":"This API can only be accessed by Burgernotes 2.0 and above"})
return
}
token:=data["secretKey"].(string)
legacyPassword:=data["legacyPassword"].(string)
_,userid,err:=getSession(token)
iferr!=nil{
c.JSON(401,gin.H{"error":"Invalid session"})
return
}
_,err=conn.Exec("UPDATE users SET versionTwoLegacyPassword = ? WHERE id = ?",legacyPassword,userid)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/login/addlegacypassword Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LOGIN-ADDLEGACYPASSWORD"})
log.Println("[ERROR] Unknown in /api/changepassword genSalt() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-CHANGEPASSWORD-SALT"})
return
}
hashedPassword,err:=hash(newPassword,salt)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/changepassword hash() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-CHANGEPASSWORD-HASH"})
return
}
_,err=conn.Exec("UPDATE users SET password = ? WHERE id = ?",hashedPassword,userid)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/changepassword Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-CHANGEPASSWORD-DBUPDATE"})
log.Println("[ERROR] Unknown in /api/userinfo getUser() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-USERINFO-GETUSER"})
return
}
space,err:=getSpace(userid)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/userinfo getSpace() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-USERINFO-GETSPACE"})
return
}
notecount,err:=getNoteCount(userid)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/userinfo getNoteCount() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-USERINFO-GETNOTECOUNT"})
log.Println("[ERROR] Unknown in /api/listnotes query at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTNOTES-DBQUERY"})
return
}
}
deferfunc(rows*sql.Rows){
err:=rows.Close()
iferr!=nil{
log.Println("[ERROR] Unknown in /api/listnotes row defer at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTNOTES-ROWCLOSE"})
return
}
}(rows)
varnotes[]map[string]interface{}
forrows.Next(){
varidint
vartitlestring
iferr:=rows.Scan(&id,&title);err!=nil{
log.Println("[ERROR] Unknown in /api/listnotes row scan at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTNOTES-ROWSCAN"})
log.Println("[ERROR] Unknown in /api/listnotes row iteration at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTNOTES-ROWERR"})
rows,err:=conn.Query("SELECT id, created, edited, title, content FROM notes WHERE creator = ? ORDER BY edited DESC",userid)
iferr!=nil{
iferrors.Is(err,sql.ErrNoRows){
c.JSON(200,[]map[string]interface{}{})
return
}else{
log.Println("[ERROR] Unknown in /api/exportnotes query at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-EXPORTNOTES-DBQUERY"})
return
}
}
deferfunc(rows*sql.Rows){
err:=rows.Close()
iferr!=nil{
log.Println("[ERROR] Unknown in /api/exportnotes row defer at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-EXPORTNOTES-ROWCLOSE"})
log.Println("[ERROR] Unknown in /api/exportnotes row scan at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-EXPORTNOTES-ROWSCAN"})
log.Println("[ERROR] Unknown in /api/exportnotes row iteration at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-EXPORTNOTES-ROWERR"})
log.Println("[ERROR] Unknown in /api/importnotes Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-IMPORTNOTES-DBINSERT"})
log.Println("[ERROR] Unknown in /api/newnote Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-NEWNOTE-DBINSERT"})
return
}else{
c.JSON(200,gin.H{"success":true})
}
}
})
router.POST("/api/readnote",func(c*gin.Context){
vardatamap[string]interface{}
err:=c.ShouldBindJSON(&data)
iferr!=nil{
c.JSON(400,gin.H{"error":"Invalid JSON"})
return
}
token:=data["secretKey"].(string)
noteId:=int(data["noteId"].(float64))
_,userid,err:=getSession(token)
iferr!=nil{
c.JSON(401,gin.H{"error":"Invalid session"})
return
}
creator,_,_,content,_,err:=getNote(noteId)
iferr!=nil{
iferrors.Is(err,sql.ErrNoRows){
c.JSON(422,gin.H{"error":"Note not found"})
return
}else{
log.Println("[ERROR] Unknown in /api/readnote getNote() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-READNOTE-GETNOTE"})
return
}
}else{
ifcreator!=userid{
c.JSON(422,gin.H{"error":"Note does not belong to user"})
return
}else{
c.JSON(200,gin.H{"content":content})
}
}
})
router.POST("/api/editnote",func(c*gin.Context){
vardatamap[string]interface{}
err:=c.ShouldBindJSON(&data)
iferr!=nil{
c.JSON(400,gin.H{"error":"Invalid JSON"})
return
}
token:=data["secretKey"].(string)
noteId:=int(data["noteId"].(float64))
content:=data["content"].(string)
title:=data["title"].(string)
_,userid,err:=getSession(token)
iferr!=nil{
c.JSON(401,gin.H{"error":"Invalid session"})
return
}
creator,_,_,_,_,err:=getNote(noteId)
iferr!=nil{
iferrors.Is(err,sql.ErrNoRows){
c.JSON(422,gin.H{"error":"Note not found"})
return
}else{
log.Println("[ERROR] Unknown in /api/editnote getNote() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-EDITNOTE-GETNOTE"})
return
}
}
ifcreator!=userid{
c.JSON(403,gin.H{"error":"Note does not belong to user"})
return
}else{
_,err:=conn.Exec("UPDATE notes SET content = ?, title = ?, edited = ? WHERE id = ?",content,title,strconv.FormatInt(time.Now().Unix(),10),noteId)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/editnote Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-EDITNOTE-DBUPDATE"})
log.Println("[ERROR] Unknown in /api/removenote getNote() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-REMOVENOTE-GETNOTE"})
return
}
}
ifcreator!=userid{
c.JSON(403,gin.H{"error":"Note does not belong to user"})
return
}else{
_,err:=conn.Exec("DELETE FROM notes WHERE id = ?",noteId)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/removenote Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-REMOVENOTE-DBDELETE"})
_,err=conn.Exec("DELETE FROM notes WHERE creator = ?",userid)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/deleteaccount notes Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-DELETEACCOUNT-NOTESDELETE"})
return
}
_,err=conn.Exec("DELETE FROM users WHERE id = ?",userid)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/deleteaccount user Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-DELETEACCOUNT-USERDELETE"})
return
}
_,err=conn.Exec("DELETE FROM sessions WHERE id = ?",userid)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/deleteaccount session Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-DELETEACCOUNT-SESSIONDELETE"})
rows,err:=conn.Query("SELECT sessionid, session, device FROM sessions WHERE id = ? ORDER BY id DESC",userid)
iferr!=nil{
iferrors.Is(err,sql.ErrNoRows){
c.JSON(200,[]map[string]interface{}{})
return
}else{
log.Println("[ERROR] Unknown in /api/sessions/list query at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SESSIONS-LIST-DBQUERY"})
return
}
}
deferfunc(rows*sql.Rows){
err:=rows.Close()
iferr!=nil{
log.Println("[ERROR] Unknown in /api/sessions/list row defer at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SESSIONS-LIST-ROWCLOSE"})
log.Println("[ERROR] Unknown in /api/sessions/list row scan at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SESSIONS-LIST-ROWSCAN"})
log.Println("[ERROR] Unknown in /api/sessions/list row iteration at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SESSIONS-LIST-ROWERR"})
c.JSON(422,gin.H{"error":"Target session not found"})
return
}else{
log.Println("[ERROR] Unknown in /api/sessions/remove getSession() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SESSIONS-REMOVE-GETSESSION"})
return
}
}else{
ifcreator!=userid{
c.JSON(403,gin.H{"error":"Session does not belong to user"})
return
}else{
_,err:=conn.Exec("DELETE FROM sessions WHERE sessionid = ?",sessionId)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/sessions/remove Exec() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-SESSIONS-REMOVE-DBDELETE"})
return
}else{
c.JSON(200,gin.H{"success":true})
}
}
}
})
router.POST("/api/listusers",func(c*gin.Context){
vardatamap[string]interface{}
err:=c.ShouldBindJSON(&data)
iferr!=nil{
c.JSON(400,gin.H{"error":"Invalid JSON"})
return
}
masterToken:=data["masterkey"].(string)
ifmasterToken==secretKey{
rows,err:=conn.Query("SELECT id, username, created FROM users ORDER BY id DESC")
iferr!=nil{
iferrors.Is(err,sql.ErrNoRows){
c.JSON(200,[]map[string]interface{}{})
return
}else{
log.Println("[ERROR] Unknown in /api/listusers query at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTUSERS-DBQUERY"})
return
}
}
deferfunc(rows*sql.Rows){
err:=rows.Close()
iferr!=nil{
log.Println("[ERROR] Unknown in /api/listusers row defer at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTUSERS-ROWCLOSE"})
log.Println("[ERROR] Unknown in /api/listusers row scan at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTUSERS-ROWSCAN"})
return
}
space,err:=getSpace(id)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/listusers getSpace() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTUSERS-GETSPACE"})
return
}
notes,err:=getNoteCount(id)
iferr!=nil{
log.Println("[ERROR] Unknown in /api/listusers getNoteCount() at",strconv.FormatInt(time.Now().Unix(),10)+":",err)
c.JSON(500,gin.H{"error":"Something went wrong on our end. Please report this bug at https://centrifuge.hectabit.org/hectabit/burgernotes and refer to the documentation for more info. Your error code is: UNKNOWN-API-LISTUSERS-GETNOTECOUNT"})