//SearchTask is used to return the search results depending on the query func SearchTask(username, query string) (types.Context, error) { var tasks []types.Task var task types.Task var TaskCreated time.Time var context types.Context comments, err := GetComments(username) if err != nil { log.Println("SearchTask: something went wrong in finding comments") } userID, err := GetUserID(username) if err != nil { return context, err } stmt := "select t.id, title, content, created_date, priority, c.name from task t, category c where t.user_id=? and c.id = t.cat_id and (title like '%" + query + "%' or content like '%" + query + "%') order by created_date desc" rows := database.query(stmt, userID, query, query) defer rows.Close() for rows.Next() { err := rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority, &task.Category) if err != nil { log.Println(err) } if comments[task.Id] != nil { task.Comments = comments[task.Id] } task.Title = strings.Replace(task.Title, query, "<span class='highlight'>"+query+"</span>", -1) task.Content = strings.Replace(task.Content, query, "<span class='highlight'>"+query+"</span>", -1) task.Content = string(md.Markdown([]byte(task.Content))) TaskCreated = TaskCreated.Local() CurrentTime := time.Now().Local() week := TaskCreated.AddDate(0, 0, 7) if (week.String() < CurrentTime.String()) && (task.Priority != "1") { task.IsOverdue = true // If one week then overdue by default } task.Created = TaskCreated.Format("Jan 2 2006") tasks = append(tasks, task) } context = types.Context{Tasks: tasks, Search: query, Navigation: "search"} return context, nil }