当前位置: 首页 > news >正文

知名网站开发哪家好网站项目需求分析

知名网站开发哪家好,网站项目需求分析,专业群建设网站,郑州做网站找哪家好生命不止#xff0c;继续 go go go !!!使用 Go 开发应用的时候#xff0c;有时会遇到需要读取静态资源的情况。比如开发 Web 应用#xff0c;程序需要加载模板文件生成输出的 HTML。在程序部署的时候#xff0c;除了发布应用可执行文件外#xff0c;还需要发布依赖的静态资…生命不止继续 go go go !!!使用 Go 开发应用的时候有时会遇到需要读取静态资源的情况。比如开发 Web 应用程序需要加载模板文件生成输出的 HTML。在程序部署的时候除了发布应用可执行文件外还需要发布依赖的静态资源文件。这给发布过程添加了一些麻烦。既然发布单独一个可执行文件是非常简单的操作就有人会想办法把静态资源文件打包进 Go 的程序文件中。参考地址http://fuxiaohei.me/2016/10/1/go-binary-embed-asset.html文中提到了go-bindatago.riceesc本片博客只会介绍go.rice其余的会之后进行介绍的。What’s an Embedded Resource?An embedded resource in a application is a file that is included as part of the application. The file is not compiled, but is accessable from the code at run-time. Embedded resources can be any file type.Languages as JAVA and C# support resources out of box. However, this is not the case for Golang. In order to emebed resource, we need to develop our own solution. Thankfully, there are couple of tools that are doing this for us.参考地址http://blog.ralch.com/tutorial/golang-embedded-resources/go.ricego.rice is a Go package that makes working with resources such as html,js,css,images,templates, etc very easy.github地址https://github.com/GeertJohan/go.riceStar: 1107获取go get github.com/GeertJohan/go.ricego get github.com/GeertJohan/go.rice/rice12FindBoxfuncation to access a particular resource bundler (directory).The function is finding the correct absolute path for your resource files.// find a rice.BoxtemplateBox, err : rice.FindBox(your-resource-directory)if err ! nil { log.Fatal(err)}// get file contents as stringtmpl, err : templateBox.String(your_asset.tmpl)if err ! nil { log.Fatal(err)}12345678910Embedded resource as source code作为源码嵌入资源命令rice embed-go1生成文件.rice-box.go1Embedded resource as an archiveappends a resource as a zip file to already built executable以zip的形式附加到已经存在的可执行文件Embedded resource as an syso resourceThis is experimental method that generates .syso file that is compiled by Go compiler. The following command generates the coff syso resource files per directory:rice embed-syso1go build -o rice append --exec 12echo中使用go.rice代码main.go:package mainimport ( net/http github.com/GeertJohan/go.rice github.com/labstack/echo)func main() { e : echo.New() // the file server for rice. app is the folder where the files come from. assetHandler : http.FileServer(rice.MustFindBox(app).HTTPBox()) // serves the index.html from rice e.GET(/, echo.WrapHandler(assetHandler)) // servers other static files e.GET(/static/*, echo.WrapHandler(http.StripPrefix(/static/, assetHandler))) e.Logger.Fatal(e.Start(:1323))}12345678910111213141516171819202122跟main.go同一级新建一个文件夹app放入文件file.txt执行rice embed-go1生成了 rice-box.gopackage mainimport ( github.com/GeertJohan/go.rice/embedded time)func init() { // define files file2 : embedded.EmbeddedFile{ Filename: file.txt, FileModTime: time.Unix(1511406219, 0), Content: string(), } // define dirs dir1 : embedded.EmbeddedDir{ Filename: , DirModTime: time.Unix(1511406219, 0), ChildFiles: []*embedded.EmbeddedFile{ file2, // file.txt }, } // link ChildDirs dir1.ChildDirs []*embedded.EmbeddedDir{} // register embeddedBox embedded.RegisterEmbeddedBox(app, embedded.EmbeddedBox{ Name: app, Time: time.Unix(1511406219, 0), Dirs: map[string]*embedded.EmbeddedDir{ : dir1, }, Files: map[string]*embedded.EmbeddedFile{ file.txt: file2, }, })}123456789101112131415161718192021222324252627282930313233343536373839404142执行go build1生成文件embed_resources.exe运行embed_resources.exe删除app文件夹下的file.txt浏览器访问http://localhost:1323/可以看到file.txt文件
http://www.yutouwan.com/news/320704/

相关文章:

  • 商业网站推广网站做中秋专题怎么弄
  • 网络科技公司网站源码下载微商怎么引流推广
  • win7 搭建iss网站做两个阿里网站
  • 淘宝网站开发需求分析西部数码网站建设助手
  • 部门将网站建设的需求电商平台开发报价
  • 印刷做网站网上接单网站建设的主要功能有哪些
  • 网站标题的设置方法网站搭建赚钱吗
  • 网站建实例深圳微信分销网站制作
  • 做一个小说网站需要多少钱网站建设php书籍
  • 海外网站速度慢株洲有名的网站
  • 做定制旅游最好的网站如何用模版做网站
  • 郑州最好的网站建设做淘宝主要看哪些网站有哪些
  • 网站建设的目的及功能网站建设技术规范
  • 物流 东莞网站建设创意广告图片及文字解析
  • 网站设置银联密码做动画网站公司
  • 个人网站建设哪家好黑龙江建设网一体化平台
  • ftp如何修改网站备案号五金网站模板
  • 只做乡村旅游的网站网站域名注册商
  • 小白网站建设教程网站推广与优化平台
  • 丽水市住房和城建建设局网站法律行业网站建设
  • wordpress 主题函数企业网站优化定制
  • 长沙网站建设公司哪家专业迪拜哪个网站是做网站的
  • 建网站的外包公司交流建筑的网站
  • 网站建设维护协议书网站流量分析指标
  • 深圳网站制作排行榜网站建设的主要产品
  • 佛山市建设网站wordpress 扁平化主题下载
  • 安徽工程建设信息网站wordpress生成静态
  • 如东建设网站哪里建设网站比较好
  • 做网站需要参考书目书做网站的图片大全
  • 网站建设都有哪些书网站模板制作教程视频