From 772d7d299722bda58e71abbd6e64d88836e12c92 Mon Sep 17 00:00:00 2001 From: dickeyxxx Date: Sun, 6 Jul 2014 15:18:54 -0700 Subject: [PATCH 1/4] added example on using Static --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 53efb20..dc9b1a8 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,22 @@ func main() { ``` +####Serving static files + +Use Engine.ServeFiles(path string, root http.FileSystem): + +```go +func main() { + r := gin.Default() + r.Static("/assets", "./assets") + + // Listen and server on 0.0.0.0:8080 + r.Run(":8080") +} +``` + +Note: this will use `httpNotFound` instead of the Router's `NotFound` handler. + ####HTML rendering Using LoadHTMLTemplates() From a1c9c0e2d451511a63c1d93f64b2929430e967ef Mon Sep 17 00:00:00 2001 From: Andre Dublin <81dublin@gmail.com> Date: Fri, 18 Jul 2014 17:08:37 -0400 Subject: [PATCH 2/4] spelling Signed-off-by: Andre Dublin <81dublin@gmail.com> --- context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context.go b/context.go index 17ba45c..80d2ed8 100644 --- a/context.go +++ b/context.go @@ -182,7 +182,7 @@ func (c *Context) MustGet(key string) interface{} { } /************************************/ -/******** ENCOGING MANAGEMENT********/ +/******** ENCODING MANAGEMENT********/ /************************************/ // This function checks the Content-Type to select a binding engine automatically, From 06e9f9497026730c8bfb6ac7ae6337a250024f12 Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Fri, 22 Aug 2014 15:32:41 +0200 Subject: [PATCH 3/4] Added nil check for embedded structs --- binding/binding.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/binding/binding.go b/binding/binding.go index bb6cbde..92ede2b 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -176,6 +176,10 @@ func Validate(obj interface{}) error { if strings.Index(field.Tag.Get("binding"), "required") > -1 { fieldType := field.Type.Kind() if fieldType == reflect.Struct { + if reflect.DeepEqual(zero, fieldValue) { + return errors.New("Required " + field.Name) + } + err := Validate(fieldValue) if err != nil { return err From d7f4db4ad34c2d4abf93fd0fce461f56cea4291d Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Fri, 22 Aug 2014 15:54:26 +0200 Subject: [PATCH 4/4] Added reference to parent structs --- binding/binding.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/binding/binding.go b/binding/binding.go index 92ede2b..3670fd9 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -151,7 +151,7 @@ func ensureNotPointer(obj interface{}) { } } -func Validate(obj interface{}) error { +func Validate(obj interface{}, parents ...string) error { typ := reflect.TypeOf(obj) val := reflect.ValueOf(obj) @@ -179,13 +179,16 @@ func Validate(obj interface{}) error { if reflect.DeepEqual(zero, fieldValue) { return errors.New("Required " + field.Name) } - - err := Validate(fieldValue) + err := Validate(fieldValue, field.Name) if err != nil { return err } } else if reflect.DeepEqual(zero, fieldValue) { - return errors.New("Required " + field.Name) + if len(parents) > 0 { + return errors.New("Required " + field.Name + " on " + parents[0]) + } else { + return errors.New("Required " + field.Name) + } } else if fieldType == reflect.Slice && field.Type.Elem().Kind() == reflect.Struct { err := Validate(fieldValue) if err != nil {