Home > Software engineering >  Gin: Deeply Rooted Static Files Not Loading
Gin: Deeply Rooted Static Files Not Loading

Time:10-04

I have a gin application in which not all the static files load. Deeply rooted static files do not load.

Static file path

repository
  assets
       project_1
          css/style.css
           vendor/aos/bootstrap

Files in the aos folder do not load, but files in the css folder load. I have tried router.Static("/asset", "./repository/assets") but it does not work

CodePudding user response:

I am familiar with this problem, but I managed it with the help of the following code:

router.Static("/public", "./public")

And the file structure I had was as follows:

root-folder
    pkg
        handler
            handler.go
    public
        file1.jpg
        file2.html
        [other files]

In the file "handler.go" was the code listed above and with it I was able to access static files.

"root-folder" denotes the root directory of the entire gin project.

I think an example of my file structure and code will help you in solving your problem.

Try to move the "assets" folder to the root directory level and use my code, only specify "assets" instead of "public".

My code also works with nested directories. That is, if there is the following structure:

root-folder
    pkg
        handler
            handler.go
    public
        file1.jpg
        file2.html
        folder1
            file3.png
            folder2
                file4.html

Then access the file /public/folder1/folder2/file 4.html won't cause any problems.

  • Related