Exemplo n.º 1
0
/*
GetServiceSettings returns the settings necessary to talk to the MailSlurper
back-end service tier.
*/
func GetServiceSettings(writer http.ResponseWriter, request *http.Request) {
	config := (context.Get(request, "config")).(*configuration.Configuration)

	settings := model.ServiceSettings{
		ServiceAddress: config.ServiceAddress,
		ServicePort:    config.ServicePort,
		Version:        "v1",
	}

	GoHttpService.WriteJson(writer, settings, 200)
}
/*
Search tries to find nodes that contain a term

GET /search?term=[searchTerm]
*/
func Search(writer http.ResponseWriter, request *http.Request) {
	log := (context.Get(request, "log")).(*logging.Logger)
	catalog := (context.Get(request, "catalog")).(*catalog.Catalog)
	term := request.URL.Query().Get("term")

	if len(term) <= 0 {
		log.Error("User provided blank term in /search")
		GoHttpService.BadRequest(writer, "Please provide a search term")
		return
	}

	log.Infof("Searching for [%s]", term)

	matches := catalog.Search(term)
	if matches == nil {
		GoHttpService.NotFound(writer, "Term "+term+" not found")
		return
	}

	GoHttpService.WriteJson(writer, matches, 200)
}
/*
GetVersion writes the current server version to the response writer

GET /version
*/
func GetVersion(writer http.ResponseWriter, request *http.Request) {
	version := (context.Get(request, "version")).(string)
	GoHttpService.WriteJson(writer, version, 200)
}