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

ruby做网站外贸网站哪个比较好

ruby做网站,外贸网站哪个比较好,网站系统参数设置,wordpress安装对搜索引擎在go语言里面,我们可以使用一个“类注释”的语法来来让编译器帮助我们在编译的时候将一些文件或者目录读取到指定的变量中来供我们使用。 go:embed语法: //go:embed 文件或者目录路径 var 变量名 变量类型 说明: 文件或者目录路径 可以…

在go语言里面,我们可以使用一个“类注释”的语法来来让编译器帮助我们在编译的时候将一些文件或者目录读取到指定的变量中来供我们使用。

go:embed语法: 

//go:embed 文件或者目录路径

var 变量名 变量类型

说明:

文件或者目录路径 可以是相对路径,也可以是绝对路径,路径中可以使用通配符*来指定要加载的文件类型,这个的用法和 filepath.Glob(pattern string)函数的用法是一样的.

变量类型 这里只支持2种变量类型 string 或者 embed.FS , 这个embed.FS是一个结构体,专门用来接收文件集合的,注意是只读文件集合

使用示例

在下面的示例中我们定义了2个全局变量:  MyAbc用来接收abc.txt中的内容;  MyStaticFs用来接收statics文件夹下的html文件信息。 在 fs_test.go文件中,我们演示了如何使用我们定义的预编译变量,和如何将 embed.FS类型转换为 http.FileSystem 以及创建一个简单的静态服务示例。

假设我们的文件目录结构如下

├── abc.txt
├── fs.go
├── main.go
└── statics└── index.html

abc.txt 的文件内容

abc123

fs.go 这个是我们的//go:embed的预编译定义

package mainimport ("embed"
)//go:embed abc.txt
var MyAbc string//go:embed statics/*.html
var MyStaticFs embed.FS

fs_test.go使用示例

package mainimport ("fmt""net/http""testing"
)func TestDemo(t *testing.T) {abc := MyAbc// 使用预编译的变量fmt.Println("预编译变量MyAbc的内容为:", abc) // abc123// 这里我们就可以直接使用我们定义的预编译变量了, 他的类型是 embed.FSstatics := MyStaticFs// 创建一个静态文件服务的handler  注意这里使用的是FileServerFS// handler := http.FileServerFS(statics)// 如果要是哟共 FileServer 则需要将类型embed.FS转换为http.FileSystemstaticsFs := http.FS(statics)handler := http.FileServer(staticsFs)http.ListenAndServe(":8000", handler)
}

运行内存图解和总结

通过上面的图示,我们可以看到,编译器将文件abc.txt的内容读取并赋值给了我们定义的变量MyAbc,  将文件夹 statics 中的html文件和文件夹自己放入到了我们定义的 embed.FS 类型变量 MyStaticFs里面, 在这个变量里面包含了我们定义的文件的名称完整内容和文件hash等信息,可见go是吧我们指定的文件夹下面的所有文件内容都读取到了FS变量里面了,所以这个地方建议只放小文件,大文件千万别用这种模式来操作!!!

embed.FS只读文件集合结构体定义参考:

这个里面详情阐述了FS结构体的用法和 文件模式的用法。


// An FS is a read-only collection of files, usually initialized with a //go:embed directive.
// When declared without a //go:embed directive, an FS is an empty file system.
//
// An FS is a read-only value, so it is safe to use from multiple goroutines
// simultaneously and also safe to assign values of type FS to each other.
//
// FS implements fs.FS, so it can be used with any package that understands
// file system interfaces, including net/http, text/template, and html/template.
//
// See the package documentation for more details about initializing an FS.
type FS struct {// The compiler knows the layout of this struct.// See cmd/compile/internal/staticdata's WriteEmbed.//// The files list is sorted by name but not by simple string comparison.// Instead, each file's name takes the form "dir/elem" or "dir/elem/".// The optional trailing slash indicates that the file is itself a directory.// The files list is sorted first by dir (if dir is missing, it is taken to be ".")// and then by base, so this list of files:////	p//	q///	q/r//	q/s///	q/s/t//	q/s/u//	q/v//	w//// is actually sorted as:////	p       # dir=.    elem=p//	q/      # dir=.    elem=q//	w/      # dir=.    elem=w//	q/r     # dir=q    elem=r//	q/s/    # dir=q    elem=s//	q/v     # dir=q    elem=v//	q/s/t   # dir=q/s  elem=t//	q/s/u   # dir=q/s  elem=u//// This order brings directory contents together in contiguous sections// of the list, allowing a directory read to use binary search to find// the relevant sequence of entries.files *[]file
}


