当前位置: 首页>>代码示例>>Golang>>正文


Golang goson.Render函数代码示例

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


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


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