Original [Go tips] teach you how to package the front-end files into the Go program, cool!

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

In the development of Golang, we sometimes want to package some external dependent files into a binary program. For example, when I developed the LESSGO web framework, I wanted to package the extension package swagger (the front end of an automated API document) into a project file, which would reduce dependencies and improve code stability. The implementation steps are as follows:

  1. Download a third-party package for two Golang
    go get github.com/jteeuwen/go-bindata/...go get github.com/elazarl/go-bindata-assetfs/...

  2. Compiling the Go-bindata-assetfs.exe file using the "Go Install" command

  3. Perform "Go-bindata-assetfs.exe views/..." Write all files in the./views directory to the Bindata_assetfs.go file

  4. A function named Assetfs () is provided in the Bindata_assetfs.go file, which returns the HTTP containing the contents of the view file. Filesystem Interface Instance

  5. For example, static file routing is called:

    http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(assetFS)))

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.