0

I have a GO project which has UI written by html. In HTML file, I have written javascript, and I can install GO and load the UI successfully.

The problem is when I move those javascript code to an external file, and include it: . I only can build GO, but when load the UI, it has error 404 Not Found which is "myscripts.js" file. The weird thing is on its header of error: Remote Address:127.0.0.1:8080 Request URL:http://localhost:8080/subscribe/myscripts.js Request Method:GET Status Code:404 Not Found

Please help, I can't find any answer yet for this

3
  • I include by simply writing this line of code in HTML file: <script src="myscripts.js" type="text/javascript"></script> Commented Mar 11, 2015 at 9:53
  • If those html files are fragments in deeper folders ensure that the script path is relative based on the final page they are inject to and not the template itself Commented Mar 11, 2015 at 9:54
  • possible duplicate of Include js file in Go template Commented Mar 11, 2015 at 16:29

1 Answer 1

3

That's normal if you only define handler for your endpoints.

You should add to your router the http.FileServer handler pointing to the directory that store your project files.

Additionally, think about the <base> that to define the root of your relative links, which will prevent errors such as path nesting.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I found a way which add to main() this line of code:

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.