-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from maxzhang1985/dev
Dev
- Loading branch information
Showing
37 changed files
with
393 additions
and
373 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ResponseRender | ||
package ActionResult | ||
|
||
import ( | ||
"io/ioutil" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ResponseRender | ||
package ActionResult | ||
|
||
import ( | ||
"github.com/ugorji/go/codec" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ResponseRender | ||
package ActionResult | ||
|
||
import ( | ||
"github.com/golang/protobuf/proto" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ResponseRender | ||
package ActionResult | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ResponseRender | ||
package ActionResult | ||
|
||
import ( | ||
"fmt" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ResponseRender | ||
package ActionResult | ||
|
||
import ( | ||
"encoding/xml" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ResponseRender | ||
package ActionResult | ||
|
||
import ( | ||
"gopkg.in/yaml.v2" | ||
|
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 |
---|---|---|
@@ -1,79 +1,79 @@ | ||
package Context | ||
|
||
import ( | ||
"github.com/maxzhang1985/yoyogo/ResponseRender" | ||
"github.com/maxzhang1985/yoyogo/ActionResult" | ||
"net/http" | ||
) | ||
|
||
func (ctx *HttpContext) HTML(code int, name string, obj interface{}) { | ||
htmlRender := ResponseRender.HTMLDebug{Files: nil, | ||
htmlRender := ActionResult.HTMLDebug{Files: nil, | ||
Glob: "../Static/template/**", | ||
Delims: ResponseRender.Delims{Left: "{[{", Right: "}]}"}, | ||
Delims: ActionResult.Delims{Left: "{[{", Right: "}]}"}, | ||
FuncMap: nil, | ||
} | ||
instance := htmlRender.Instance(name, obj) | ||
_ = instance.Render(ctx.Resp) | ||
} | ||
|
||
func (ctx *HttpContext) IndentedJSON(code int, obj interface{}) { | ||
ctx.Render(code, ResponseRender.IndentedJson{Data: obj}) | ||
ctx.Render(code, ActionResult.IndentedJson{Data: obj}) | ||
} | ||
|
||
func (c *HttpContext) SecureJSON(code int, obj interface{}) { | ||
c.Render(code, ResponseRender.SecureJson{Prefix: "", Data: obj}) | ||
c.Render(code, ActionResult.SecureJson{Prefix: "", Data: obj}) | ||
} | ||
|
||
func (c *HttpContext) JSONP(code int, obj interface{}) { | ||
callback := c.QueryStringOrDefault("callback", "") | ||
if callback == "" { | ||
c.Render(code, ResponseRender.Json{Data: obj}) | ||
c.Render(code, ActionResult.Json{Data: obj}) | ||
return | ||
} | ||
c.Render(code, ResponseRender.Jsonp{Callback: callback, Data: obj}) | ||
c.Render(code, ActionResult.Jsonp{Callback: callback, Data: obj}) | ||
} | ||
|
||
func (c *HttpContext) JSON(code int, obj interface{}) { | ||
c.Render(code, ResponseRender.Json{Data: obj}) | ||
c.Render(code, ActionResult.Json{Data: obj}) | ||
} | ||
|
||
// AsciiJSON serializes the given struct as JSON into the response body with unicode to ASCII string. | ||
// It also sets the Content-Type as "application/json". | ||
func (c *HttpContext) AsciiJSON(code int, obj interface{}) { | ||
c.Render(code, ResponseRender.AsciiJson{Data: obj}) | ||
c.Render(code, ActionResult.AsciiJson{Data: obj}) | ||
} | ||
|
||
// PureJSON serializes the given struct as JSON into the response body. | ||
// PureJSON, unlike JSON, does not replace special html characters with their unicode entities. | ||
func (c *HttpContext) PureJSON(code int, obj interface{}) { | ||
c.Render(code, ResponseRender.PureJson{Data: obj}) | ||
c.Render(code, ActionResult.PureJson{Data: obj}) | ||
} | ||
|
||
// XML serializes the given struct as XML into the response body. | ||
// It also sets the Content-Type as "application/xml". | ||
func (c *HttpContext) XML(code int, obj interface{}) { | ||
c.Render(code, ResponseRender.XML{Data: obj}) | ||
c.Render(code, ActionResult.XML{Data: obj}) | ||
} | ||
|
||
// YAML serializes the given struct as YAML into the response body. | ||
func (c *HttpContext) YAML(code int, obj interface{}) { | ||
c.Render(code, ResponseRender.YAML{Data: obj}) | ||
c.Render(code, ActionResult.YAML{Data: obj}) | ||
} | ||
|
||
// ProtoBuf serializes the given struct as ProtoBuf into the response body. | ||
func (c *HttpContext) ProtoBuf(code int, obj interface{}) { | ||
c.Render(code, ResponseRender.ProtoBuf{Data: obj}) | ||
c.Render(code, ActionResult.ProtoBuf{Data: obj}) | ||
} | ||
|
||
// String writes the given string into the response body. | ||
func (c *HttpContext) Text(code int, format string, values ...interface{}) { | ||
c.Render(code, ResponseRender.Text{Format: format, Data: values}) | ||
c.Render(code, ActionResult.Text{Format: format, Data: values}) | ||
} | ||
|
||
func (c *HttpContext) File(filepath string) { | ||
http.ServeFile(c.Resp, c.Req, filepath) | ||
} | ||
|
||
func (c *HttpContext) FileStream(code int, bytes []byte) { | ||
render := ResponseRender.FormFileStream(bytes) | ||
render := ActionResult.FormFileStream(bytes) | ||
c.Render(code, render) | ||
} |
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,14 @@ | ||
package Controller | ||
|
||
type ApiController struct { | ||
} | ||
|
||
func (c *ApiController) GetView() string { | ||
return "" | ||
} | ||
|
||
type IController interface { | ||
GetView() string | ||
//ViewData interface{} | ||
//Data interface{} | ||
} |
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
package Controller | ||
|
||
type RequestParam struct { | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,18 @@ | ||
package DependencyInjection | ||
|
||
import "github.com/maxzhang1985/inject" | ||
import "github.com/defval/inject/v2" | ||
|
||
type DefaultServiceProvider struct { | ||
container *inject.Container | ||
} | ||
|
||
func (d DefaultServiceProvider) GetService(refObject interface{}) (err error) { | ||
err = d.container.Extract(refObject) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return err | ||
} | ||
|
||
func (d DefaultServiceProvider) GetServiceByName(refObject interface{}, name string) (err error) { | ||
err = d.container.Extract(refObject, inject.Name(name)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return err | ||
} |
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
Oops, something went wrong.