debug and make mail work

This commit is contained in:
2024-09-02 21:32:59 +02:00
parent 50142e16be
commit a51282eeec
5 changed files with 73 additions and 10 deletions

View File

@ -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