-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👔 update: update the context data binding logic
- remove Route.Validator field
- Loading branch information
Showing
7 changed files
with
59 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# TODO | ||
|
||
## new server | ||
|
||
```go | ||
srv := rux.NewServer() | ||
``` | ||
|
||
## context | ||
|
||
```go | ||
type ServiceProvider interface { | ||
Service(name string) any | ||
} | ||
|
||
type ServiceProviderFunc(name string) any | ||
|
||
// ServiceProviderFunc implements ServiceProvider | ||
func (f ServiceProviderFunc) Service(name string) any { | ||
return f(name) | ||
} | ||
|
||
type Context struct { | ||
// add service provider | ||
ProviderFunc ServiceProvider | ||
|
||
// app | ||
srv *Server | ||
app *Server | ||
app *Router | ||
} | ||
|
||
// Service returns a service by name. eg: c.Service("db") | ||
func (c *Context) Service(name string) any { | ||
return c.ProviderFunc(name) | ||
} | ||
``` | ||
|
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 |
---|---|---|
|
@@ -31,5 +31,5 @@ func decodeJSON(r io.Reader, ptr any) error { | |
return err | ||
} | ||
|
||
return validating(ptr) | ||
return Validate(ptr) | ||
} |
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 |
---|---|---|
|
@@ -32,5 +32,5 @@ func decodeXML(r io.Reader, obj any) error { | |
return err | ||
} | ||
|
||
return validating(obj) | ||
return Validate(obj) | ||
} |
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