-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Reindert Vetter
committed
Jun 8, 2020
1 parent
db2ed19
commit ccb1c50
Showing
11 changed files
with
109 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/lanvard/contract/inter" | ||
) | ||
|
||
type Api struct{} | ||
|
||
func (a Api) Handle(request inter.Request, next inter.Next) inter.Response { | ||
return next(request) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/lanvard/contract/inter" | ||
) | ||
|
||
type RouteModelBinding struct{} | ||
|
||
func (b RouteModelBinding) Handle(request inter.Request, next inter.Next) inter.Response { | ||
// request.App().Instance("user", func() model.User { | ||
// return model.User.Find(request.UrlValue("user")) | ||
// }) | ||
|
||
return next(request) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/lanvard/contract/inter" | ||
) | ||
|
||
type Web struct{} | ||
|
||
func (a Web) Handle(request inter.Request, next inter.Next) inter.Response { | ||
return next(request) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ type User struct { | |
email string | ||
} | ||
|
||
func NewUser(id int, fullName string) User { | ||
return User{id: id, email: fullName} | ||
func (u User) Find() User { | ||
return User{id: 1, email: "[email protected]"} | ||
} | ||
|
||
func NewUser(id int, email string) User { | ||
return User{id: id, email: email} | ||
} | ||
|
||
func (u User) ToMap() map[string]interface{} { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,42 @@ import ( | |
"lanvard/src/contract" | ||
) | ||
|
||
var User = struct { | ||
AllByRequest func(inter.Request) ([]contract.User, error) | ||
OneByRequest func(inter.Request) (contract.User, error) | ||
}{ | ||
AllByRequest: func(request inter.Request) ([]contract.User, error) { | ||
var err error | ||
var users []contract.User | ||
|
||
users = append(users, model.NewUser(5435, "[email protected]")) | ||
|
||
return users, err | ||
}, | ||
|
||
OneByRequest: func(request inter.Request) (contract.User, error) { | ||
var err error | ||
userId := request.UrlValue("user").Number() | ||
|
||
user := model.NewUser(userId, "[email protected]") | ||
return user, err | ||
}, | ||
type User struct { | ||
Request inter.Request | ||
} | ||
|
||
func (adapter User) All() []contract.User { | ||
users, err := adapter.AllE() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return users | ||
} | ||
|
||
func (adapter User) AllE() ([]contract.User, error) { | ||
var err error | ||
var users []contract.User | ||
|
||
users = append(users, model.NewUser(5435, "[email protected]")) | ||
|
||
return users, err | ||
} | ||
|
||
func (adapter User) Find() contract.User { | ||
user, err := adapter.FindE() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return user | ||
} | ||
|
||
func (adapter User) FindE() (contract.User, error) { | ||
userId, err := adapter.Request.UrlValue("user").NumberE() | ||
if err != nil { | ||
return _, err | ||
} | ||
|
||
return model.NewUser(userId, "[email protected]") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters