本文整理匯總了Golang中github.com/facebookgo/inject.Populate函數的典型用法代碼示例。如果您正苦於以下問題:Golang Populate函數的具體用法?Golang Populate怎麽用?Golang Populate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Populate函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDoesNotOverwriteInterface
func TestDoesNotOverwriteInterface() {
i := 100
a := &TypeAnswerStruct{}
var v struct {
K *int `inject:""`
A Answerable `inject:""`
B *TypeNestedStruct `inject:""`
}
fmt.Println(v)
v.A = a
v.K = &i
/*
var g inject.Graph
if err := g.Provide(&inject.Object{Name: "inttest", Value: &i}); err != nil {
fmt.Println(err)
}
*/
if err := inject.Populate(&v); err != nil {
fmt.Println(err)
}
a.answer = 1
i = 99
fmt.Println(v.A)
fmt.Println(v.B)
fmt.Println(*v.K)
if v.A != a {
fmt.Println("original A was lost")
}
if v.B == nil {
fmt.Println("v.B is nil")
}
}
示例2: init
func init() {
// Filters is the default set of global filters.
revel.Filters = []revel.Filter{
CorsFilter,
revel.PanicFilter, // Recover from panics and display an error page instead.
revel.RouterFilter, // Use the routing table to select the right Action
revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
revel.ParamsFilter, // Parse parameters into Controller.Params.
// revel.SessionFilter, // Restore and write the session cookie.
// revel.FlashFilter, // Restore and write the flash cookie.
revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie.
revel.I18nFilter, // Resolve the requested language
HeaderFilter, // Add some security based headers
revel.InterceptorFilter, // Run interceptors around the action.
revel.CompressFilter, // Compress the result.
revel.ActionInvoker, // Invoke the action.
}
persistence.InitDb()
var app controllers.AccountController
if err := inject.Populate(&app); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
示例3: TestInjectWithStructValue
func TestInjectWithStructValue() {
var v TypeWithStructValue
if err := inject.Populate(&v); err != nil {
fmt.Println(err)
}
fmt.Println(v)
}
示例4: TestInterfaceIncludingPrivate
func TestInterfaceIncludingPrivate(t *testing.T) {
var v struct {
A Answerable `inject:""`
B *TypeNestedStruct `inject:"private"`
C *TypeAnswerStruct `inject:""`
}
if err := inject.Populate(&v); err != nil {
t.Fatal(err)
}
if v.A == nil {
t.Fatal("v.A is nil")
}
if v.B == nil {
t.Fatal("v.B is nil")
}
if v.C == nil {
t.Fatal("v.C is nil")
}
if v.A != v.C {
t.Fatal("v.A != v.C")
}
if v.A == v.B {
t.Fatal("v.A == v.B")
}
}
示例5: TestInterfaceIncludingPrivate
func TestInterfaceIncludingPrivate() {
var v struct {
A Answerable `inject:""`
B *TypeNestedStruct `inject:"private"`
C *TypeAnswerStruct `inject:""`
}
if err := inject.Populate(&v); err != nil {
fmt.Println(err)
}
fmt.Println(v)
if v.A == nil {
fmt.Println("v.A is nil")
}
if v.B == nil {
fmt.Println("v.B is nil")
}
if v.C == nil {
fmt.Println("v.C is nil")
}
if v.A != v.C {
fmt.Println("v.A != v.C")
}
if v.A == v.B {
fmt.Println("v.A == v.B")
}
}
示例6: TestInjectWithStructValue
func TestInjectWithStructValue(t *testing.T) {
var v TypeWithStructValue
if err := inject.Populate(&v); err != nil {
t.Fatal(err)
}
if v.Inline.A == nil {
t.Fatal("v.Inline.A is nil")
}
}
示例7: TagWithJustColon
func TagWithJustColon() {
var a TypeWithJustColon
err := inject.Populate(&a)
if err == nil {
fmt.Println(a)
} else {
fmt.Println(err)
}
}
示例8: initApp
func initApp() HomomorphicEncryptionBackendApp {
var app HomomorphicEncryptionBackendApp
inject.Populate(&app)
app.Router.init()
return app
}
示例9: TestInjectMap
func TestInjectMap(t *testing.T) {
var v struct {
A map[string]int `inject:"private"`
}
if err := inject.Populate(&v); err != nil {
t.Fatal(err)
}
if v.A == nil {
t.Fatal("v.A is nil")
}
}
示例10: TestErrorOnNonPointerStructInject
func TestErrorOnNonPointerStructInject(t *testing.T) {
var a TypeWithNonPointerStructInject
err := inject.Populate(&a)
if err == nil {
t.Fatalf("expected error for %+v", a)
}
const msg = "found inject tag on unsupported field A in type *inject_test.TypeWithNonPointerStructInject"
if err.Error() != msg {
t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
}
}
示例11: TestProvideTwoOfTheSameWithPopulate
func TestProvideTwoOfTheSameWithPopulate(t *testing.T) {
a := TypeAnswerStruct{}
err := inject.Populate(&a, &a)
if err == nil {
t.Fatal("expected error")
}
const msg = "provided two unnamed instances of type *github.com/facebookgo/inject_test.TypeAnswerStruct"
if err.Error() != msg {
t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
}
}
示例12: TestPrivateIsFollowed
func TestPrivateIsFollowed(t *testing.T) {
var v struct {
A *TypeNestedStruct `inject:"private"`
}
if err := inject.Populate(&v); err != nil {
t.Fatal(err)
}
if v.A.A == nil {
t.Fatal("v.A.A is nil")
}
}
示例13: TestInjectInterfaceMissing
func TestInjectInterfaceMissing(t *testing.T) {
var v TypeInjectInterfaceMissing
err := inject.Populate(&v)
if err == nil {
t.Fatal("did not find expected error")
}
const msg = "found no assignable value for field Answerable in type *inject_test.TypeInjectInterfaceMissing"
if err.Error() != msg {
t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
}
}
示例14: TestInjectTwoSatisfyInterface
func TestInjectTwoSatisfyInterface(t *testing.T) {
var v TypeInjectTwoSatisfyInterface
err := inject.Populate(&v)
if err == nil {
t.Fatal("did not find expected error")
}
const msg = "found two assignable values for field Answerable in type *inject_test.TypeInjectTwoSatisfyInterface. one type *inject_test.TypeAnswerStruct with value &{0 0} and another type *inject_test.TypeNestedStruct with value <*inject_test.TypeNestedStruct Value>"
if err.Error() != msg {
t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
}
}
示例15: TestInjectPrivateInterface
func TestInjectPrivateInterface(t *testing.T) {
var v TypeInjectPrivateInterface
err := inject.Populate(&v)
if err == nil {
t.Fatal("did not find expected error")
}
const msg = "found private inject tag on interface field Answerable in type *inject_test.TypeInjectPrivateInterface"
if err.Error() != msg {
t.Fatalf("expected:\n%s\nactual:\n%s", msg, err.Error())
}
}