debug and make mail work
This commit is contained in:
		@ -12,6 +12,7 @@ type RequestPayload struct {
 | 
			
		||||
	Action string      `string:"action"`
 | 
			
		||||
	Auth   AuthPayload `json:"auth,omitempty"`
 | 
			
		||||
	Log    LogPayload  `json:"log,omitempty"`
 | 
			
		||||
	Mail   MailPayload `json:"mail,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type AuthPayload struct {
 | 
			
		||||
@ -24,6 +25,13 @@ type LogPayload struct {
 | 
			
		||||
	Data string `json:"data"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type MailPayload struct {
 | 
			
		||||
	From    string `json:"from"`
 | 
			
		||||
	To      string `json:"to"`
 | 
			
		||||
	Subject string `json:"subject"`
 | 
			
		||||
	Content string `json:"content"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *Config) Broker(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	payload := jsonResponse{
 | 
			
		||||
		Error:   false,
 | 
			
		||||
@ -47,6 +55,8 @@ func (app *Config) HandleSubmission(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
		app.authenticate(w, requestPayload.Auth)
 | 
			
		||||
	case "log":
 | 
			
		||||
		app.LogItem(w, requestPayload.Log)
 | 
			
		||||
	case "mail":
 | 
			
		||||
		app.SendMail(w, requestPayload.Mail)
 | 
			
		||||
	default:
 | 
			
		||||
		app.errorJSON(w, errors.New("unknown action"))
 | 
			
		||||
	}
 | 
			
		||||
@ -81,6 +91,21 @@ func (app *Config) LogItem(w http.ResponseWriter, entry LogPayload) {
 | 
			
		||||
	app.callService(w, loggerService)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *Config) SendMail(w http.ResponseWriter, entry MailPayload) {
 | 
			
		||||
	log.Println(entry)
 | 
			
		||||
	mailService := Microservice{
 | 
			
		||||
		Input: entry,
 | 
			
		||||
		Addr:  "http://mail-service/send-mail",
 | 
			
		||||
		ErrCode: statusError{
 | 
			
		||||
			ExpectedCode: http.StatusAccepted,
 | 
			
		||||
			ErrCode:      http.StatusInternalServerError,
 | 
			
		||||
			Err:          errors.New("internal error"),
 | 
			
		||||
		},
 | 
			
		||||
		SuccessMsg: "Mail sent!",
 | 
			
		||||
	}
 | 
			
		||||
	app.callService(w, mailService)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type statusError struct {
 | 
			
		||||
	ExpectedCode int
 | 
			
		||||
	ErrCode      int
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user