- VisualStudio2022插件的安装及使用-编程手把手系列文章
- pprof-在现网场景怎么用
- C#实现的下拉多选框,下拉多选树,多级节点
- 【学习笔记】基础数据结构:猫树
https://github.com/OblivionOcean/Goh 。
Goh 是一款Go语言的预编译快速模板引擎.
English | 简体中文 。
从 https://github.com/slinso/goTemplateBenchmark 获取,目前为本地测试结果,代码与Hero部分的测试代码相同,BenchmarkComplexGoDirectBuffer和BenchmarkComplexGoStaticString分别是写入Buffer和静态String,所以不做计算,因此复杂模板测试排名第一 。
goos: windows goarch: amd64 pkg: github.com/SlinSo/goTemplateBenchmark cpu: Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz # 复杂模板测试 BenchmarkComplexGolang-16 36800 31428 ns/op 6562 B/op 290 allocs/op BenchmarkComplexGolangText-16 88148 13370 ns/op 2235 B/op 107 allocs/op BenchmarkComplexEgo-16 486294 2411 ns/op 568 B/op 31 allocs/op BenchmarkComplexQuicktemplate-16 1367928 878.1 ns/op 0 B/op 0 allocs/op BenchmarkComplexTempl-16 788673 1400 ns/op 408 B/op 11 allocs/op BenchmarkComplexFtmpl-16 293755 3982 ns/op 3534 B/op 38 allocs/op BenchmarkComplexFtmplInclude-16 317361 4142 ns/op 3534 B/op 38 allocs/op BenchmarkComplexMustache-16 90567 13748 ns/op 7274 B/op 156 allocs/op BenchmarkComplexGorazor-16 361304 3195 ns/op 3688 B/op 24 allocs/op BenchmarkComplexJetHTML-16 189176 5928 ns/op 532 B/op 5 allocs/op BenchmarkComplexHero-16 1410391 863.5 ns/op 0 B/op 0 allocs/op BenchmarkComplexGoh-16 2304783 535.4 ns/op 0 B/op 0 allocs/op BenchmarkComplexJade-16 1826784 651.8 ns/op 0 B/op 0 allocs/op BenchmarkComplexGoDirectBuffer-16 2890996 414.6 ns/op 0 B/op 0 allocs/op BenchmarkComplexGoHyperscript-16 1717754 778.6 ns/op 0 B/op 0 allocs/op BenchmarkComplexGoStaticString-16 84003024 14.44 ns/op 0 B/op 0 allocs/op # 简单模板测试 BenchmarkGolang-16 300493 3691 ns/op 768 B/op 35 allocs/op BenchmarkGolangText-16 1000000 1073 ns/op 128 B/op 7 allocs/op BenchmarkGoDirectBuffer-16 21959280 55.81 ns/op 0 B/op 0 allocs/op BenchmarkGoCustomHtmlAPI-16 14034298 85.06 ns/op 0 B/op 0 allocs/op BenchmarkGoFunc3-16 14962965 68.62 ns/op 0 B/op 0 allocs/op BenchmarkEgo-16 2577276 464.3 ns/op 85 B/op 8 allocs/op BenchmarkHB-16 280617 4445 ns/op 2448 B/op 51 allocs/op BenchmarkQuicktemplate-16 7013572 168.9 ns/op 0 B/op 0 allocs/op BenchmarkFtmpl-16 1000000 1000 ns/op 774 B/op 12 allocs/op BenchmarkAce-16 179811 6605 ns/op 1121 B/op 40 allocs/op BenchmarkAmber-16 268149 3800 ns/op 849 B/op 36 allocs/op BenchmarkMustache-16 523143 2636 ns/op 1722 B/op 30 allocs/op BenchmarkPongo2-16 350612 3862 ns/op 2074 B/op 32 allocs/op BenchmarkHandlebars-16 162860 7261 ns/op 3423 B/op 75 allocs/op BenchmarkGorazor-16 1562088 772.3 ns/op 512 B/op 5 allocs/op BenchmarkSoy-16 639549 2200 ns/op 1224 B/op 19 allocs/op BenchmarkJetHTML-16 1960117 600.4 ns/op 0 B/op 0 allocs/op BenchmarkHero-16 10452396 113.9 ns/op 0 B/op 0 allocs/op BenchmarkGoh-16 14838537 81.97 ns/op 0 B/op 0 allocs/op BenchmarkJade-16 15025261 78.85 ns/op 0 B/op 0 allocs/op BenchmarkTempl-16 4015622 293.1 ns/op 96 B/op 2 allocs/op BenchmarkGomponents-16 479330 2882 ns/op 1112 B/op 56 allocs/op ok github.com/SlinSo/goTemplateBenchmark 65.553s
go get -u github.com/OblivionOcean/Goh go install github.com/OblivionOcean/Goh # 依赖 go get golang.org/x/tools/cmd/goimports go install golang.org/x/tools/cmd/goimports
~ $ Goh Usage of ./Goh: -dest string generated golang files dir, it will be the same with source if not set -ext string source file extensions, comma splitted if many (default ".html") -pkg string the generated template package name, default is template (default "template") -src string the html template file or directory (default "./")
完整的使用方法请参考实例程序 。
<%: func UserList(title string, userList []string, buf *bytes.Buffer) %> <%= title %> <%= title %>
<% for _, user :=range userList { %> <% if user !="Alice" { %> - <%= user %>
<% } %> <% } %>
package main import ( "bytes" "net/http" "github.com/OblivionOcean/Goh/example/template" ) func main() { http.HandleFunc("/users", func(w http.ResponseWriter, req *http.Request) { var userList = []string{ "Alice", "Bob", "Tom", } buffer := new(bytes.Buffer) template.UserList("User List", userList, buffer) w.Write(buffer.Bytes()) }) http.ListenAndServe(":8080", nil) }
文档修改自https://github.com/shiyanhui/hero 。
Goh总共有九种语句,他们分别是:
<%: func define %>
*bytes.Buffer
hoặcio.Writer
, hero会自动识别该参数的名字,并把把结果写到该参数里。<%: func UserList(userList []string, buffer *bytes.Buffer) %>
<%: func UserList(userList []string, w io.Writer) %>
<%: func UserList(userList []string, w io.Writer) (int, error) %>
<%~ "parent template" %>
<%~ "index.html" >
<%+ "sub template" %>
C++
TRONG#include
有点类似。<%+ "user.html" >
<%! go code %>
<%! import ( "fmt" "strings" ) var a int const b = "hello, world" func Add(a, b int) int { return a + b } type S struct { Name string } func (s S) String() string { return s.Name } %>
<%@ blockName { %> <% } %>
暂不支持该语法,请使用其他方式代替.
<% go code %>
<% for _, user := range userList { %> <% if user != "Alice" { %> <%= user %> <% } %> <% } %> <% a, b := 1, 2 c := Add(a, b) %>
<%==[t] variable %>
,<%- variable %>
t
是变量的类型,hero会自动根据t
来选择转换函数。t
的待选值有:b
: boolTôi
: int, int8, int16, int32, int64bạn
: byte, uint, uint8, uint16, uint32, uint64f
: float32, float64S
: stringbs
: []bytev
: interfaceĐể ý:
t
没有设置,那么t
默认为S
.v
,因为其对应的转换函数为fmt.Sprintf("%v", variable)
,该函数很慢。<%== "hello" %> <%==i 34 %> <%==u Add(a, b) %> <%==s user.Name %>
<%= statement %>
html.EscapesString
记性转义。t
跟上面原生值语句中的t
一样。<%= a %> <%= a + b %> <%= Add(a, b) %> <%= user.Name %>
<%# note %>
<# 这是一个注释 >
.Shiyanhui/hero 。
最后此篇关于Goh:一款Go语言的预编译快速模板引擎。(Benchmark排名第一)的文章就讲到这里了,如果你想了解更多关于Goh:一款Go语言的预编译快速模板引擎。(Benchmark排名第一)的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
是否有任何库或框架旨在促进从另一种成熟的编程语言中构建项目? 在 C++、java 等编程语言中指定逻辑、集合和复杂规则非常容易,但在 Makefile 中完成这些事情似乎是一场艰苦的战斗。我还没有深
我有这段代码可以用 clang 编译得很好(即使使用 -Weverything),但是 gcc 会发出错误。 #include #include #include using namespace
我有以下 block 头文件 BKE_mesh.h: /* Connectivity data */ typedef struct IndexNode { struct IndexNode *
我在我的一个项目中遇到了一个奇怪的问题。我的代码库依赖于一个外部库,其中包含一个名为 Dataset 的类. Dataset类私有(private)继承自 std::vector (其中 Sample
当使用 gcc、g++ 或 make 在终端中编译一个小型 C 或 C++ 项目时,我收到以下错误: /tmp/ccG1caGi.o: In function `main': main.c:(.tex
我正在尝试从 CVS 为 Windows 上的 Emacs 23.1.50 编译 CEDET,但在“第 6 步:打开 EDE...”时出现错误:“defvar:作为变量的符号值是无效的:cedet-m
我正在(重新)学习编程,我从 C 开始。我的 IDE(如果我可以这么说)是 Windows7 上的 cygwin(32 位)和 Visual-Studio 2010。我总是编译我用 gcc (cygw
我喜欢在模板类中使用本地类来执行类似“static if”的构造。但是我遇到了 gcc 4.8 不想编译我的代码的问题。但是 4.7 可以。 这个例子: #include #include #in
我有一个项目,必须仅使用 java 1.4 进行编译。但我计划使用mockito 编写一些单元测试。我想要一种在 pom 中指定的方法,以便 src/main/java 使用 jdk 1.4 编译,但
我想了解 PHP 编译过程是如何工作的。 假设我有一个名为funcs.php 的文件并且这个文件有三个函数,如果我include 或require 它,所有的在文件加载期间编译三个函数?或者源代码会被
编译工具链 我们写程序的时候用的都是集成开发环境 (IDE: Integrated Development Environment),集成开发环境可以极大地方便我们程序员编写程序,但是配置起来
当我编写一些 Scala 代码时,在尝试编译代码时收到一条奇怪的错误消息。我将代码分解为一个更简单的代码(从语义的角度来看这完全没有意义,但仍然显示了错误)。 scala> :paste // Ent
我正在编译一个 SCSS 文件,它似乎删除了我的评论。我可以使用什么命令来保留所有评论? >SASS input.scss output.css 我在 SCSS 中看到两种类型的注释。 // Comm
Đây là mã của tôi: #include typedef struct { const char *description; float value; int age; } swag
当您编译 grails war 时,我知道 .groovy 代码被编译为字节码类文件,但我不明白容器(例如 tomcat)如何在请求 GSP 时知道如何编译它们。容器了解 GSP 吗?安装在服务器上的
我正在努力将多个文件编译成一个通用程序。我收到一个错误: undefined reference to 'pi' 这是我的代码和 Makefile 的框架。我做错了什么?谢谢! 文件:calcPi.c
我尝试使用 LD_PRELOAD 来 Hook sprintf function ,所以我将打印到缓冲区的结果: #define _GNU_SOURCE #include #include int
我正在寻找最简单的方法来自动将 CoffeeScript 重新编译为 JS。 阅读documentation但仍然很难得到我想要的东西。 我需要它来监视文件夹 src/ 中的任何 *.coffee 文
我想使用定制waveformjs 。我发现this on SO但是,我不知道如何编译/安装波形来开始。我从 GitHub 克隆它并进行了更改,但是我不知道如何将其转换为 .js 文件。 最佳答案 为了
Thật khó để biết câu hỏi ở đây là gì. Câu hỏi này mơ hồ, không rõ ràng, không đầy đủ, quá rộng hoặc mang tính tu từ và không thể trả lời hợp lý theo hình thức hiện tại. Để được trợ giúp làm rõ vấn đề này để bạn có thể mở lại, hãy truy cập trung tâm trợ giúp. Đã đóng
Tôi là một lập trình viên xuất sắc, rất giỏi!