This is first of series of posts I am going to write as and when it happens.
When trying to develop code, the first limitation is body and brain. (or heart and soul) ; But some times silly things take up all the available time wasting precious dev time. Here are two such things happened to me this week.
All I am trying to do is create a rudimentary web html page to try one of the REST API. (I know postman could be used, but I have plans to evolve this rudimentary into full blown web UI later – anyhow the REST API is already well tested with unit testing and postman)
<form action="/restapi" method="post">
And it didn’t work!. Surprise, surprise!!
when I convert this to GET its working. I created so many forms in the past what the hell is happening? I check/recheck every bit by bit – deleted everything and retyped. Nothing is helping. There is no way this could go wrong. I double check, recheck my back-end code. Try different ways of doing back-end code. Is it because I am not including request.Form.Parse()? OK – no harm, let me add it. No luck. Took a break, and restarted with a fresh mind.
Finally a light bulb💡 – instead of worrying about back-end code I thought may be browser is not sending the post data, but that is not the case 😞 – anyhow, I Google searched for GET is working and POST sending empty data. Finally some result to help me 😥. If we don’t put a slash in the end it will redirect without post data.
I wrote so many forms in the past but most of them are for PHP or c#; this one is for golang. In PHP I used to give complete file name something like restapi.php so redirection didn’t came into picture. c# thanks to visual studio it is taken care.
After adding a slash it started working! Silly!!
<form action="/restapi/" method="post">
The second speed breaker is when trying to run ./main in docker I got incorrect permissions.
I added chmod +x ==> no luck.
I have a RUN cd main followed by CMD [“./main”] in Dockerfile ;
Expected PWD when CMD is being executed to be main directory. But that is the not the case –
so ./main ==> I assumed it will in main directory executing main exe; but docker is trying to run main directory and getting no permissions issue!
After staring at the screen for a long time, I realized what is happening. (of course did many not so useful search and reads)
Hindsight – I should never name directory and other files with same name. It adds confusion to the error messages. Making almost error message useless.
Fixed this by making WORKDIR /app/main before CMD.