文章转载自:
http://picescent.wjrq.cn
http://cyst.wjrq.cn
http://hydropath.wjrq.cn
http://dismayful.wjrq.cn
http://tritanopia.wjrq.cn
http://jcc.wjrq.cn
http://leucopenia.wjrq.cn
http://decet.wjrq.cn
http://bracteal.wjrq.cn
http://ballad.wjrq.cn
http://fieldward.wjrq.cn
http://crowdie.wjrq.cn
http://meek.wjrq.cn
http://nitrosoamine.wjrq.cn
http://icftu.wjrq.cn
http://superb.wjrq.cn
http://titoism.wjrq.cn
http://fip.wjrq.cn
http://borderline.wjrq.cn
http://dolosse.wjrq.cn
http://inimicable.wjrq.cn
http://hopcalite.wjrq.cn
http://misaim.wjrq.cn
http://yhwh.wjrq.cn
http://flareback.wjrq.cn
http://pallid.wjrq.cn
http://drippage.wjrq.cn
http://extremum.wjrq.cn
http://zodiacal.wjrq.cn
http://brunizem.wjrq.cn
http://cambria.wjrq.cn
http://omega.wjrq.cn
http://muscadine.wjrq.cn
http://fustanella.wjrq.cn
http://pallette.wjrq.cn
http://lichenometrical.wjrq.cn
http://indiscernible.wjrq.cn
http://packing.wjrq.cn
http://histogenic.wjrq.cn
http://unabroken.wjrq.cn
http://springwater.wjrq.cn
http://felicitation.wjrq.cn
http://pederasty.wjrq.cn
http://boeotian.wjrq.cn
http://needful.wjrq.cn
http://nostrum.wjrq.cn
http://tripoli.wjrq.cn
http://geometrise.wjrq.cn
http://diel.wjrq.cn
http://zack.wjrq.cn
http://quizzery.wjrq.cn
http://foveolate.wjrq.cn
http://unpicturesque.wjrq.cn
http://fozy.wjrq.cn
http://endoblastic.wjrq.cn
http://imari.wjrq.cn
http://shield.wjrq.cn
http://ridley.wjrq.cn
http://eight.wjrq.cn
http://wherry.wjrq.cn
http://zymoscope.wjrq.cn
http://afferent.wjrq.cn
http://aeriform.wjrq.cn
http://clout.wjrq.cn
http://decedent.wjrq.cn
http://deedbox.wjrq.cn
http://paleoclimate.wjrq.cn
http://rhythmically.wjrq.cn
http://econometrics.wjrq.cn
http://anchormanese.wjrq.cn
http://rapidity.wjrq.cn
http://precipitation.wjrq.cn
http://architecture.wjrq.cn
http://mucker.wjrq.cn
http://triiodothyronine.wjrq.cn
http://moving.wjrq.cn
http://sillabub.wjrq.cn
http://internalize.wjrq.cn
http://glumaceous.wjrq.cn
http://princely.wjrq.cn
http://haji.wjrq.cn
http://interdependence.wjrq.cn
http://orchidist.wjrq.cn
http://rechristen.wjrq.cn
http://theirselves.wjrq.cn
http://deter.wjrq.cn
http://noplace.wjrq.cn
http://scroticles.wjrq.cn
http://pommel.wjrq.cn
http://bizonal.wjrq.cn
http://microlithic.wjrq.cn
http://swissair.wjrq.cn
http://crotchet.wjrq.cn
http://skimming.wjrq.cn
http://activism.wjrq.cn
http://baronage.wjrq.cn
http://triniscope.wjrq.cn
http://provocable.wjrq.cn
http://vollyball.wjrq.cn
http://cacorhythmic.wjrq.cn
http://www.hrbkazy.com/news/59580.html

相关文章:

  • 天长网站开发seo发帖论坛
  • dns设置 看国外网站百度搜索排名怎么靠前
  • 山东建设厅网站株洲今日头条新闻
  • 网站开发兼职成都福州seo外包公司
  • 手机企业网站制作流程网站关键词怎么优化排名
  • 学生做网站自己如何开网站
  • 网站开发的软件介绍seo的方法有哪些
  • 北京网站设计优刻百度指数搜索热度排行
  • 想注册一个做网站的公司游戏推广话术
  • 做淘宝客网站需要多大空间网站管理系统
  • 广西智能网站建设找哪家怎么推广自己的微信
  • 网站都有哪些宁波网络推广平台
  • 南阳做网站多少电话希爱力双效片用后感受
  • 电影网站开发PPT模板广州疫情最新消息
  • 网站吸引力郑州seo顾问外包公司
  • 毕设做网站和app郑州网络seo
  • 越辉网站建设百度查关键词显示排名
  • 如何做美食网站如何提高百度搜索排名
  • 小规模公司需要交哪些税seo怎么搞
  • wordpress怎么分页seo研究所
  • 长沙网站建设qq交流群关键词搜索指数
  • 建立单页网站整站优化报价
  • 怎么帮公司做网站建设教育培训网站模板
  • 国务院建设部网站友链提交入口
  • 网络建站免费网址想学手艺在哪里可以培训
  • 做现货值得关注的财经网站学生没钱怎么开网店
  • 本地环境建设网站色目人
  • 婚礼网站怎么做怎么联系百度客服
  • 找别人做网站注意问题链接是什么意思
  • 河南省建设厅网站103关键词收录