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

茌平做网站推广备份整个网站

茌平做网站推广,备份整个网站,wordpress插件合并,网站结构布局在go语言里面#xff0c;我们可以使用一个“类注释”的语法来来让编译器帮助我们在编译的时候将一些文件或者目录读取到指定的变量中来供我们使用。 go:embed语法#xff1a; //go:embed 文件或者目录路径 var 变量名 变量类型 说明#xff1a; 文件或者目录路径 可以…在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.FSfs_test.go使用示例 package mainimport (fmtnet/httptesting )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/staticdatas WriteEmbed.//// The files list is sorted by name but not by simple string comparison.// Instead, each files 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. elemp// q/ # dir. elemq// w/ # dir. elemw// q/r # dirq elemr// q/s/ # dirq elems// q/v # dirq elemv// q/s/t # dirq/s elemt// q/s/u # dirq/s elemu//// 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://www.hkea.cn/news/14403232/

相关文章:

  • 德宏州乡城建设局网站律师做网站
  • 《网站建设 补充合同学校网站建设项目可行性分析报告
  • 建设学校网站方案外包建设网站服务
  • 移动网站打不开解决办法网络销售培训学校
  • 网站怎么建立视频百度旗下推广平台有哪些
  • 南宁做网站 的网站建设佛
  • 国产最好的a级suv台州路桥区企业全网seo优化
  • 网站内容上传网站如何添加百度统计
  • 做外贸网站报价网站更新怎么做
  • 西安网站建设seo长宁区科技网站建设
  • 好的外贸网站特点wordpress镜像系统
  • 网站建设现状 数据一级域名做网站
  • 泰州公司做网站好看大方的企业网站源码.net
  • 东莞快速网站制作哪家强商务推广
  • php网站超市源码技术支持 长沙网站建设-创研科技
  • 志愿海南网站icp备案网站接入信息 ip地址段
  • 做期货都看哪个网站仁怀那里可以做网站
  • 怀化二医院网站室内设计网站平面案例
  • 南京网站seo服务陕西建设网最新消息
  • 三雷网站程序自己可以建设一个网站要钱
  • 响站怎么建设网站国家摄影网站
  • 自己怎么做商城网站吗网站建设对付客户
  • 连云港网站排名优化网站和app的关系
  • 设计官方网站收录图片的网站
  • 西安做网站微信公司哪家好天津建设工程信息网账号密码
  • 商城网站设计实训总结网站建设方投资成本
  • 百度h5可以做网站吗pixso在线设计平台
  • 北京pc端网站开发怀远网站建设哪家好
  • 网站建设 开票哪家网站开发好
  • 不锈钢网站哪家最专业织梦网站关闭手机版