Commit d5461c49 authored by Pasan Mallawaarachchi's avatar Pasan Mallawaarachchi 💻

remove panic and STD output

parent 70c607de
...@@ -154,6 +154,7 @@ func main() { ...@@ -154,6 +154,7 @@ func main() {
if reqErr != nil { if reqErr != nil {
alert := " Error creating request to OUTBOX DB \n" + reqErr.Error() alert := " Error creating request to OUTBOX DB \n" + reqErr.Error()
alertAdmin(alert) alertAdmin(alert)
fmt.Printf("Error : %s", reqErr.Error())
//panic(reqErr) //panic(reqErr)
} }
req.Header.Set(config.Requests.HeaderType, config.Requests.HeaderJson) req.Header.Set(config.Requests.HeaderType, config.Requests.HeaderJson)
...@@ -162,6 +163,7 @@ func main() { ...@@ -162,6 +163,7 @@ func main() {
if respErr != nil { if respErr != nil {
alert := " Error in getting email from the OUTBOX DB \n" + respErr.Error() alert := " Error in getting email from the OUTBOX DB \n" + respErr.Error()
alertAdmin(alert) alertAdmin(alert)
fmt.Printf("Error : %s", reqErr.Error())
//panic(respErr) //panic(respErr)
} }
defer resp.Body.Close() defer resp.Body.Close()
...@@ -277,11 +279,13 @@ func worker(i int) { ...@@ -277,11 +279,13 @@ func worker(i int) {
var config Config var config Config
source, sourceErr := ioutil.ReadFile("config.yaml") source, sourceErr := ioutil.ReadFile("config.yaml")
if sourceErr != nil { if sourceErr != nil {
panic(sourceErr) fmt.Printf("sourceErr : %s", sourceErr.Error())
//panic(sourceErr)
} }
configErr := yaml.Unmarshal(source, &config) configErr := yaml.Unmarshal(source, &config)
if configErr != nil { if configErr != nil {
panic(configErr) fmt.Printf("configErr : %s", configErr.Error())
//panic(configErr)
} }
//fmt.Println("Worker ", i, " strats working") //fmt.Println("Worker ", i, " strats working")
...@@ -352,7 +356,8 @@ func worker(i int) { ...@@ -352,7 +356,8 @@ func worker(i int) {
//if(attachErr != nil) //if(attachErr != nil)
//attchResp, err := http.DefaultClient.Do(attachReq) //attchResp, err := http.DefaultClient.Do(attachReq)
if err != nil { if err != nil {
panic(err) fmt.Printf("attchResp : %s", err.Error())
// panic(err)
} }
defer attchResp.Body.Close() defer attchResp.Body.Close()
respbody, _ := ioutil.ReadAll(attchResp.Body) respbody, _ := ioutil.ReadAll(attchResp.Body)
...@@ -362,20 +367,24 @@ func worker(i int) { ...@@ -362,20 +367,24 @@ func worker(i int) {
dec, err := base64.StdEncoding.DecodeString(resp) dec, err := base64.StdEncoding.DecodeString(resp)
if err != nil { if err != nil {
panic(err) fmt.Printf("Decode err : %s", err.Error())
//panic(err)
} }
f, err := os.Create(filename) f, err := os.Create(filename)
if err != nil { if err != nil {
panic(err) fmt.Printf("File err : %s", err.Error())
//panic(err)
} }
//defer f.Close() //defer f.Close()
if _, err := f.Write(dec); err != nil { if _, err := f.Write(dec); err != nil {
panic(err) fmt.Printf("File write err : %s", err.Error())
// panic(err)
} }
if err := f.Sync(); err != nil { if err := f.Sync(); err != nil {
panic(err) fmt.Printf("Sync err : %s", err.Error())
//panic(err)
} }
//message.AddHeader("Content-Type", "multipart/form-data") //message.AddHeader("Content-Type", "multipart/form-data")
...@@ -390,6 +399,7 @@ func worker(i int) { ...@@ -390,6 +399,7 @@ func worker(i int) {
MailgunResp, id, err := mg.Send(ctx, message) MailgunResp, id, err := mg.Send(ctx, message)
if err != nil { if err != nil {
// log.Fatal(err) // log.Fatal(err)
fmt.Printf("MailgunResp err : %s", err.Error())
alertAdmin(" MAilgun Error \n" + err.Error()) alertAdmin(" MAilgun Error \n" + err.Error())
} }
if len(filename) > 0 { if len(filename) > 0 {
...@@ -447,6 +457,7 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string ...@@ -447,6 +457,7 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string
resp, id, err := mg.Send(ctx, message) resp, id, err := mg.Send(ctx, message)
if err != nil { if err != nil {
//log.Fatal(err) //log.Fatal(err)
fmt.Printf("MAilgun Error : %s", err.Error())
alertAdmin(" MAilgun Error \n" + err.Error()) alertAdmin(" MAilgun Error \n" + err.Error())
} }
//fmt.Println(resp) //fmt.Println(resp)
...@@ -454,11 +465,13 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string ...@@ -454,11 +465,13 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string
var config Config var config Config
source, sourceErr := ioutil.ReadFile("config.yaml") source, sourceErr := ioutil.ReadFile("config.yaml")
if sourceErr != nil { if sourceErr != nil {
panic(sourceErr) fmt.Printf("Mail config err : %s", sourceErr.Error())
// panic(sourceErr)
} }
configErr := yaml.Unmarshal(source, &config) configErr := yaml.Unmarshal(source, &config)
if configErr != nil { if configErr != nil {
panic(configErr) fmt.Printf("configErr : %s", configErr.Error())
// panic(configErr)
} }
if config.AppMod.Production == "0" { if config.AppMod.Production == "0" {
...@@ -475,11 +488,13 @@ func alertAdmin(err string) { ...@@ -475,11 +488,13 @@ func alertAdmin(err string) {
var config Config var config Config
source, sourceErr := ioutil.ReadFile("config.yaml") source, sourceErr := ioutil.ReadFile("config.yaml")
if sourceErr != nil { if sourceErr != nil {
panic(sourceErr) fmt.Printf("Admin Alert err : %s", sourceErr.Error())
// panic(sourceErr)
} }
configErr := yaml.Unmarshal(source, &config) configErr := yaml.Unmarshal(source, &config)
if configErr != nil { if configErr != nil {
panic(configErr) fmt.Printf("Unmarshal err : %s", configErr.Error())
// panic(configErr)
} }
// sending mail via Mailgun // sending mail via Mailgun
...@@ -499,11 +514,13 @@ func logmail(subject, sender, recipient, cc, bcc, attachment, readTimeOutbox, ma ...@@ -499,11 +514,13 @@ func logmail(subject, sender, recipient, cc, bcc, attachment, readTimeOutbox, ma
var config Config var config Config
source, sourceErr := ioutil.ReadFile("config.yaml") source, sourceErr := ioutil.ReadFile("config.yaml")
if sourceErr != nil { if sourceErr != nil {
panic(sourceErr) fmt.Printf("Logmail sourceErr : %s", sourceErr.Error())
// panic(sourceErr)
} }
configErr := yaml.Unmarshal(source, &config) configErr := yaml.Unmarshal(source, &config)
if configErr != nil { if configErr != nil {
panic(configErr) fmt.Printf("Unmarshal configErr : %s", configErr.Error())
// panic(configErr)
} }
logBody := strings.NewReader(`{"Mail Subject":"` + subject + logBody := strings.NewReader(`{"Mail Subject":"` + subject +
...@@ -539,11 +556,13 @@ func sentmail(subject, sender, recipient, cc, bcc, attachment, body, mailID stri ...@@ -539,11 +556,13 @@ func sentmail(subject, sender, recipient, cc, bcc, attachment, body, mailID stri
var config Config var config Config
source, sourceErr := ioutil.ReadFile("config.yaml") source, sourceErr := ioutil.ReadFile("config.yaml")
if sourceErr != nil { if sourceErr != nil {
panic(sourceErr) fmt.Printf("Sentmail sourceErr : %s", sourceErr.Error())
// panic(sourceErr)
} }
configErr := yaml.Unmarshal(source, &config) configErr := yaml.Unmarshal(source, &config)
if configErr != nil { if configErr != nil {
panic(configErr) fmt.Printf("Sentmail configErr : %s", configErr.Error())
// panic(configErr)
} }
sentBody := strings.NewReader(`{"Mail Subject":"` + subject + sentBody := strings.NewReader(`{"Mail Subject":"` + subject +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment