package main

import (
	"net/http"
	"log"
)

func Index(w http.ResponseWriter, r *http.Request) {
	body := NewRequest(r).GetBody()

	if config.FastPublish {
		if len(body) > 0 {
			servicesQueue.Publish(body)
		}
		return
	}

	service, err := NewService(body)
	response := NewResponse(w)

	if err != nil {
		response.Body.Error = true
		response.Body.Message = err.Error()
		response.Status = http.StatusUnprocessableEntity
		log.Printf(err.Error())
	} else {
		err := validate.Struct(service)
		if err == nil {
			servicesQueue.Publish(body)
			response.Body.Message = "Success"
			response.Status = http.StatusCreated
			log.Printf("Received: %s", string(body))
		} else {
			response.Body.Error = true
			response.Body.Message = err.Error()
			response.Status = http.StatusBadRequest
			log.Printf(err.Error())
		}
	}

	response.Write()
}

package main

import (
	"net/http"
	"log"
)

func Index(w http.ResponseWriter, r *http.Request) {
	body := NewRequest(r).GetBody()

	if config.FastPublish {
		if len(body) > 0 {
			servicesQueue.Publish(body)
		}
		return
	}

	service, err := NewService(body)
	response := NewResponse(w)

	if err != nil {
		response.Body.Error = true
		response.Body.Message = err.Error()
		response.Status = http.StatusUnprocessableEntity
		log.Printf(err.Error())
	} else {
		err := validate.Struct(service)
		if err == nil {
			servicesQueue.Publish(body)
			response.Body.Message = http.StatusText(http.StatusAccepted)
			response.Status = http.StatusAccepted
			log.Printf("Accepted: %s", string(body))
		} else {
			response.Body.Error = true
			response.Body.Message = err.Error()
			response.Status = http.StatusBadRequest
			log.Printf(err.Error())
		}
	}

	response.Write()
}

Set accepted status when successfully published.
Set accepted status when successfully published.
