How can I improve this code?

I need to validate the images’ format and size, but of course, if an error occurs I need to save it in a variable (in this case infoMessage struct) , but due to I am using Ajax to handle the request I have no idea how can I pass the request over all the functions and then marshal the infoMessage struct and send it to the user if something wrong happens.

I’m able to send errors from validateFormatImgs but I also need to send errors from validateSizeImgs because of that I need the http.ResponseWritter variable to send the JSON, but I don’t know how I can improve this code. I am kind of new in Golang maybe there is a better (sure there is one) way to do this, any tip or change is welcome!.

you can split validateSizeImgs in two functions. first validates size in the same manner like validateFormatImgs and second save the image the, check the errors doing something like this:

if validateFormatImgs == true && validateSizeImgs == true {
} else {
  .... send/show error to user

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.