當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。