Ejemplo n.º 1
0
func getJsonCodec() services.CodecService {
	codecService := services.NewWebCodecService()
	myCodecService := new(services.WebCodecService)
	codec, _ := codecService.GetCodec("application/json")
	myCodecService.AddCodec(codec)
	return myCodecService
}
Ejemplo n.º 2
0
func TestAPI_WriteResponseObject_CodecOptions(t *testing.T) {
	http := new(GowebHTTPResponder)
	codecService := new(codecsservices.WebCodecService)
	codecService.AddCodec(new(CodecOptionsTester))
	API := NewGowebAPIResponder(codecService, http)
	ctx := context_test.MakeTestContext()
	test_option := "test"
	ctx.CodecOptions().Set("test_option", test_option)

	testData := "data"

	API.WriteResponseObject(ctx, 200, testData)

	assert.Equal(t, context_test.TestResponseWriter.Output, `{"data":"`+testData+`","test_option":"`+test_option+`"}`)
}