• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang goson.Render函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/emilsjolander/goson.Render函数的典型用法代码示例。如果您正苦于以下问题:Golang Render函数的具体用法?Golang Render怎么用?Golang Render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Render函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

func main() {

	user := &User{
		Name: "Emil Sjölander",
		Repos: []Repo{
			Repo{
				Name:  "goson",
				Url:   "https://github.com/emilsjolander/goson",
				Stars: 0,
				Forks: 0,
			},
			Repo{
				Name:  "StickyListHeaders",
				Url:   "https://github.com/emilsjolander/StickyListHeaders",
				Stars: 722,
				Forks: 197,
			},
			Repo{
				Name:  "android-FlipView",
				Url:   "https://github.com/emilsjolander/android-FlipView",
				Stars: 157,
				Forks: 47,
			},
		},
	}

	result, err := goson.Render("user", goson.Args{"User": user})

	if err != nil {
		panic(err)
	}

	fmt.Println(string(result))
}
开发者ID:nathan-hoad,项目名称:goson,代码行数:34,代码来源:sample.go


示例2: TestInt

// Test rendering an int passed to Args. Test all sizes of ints
func TestInt(t *testing.T) {
	result, err := goson.Render("templates/int", goson.Args{"int": int(-1), "int8": int8(2), "int16": int16(3), "int32": int32(-4), "int64": int64(5)})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"int\":-1,\"int8\":2,\"int16\":3,\"int32\":-4,\"int64\":5}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:input_test.go


示例3: TestUint

// Test rendering an uint passed to Args. Test all sizes of uints
func TestUint(t *testing.T) {
	result, err := goson.Render("templates/uint", goson.Args{"uint": uint(10), "uint8": uint8(20), "uint16": uint16(30), "uint32": uint32(40), "uint64": uint64(50)})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"uint\":10,\"uint8\":20,\"uint16\":30,\"uint32\":40,\"uint64\":50}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:input_test.go


示例4: TestFloat

// Test rendering a float passed to Args. Test all sizes of floats
func TestFloat(t *testing.T) {
	result, err := goson.Render("templates/float", goson.Args{"float32": float32(32.32), "float64": float64(64.64)})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"float32\":32.32,\"float64\":64.64}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:input_test.go


示例5: TestJSONMarshaler

// Test rendering a json.Marshaler interface passed to Args
func TestJSONMarshaler(t *testing.T) {
	result, err := goson.Render("templates/marshaler", goson.Args{"marshaler": &time.Time{}})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"json\":\"0001-01-01T00:00:00Z\"}" {
		t.Error("json did not match")
	}
}
开发者ID:hooblei,项目名称:goson,代码行数:9,代码来源:input_test.go


示例6: TestConstants

// Test rendering of constants in the template. string, int, float, bool and object literals
func TestConstants(t *testing.T) {
	result, err := goson.Render("templates/constants", goson.Args{})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"object\":{\"string\":\"hej\",\"int\":123,\"float\":1.23,\"bool\":true}}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:syntax_test.go


示例7: TestBool

// Test rendering a bool passed to Args.
func TestBool(t *testing.T) {
	result, err := goson.Render("templates/bool", goson.Args{"bool": true})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"bool\":true}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:input_test.go


示例8: TestString

// Test rendering a string passed to Args.
func TestString(t *testing.T) {
	result, err := goson.Render("templates/string", goson.Args{"string": "a string"})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"string\":\"a string\"}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:input_test.go


示例9: TestFunction

// Test rendering a function passed to Args.
func TestFunction(t *testing.T) {
	result, err := goson.Render("templates/function", goson.Args{"MyFunc": func() int { return 1337 }})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"func_result\":1337}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:input_test.go


示例10: TestComments

// Test commenting out lines with both single and multiline syntax
func TestComments(t *testing.T) {
	result, err := goson.Render("templates/comments", goson.Args{})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"first\":1,\"third\":3,\"fifth\":5}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:syntax_test.go


示例11: TestMethod

// Test rendering a method attached to a struct passed to Args.
func TestMethod(t *testing.T) {
	result, err := goson.Render("templates/method", goson.Args{"MyStruct": new(MethodTester)})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"my_struct\":{\"method\":\"method test\"}}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:9,代码来源:input_test.go


示例12: TestSliceOfPrimitives

// Test rendering a slice of primites where the primitives are looped over and wrapped in json objects.
func TestSliceOfPrimitives(t *testing.T) {
	ints := []int{1, 2, 4, 8}
	result, err := goson.Render("templates/slice_of_ints", goson.Args{"Ints": ints})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"ints\":[{\"int\":1},{\"int\":2},{\"int\":4},{\"int\":8}]}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:10,代码来源:input_test.go


示例13: TestStructPtr

// Test rendering a pointer to a struct passed to Args.
func TestStructPtr(t *testing.T) {
	myStruct := struct{ MyString string }{MyString: "MyString"}
	result, err := goson.Render("templates/struct", goson.Args{"MyStruct": &myStruct})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"my_struct\":{\"my_string\":\"MyString\"}}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:10,代码来源:input_test.go


示例14: TestMap

// Test rendering a map passed to Args.
func TestMap(t *testing.T) {
	myMap := map[string]string{"key1": "key 1!", "key2": "key 2!", "key3": "key 3!"}
	result, err := goson.Render("templates/map", goson.Args{"MyMap": myMap})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"my_map\":{\"key1\":\"key 1!\",\"key2\":\"key 2!\",\"key3\":\"key 3!\"}}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:10,代码来源:input_test.go


示例15: TestAnonymousEmbeddedStruct

// Test rendering methods and properties of a anonymous embedded struct
func TestAnonymousEmbeddedStruct(t *testing.T) {
	v := &Outer{Inner{Property: "property"}}
	result, err := goson.Render("templates/anonymous_embedded_struct", goson.Args{"Outer": v})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"my_struct\":{\"property\":\"property\",\"method\":\"method\"}}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:10,代码来源:input_test.go


示例16: TestLoop

// Test looping over a slice
func TestLoop(t *testing.T) {
	type Item struct{ Id int }
	items := []Item{Item{1}, Item{12}, Item{123}}
	result, err := goson.Render("templates/loop", goson.Args{"Items": items})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"items\":[{\"id\":1},{\"id\":12},{\"id\":123}]}" {
		t.Error("json did not match ")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:11,代码来源:syntax_test.go


示例17: TestInclude

// Test including a template with arguments
func TestInclude(t *testing.T) {
	type MyStruct struct{ MyString string }
	myStruct := MyStruct{"hej!"}
	result, err := goson.Render("templates/include", goson.Args{"MyStruct": myStruct})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"a_string\":\"rendering a include\",\"my_included_string\":\"hej!\"}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:11,代码来源:syntax_test.go


示例18: TestJSONMarshalerCollection

// Test rendering a json.Marshaler within a slice
func TestJSONMarshalerCollection(t *testing.T) {
	v1 := []time.Time{time.Time{}}
	v2 := []*time.Time{&time.Time{}}
	result, err := goson.Render("templates/marshaler_collection", goson.Args{"v1": v1, "v2": v2})
	if err != nil {
		t.Error(err)
	} else if string(result) != `{"v1":["0001-01-01T00:00:00Z"],"v2":["0001-01-01T00:00:00Z"]}` {
		t.Error("json did not match")
	}
}
开发者ID:hooblei,项目名称:goson,代码行数:11,代码来源:input_test.go


示例19: TestSliceOfMaps

// Test rendering a slice of maps.
func TestSliceOfMaps(t *testing.T) {
	type Object map[string]string
	objects := []Object{Object{"StringField": "hej"}, Object{"StringField": "jag"}, Object{"StringField": "heter"}, Object{"StringField": "emil"}}
	result, err := goson.Render("templates/slice_of_objects", goson.Args{"Objects": objects})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"objects\":[{\"string\":\"hej\"},{\"string\":\"jag\"},{\"string\":\"heter\"},{\"string\":\"emil\"}]}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:11,代码来源:input_test.go


示例20: TestAlias

// Test aliasing a struct
func TestAlias(t *testing.T) {
	type InnerStruct struct{ MyString string }
	type MyStruct struct{ MyInnerStruct InnerStruct }
	myStruct := MyStruct{InnerStruct{"hej!"}}
	result, err := goson.Render("templates/alias", goson.Args{"MyStruct": myStruct})
	if err != nil {
		t.Error(err)
	} else if string(result) != "{\"object\":{\"string\":\"hej!\"}}" {
		t.Error("json did not match")
	}
}
开发者ID:MarkBruns,项目名称:goson,代码行数:12,代码来源:syntax_test.go



注:本文中的github.com/emilsjolander/goson.Render函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ssh.PublicKey类代码示例发布时间:2022-05-23
下一篇:
Golang swagger.RegisterSwaggerService函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap