// Delete log record func Delete(res http.ResponseWriter, ctx *context.Context, params martini.Params) { conn := common.GetConnection() d := goes.Document{ Index: ctx.User.GetIndexName(), Type: params["type"], Id: params["id"], } _, err := conn.Delete(d, url.Values{}) if err != nil { res.WriteHeader(503) } }
// View log record func View(res http.ResponseWriter, ctx *context.Context, params martini.Params) { conn := common.GetConnection() response, err := conn.Get(ctx.User.GetIndexName(), params["type"], params["id"], url.Values{}) if err != nil { res.WriteHeader(404) } j, err := json.Marshal(response.Source) if err != nil { res.WriteHeader(503) } res.Write(j) }
// Search logs in elastic. func search(searchRequest SearchRequest) (goes.Response, error) { conn := common.GetConnection() var query = map[string]interface{}{ "from": searchRequest.From, "size": searchRequest.Size, "sort": map[string]string{ "datetime": "desc", }, } if len(searchRequest.Text) > 0 { strconv.Quote(searchRequest.Text) query["query"] = map[string]interface{}{ "query_string": map[string]string{ "default_field": "message", "query": searchRequest.Text, }, } } // Build time range query if searchRequest.TimeRange.IsValid() { datetime := make(map[string]string) if searchRequest.TimeRange.Start != "" { datetime["gte"] = searchRequest.TimeRange.Start } if searchRequest.TimeRange.Stop != "" { datetime["lte"] = searchRequest.TimeRange.Stop } query["filter"] = map[string]interface{}{ "range": map[string]interface{}{ "datetime": datetime, }, } } extraArgs := make(url.Values, 0) searchResults, err := conn.Search(query, searchRequest.Indexes, searchRequest.Types, extraArgs) if err != nil { return goes.Response{}, errors.New("No records found.") } else { return *searchResults, nil } }
func Register(ctx *context.Context) { ctx.Request.ParseForm() form := ®isterForm{ EnableValidation: &common.EnableValidation{}, } if ctx.Request.Method == "POST" { form.Email = ctx.Request.Form.Get("email") form.Password = ctx.Request.Form.Get("password") form.SetupValidation() if !form.EnableValidation.Valid.HasErrors() && form.IsValid() { password, err := common.HashPassword(form.Password) if err != nil { panic(err.Error()) } doc := goes.Document{ Index: "users", Type: "user", Fields: map[string]string{ "email": form.Email, "password": password, "apiKey": buildApiKey(form.Email), }, } extraArgs := make(url.Values, 0) common.GetConnection().Index(doc, extraArgs) ctx.Render.Redirect("/login") } } ctx.HTML("users/register", context.ViewData{ "form": form, }) }