I'm writing my website in golang but there is issue called 404 page not found

147 views
Skip to first unread message

Ali Hassan

unread,
Mar 8, 2020, 11:19:20 AM3/8/20
to golang-nuts

goSnippet.JPGfirefox.JPG

xhrSnippet.JPG

htmlSnippnet.JPGBrowser Error 404   please help me resolve this error. I think this is because of html page but when try this /register.html then whole page display on my console. I will exchange my data 


buttonSnippnet.JPG

Brian Candler

unread,
Mar 8, 2020, 11:32:59 AM3/8/20
to golang-nuts
Well, I can't see your problem immediately, but you've not made it easy for anyone to help you.

Am I going to retype your screen images to replicate the problem? No.  Am I going to write a main() function which wraps your code, and then work out what all the import statements need to be to make it complete? No.

Therefore, I suggest the best way to get help is to produce a standalone application which replicates the problem, and submit it in *text* format, so it's something we can simply copy-paste into a terminal, run and debug.

It doesn't need the HTML or Javascript parts - it's fine to use 'curl -X POST ...' to send a message to it.

Regards,

Brian.

leszek...@gmail.com

unread,
Mar 8, 2020, 7:56:04 PM3/8/20
to golang-nuts
Hello,

It would be much clearer if you posted a complete sample of a Go code. Which framework are you using for the server? I guess it could be something with the server config, can it accept POST methods? Did you test the server first, independently of your frontend, by using curl or PostMan? It could be a problem with preflight request from the browser. 

The screenshot of the console is too small to read. 

/Leszek

anderson...@blacklane.com

unread,
Mar 9, 2020, 10:53:20 AM3/9/20
to golang-nuts
please post the code as text. Either in a github/whatever repo or here, but please, as text and a runnable code.

I don't see you registering any handler for /register.html, you have one for /register only. Also if the method is not POST, you should return 405 Method Not Allowed instead of 404 Not Found.

As tip, use the http constants such as http.MethodPost. See them here: https://golang.org/pkg/net/http/#pkg-constants

Best,
Anderson

Amnon Baron Cohen

unread,
Mar 9, 2020, 3:10:06 PM3/9/20
to golang-nuts
Also worth adding some unit tests, including one which reproduces your 404 error.

See https://www.youtube.com/watch?v=hVFEV-ieeew for a great video about how to 
add these tests.
Reply all
Reply to author
Forward
0 new messages