Golang uses packr2 to package static files into binary files

        When using Golang to develop some small programs, you may need to display some configuration or monitoring information to the user. In this case, you need to create a web interface to display or configure the data. When we package and publish, we show that we do not want to include some files and folders. At this time, I want to package the web files directly into binary files. This can be achieved using the tool packr2.

First: packr2

        packr2 address: https://github.com/gobuffalo/packr

        1. Reference this package in the project  

go get -u github.com/gobuffalo/packr/v2

       2. Install the binary file and put the file into the release package for packaging.

go get -u github.com/gobuffalo/packr/v2/packr2

Second: gin, the gin web framework used in my project

        Directory Structure:

               

         1. Normal use is like this: In this way, views need to be placed in the same directory as the packaged executable file.

router := gin.Default()
router.Static("/static", "./views/static")
router.Run("0.0.0.0:8080")

        2

Guess you like

Origin blog.csdn.net/saperliu/article/details/110633504