Sync master into develop
- Add265faff4ba- Update "github.com/julienschmidt/httprouter" version in Godeps - Add28b9ff9e34
This commit is contained in:
		
							
								
								
									
										2
									
								
								Godeps/Godeps.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Godeps/Godeps.json
									
									
									
										generated
									
									
									
								
							| @ -4,7 +4,7 @@ | |||||||
| 	"Deps": [ | 	"Deps": [ | ||||||
| 		{ | 		{ | ||||||
| 			"ImportPath": "github.com/julienschmidt/httprouter", | 			"ImportPath": "github.com/julienschmidt/httprouter", | ||||||
| 			"Rev": "90d58bada7e6154006f2728ee09053271154a8f6" | 			"Rev": "aeec11926f7a8fab580383810e1b1bbba99bdaa7" | ||||||
| 		} | 		} | ||||||
| 	] | 	] | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										15
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								README.md
									
									
									
									
									
								
							| @ -313,6 +313,21 @@ 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 | ####HTML rendering | ||||||
|  |  | ||||||
|  | |||||||
| @ -155,7 +155,7 @@ func ensureNotPointer(obj interface{}) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func Validate(obj interface{}) error { | func Validate(obj interface{}, parents ...string) error { | ||||||
| 	typ := reflect.TypeOf(obj) | 	typ := reflect.TypeOf(obj) | ||||||
| 	val := reflect.ValueOf(obj) | 	val := reflect.ValueOf(obj) | ||||||
|  |  | ||||||
| @ -180,12 +180,19 @@ func Validate(obj interface{}) error { | |||||||
| 			if strings.Index(field.Tag.Get("binding"), "required") > -1 { | 			if strings.Index(field.Tag.Get("binding"), "required") > -1 { | ||||||
| 				fieldType := field.Type.Kind() | 				fieldType := field.Type.Kind() | ||||||
| 				if fieldType == reflect.Struct { | 				if fieldType == reflect.Struct { | ||||||
| 					err := Validate(fieldValue) | 					if reflect.DeepEqual(zero, fieldValue) { | ||||||
|  | 						return errors.New("Required " + field.Name) | ||||||
|  | 					} | ||||||
|  | 					err := Validate(fieldValue, field.Name) | ||||||
| 					if err != nil { | 					if err != nil { | ||||||
| 						return err | 						return err | ||||||
| 					} | 					} | ||||||
| 				} else if reflect.DeepEqual(zero, fieldValue) { | 				} 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 { | 				} else if fieldType == reflect.Slice && field.Type.Elem().Kind() == reflect.Struct { | ||||||
| 					err := Validate(fieldValue) | 					err := Validate(fieldValue) | ||||||
| 					if err != nil { | 					if err != nil { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user