mirror of
				https://github.com/labstack/echo.git
				synced 2025-10-30 23:57:38 +02:00 
			
		
		
		
	exposed read timeout, write timeout properties, updated docs
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
		
							
								
								
									
										14
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								README.md
									
									
									
									
									
								
							| @@ -34,10 +34,16 @@ | ||||
|  | ||||
| **Use issues for everything** | ||||
|  | ||||
| - Report issues | ||||
| - Discuss on chat before sending a pull request | ||||
| - Suggest new features or enhancements | ||||
| - Improve/fix documentation | ||||
| - For a small change, just send a PR. | ||||
| - For bigger changes open an issue for discussion before sending a PR. | ||||
| - PR should have: | ||||
|   - Test case | ||||
|   - Documentation | ||||
|   - Recipe (If it makes sense) | ||||
| - You can also contribute by: | ||||
|   - Reporting issues | ||||
|   - Suggesting new features or enhancements | ||||
|   - Improve/fix documentation | ||||
|  | ||||
| ## Credits | ||||
| - [Vishal Rana](https://github.com/vishr) - Author | ||||
|   | ||||
							
								
								
									
										20
									
								
								echo.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								echo.go
									
									
									
									
									
								
							| @@ -66,9 +66,12 @@ type ( | ||||
| 		Validator        Validator | ||||
| 		Renderer         Renderer | ||||
| 		AutoTLSManager   autocert.Manager | ||||
| 		ReadTimeout      time.Duration | ||||
| 		WriteTimeout     time.Duration | ||||
| 		ShutdownTimeout  time.Duration | ||||
| 		Color            *color.Color | ||||
| 		Logger           Logger | ||||
| 		stdLogger        *slog.Logger | ||||
| 		server           *graceful.Server | ||||
| 		tlsServer        *graceful.Server | ||||
| 		premiddleware    []MiddlewareFunc | ||||
| @@ -249,6 +252,7 @@ func New() (e *Echo) { | ||||
| 	e.HTTPErrorHandler = e.DefaultHTTPErrorHandler | ||||
| 	e.Binder = &DefaultBinder{} | ||||
| 	e.Logger.SetLevel(log.OFF) | ||||
| 	e.stdLogger = slog.New(e.Logger.Output(), e.Logger.Prefix()+": ", 0) | ||||
| 	e.pool.New = func() interface{} { | ||||
| 		return e.NewContext(nil, nil) | ||||
| 	} | ||||
| @@ -519,7 +523,12 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||||
|  | ||||
| // Start starts the HTTP server. | ||||
| func (e *Echo) Start(address string) error { | ||||
| 	return e.StartServer(&http.Server{Addr: address}) | ||||
| 	return e.StartServer(&http.Server{ | ||||
| 		Addr:         address, | ||||
| 		ReadTimeout:  e.ReadTimeout, | ||||
| 		WriteTimeout: e.WriteTimeout, | ||||
| 		ErrorLog:     e.stdLogger, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| // StartTLS starts the HTTPS server. | ||||
| @@ -548,8 +557,11 @@ func (e *Echo) startTLS(address string, config *tls.Config) error { | ||||
| 		config.NextProtos = append(config.NextProtos, "h2") | ||||
| 	} | ||||
| 	return e.StartServer(&http.Server{ | ||||
| 		Addr:      address, | ||||
| 		TLSConfig: config, | ||||
| 		Addr:         address, | ||||
| 		ReadTimeout:  e.ReadTimeout, | ||||
| 		WriteTimeout: e.WriteTimeout, | ||||
| 		TLSConfig:    config, | ||||
| 		ErrorLog:     e.stdLogger, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| @@ -559,7 +571,7 @@ func (e *Echo) StartServer(s *http.Server) error { | ||||
| 	gs := &graceful.Server{ | ||||
| 		Server:  s, | ||||
| 		Timeout: e.ShutdownTimeout, | ||||
| 		Logger:  slog.New(e.Logger.Output(), e.Logger.Prefix()+": ", 0), | ||||
| 		Logger:  e.stdLogger, | ||||
| 	} | ||||
| 	if s.TLSConfig == nil { | ||||
| 		e.server = gs | ||||
|   | ||||
| @@ -7,15 +7,10 @@ description = "Customizing Echo" | ||||
|   weight = 3 | ||||
| +++ | ||||
|  | ||||
| ## HTTP Error Handler | ||||
| ## Debug | ||||
|  | ||||
| `Echo#HTTPErrorHandler` can be used to set custom http error handler. | ||||
|  | ||||
| [Learn more](/guide/error-handling) | ||||
|  | ||||
| ## Debugging | ||||
|  | ||||
| `Echo#Debug` can be used to enable / disable debug mode. | ||||
| `Echo#Debug` can be used to enable / disable debug mode. Debug mode sets the log level | ||||
| to `DEBUG`. | ||||
|  | ||||
| ## Logging | ||||
|  | ||||
| @@ -24,12 +19,12 @@ description = "Customizing Echo" | ||||
| `Echo#Logger.SetOutput(io.Writer)` can be used to set the output destination for | ||||
| the logger. Default value is `os.Stdout` | ||||
|  | ||||
| To completely disable logs use `Echo#Logger.SetOutput(io.Discard)` or `Echo#Logger.SetLevel(log.OFF)` | ||||
| To completely disabl logs use `Echo#Logger.SetOutput(io.Discard)` or `Echo#Logger.SetLevel(log.OFF)` | ||||
|  | ||||
| ### Log Level | ||||
|  | ||||
| `Echo#Logger.SetLevel(log.Lvl)` can be used to set the log level for the logger. | ||||
| Default value `OFF`. Possible values: | ||||
| Default value is `OFF`. Possible values: | ||||
|  | ||||
| - `DEBUG` | ||||
| - `INFO` | ||||
| @@ -37,6 +32,67 @@ Default value `OFF`. Possible values: | ||||
| - `ERROR` | ||||
| - `OFF` | ||||
|  | ||||
| Logging is implemented using `echo.Logger` interface which allows you to use a | ||||
| custom logger. Custom logger can be set using `Echo#Logger`. | ||||
| ### Custom Logger | ||||
|  | ||||
| Logging is implemented using `echo.Logger` interface which allows you to register | ||||
| a custom logger using `Echo#Logger`. | ||||
|  | ||||
| ## Custom Server | ||||
|  | ||||
| `Echo#StartServer()` can be used to run a custom `http.Server`.  | ||||
|  | ||||
| *Example* | ||||
|  | ||||
| ```go | ||||
| s := &http.Server{ | ||||
|   Addr:         ":1323", | ||||
|   ReadTimeout:  20 * time.Minute, | ||||
|   WriteTimeout: 20 * time.Minute, | ||||
| } | ||||
| e.Logger.Fatal(e.StartServer(s)) | ||||
| ``` | ||||
|  | ||||
| ## Disable HTTP/2 | ||||
|  | ||||
| `Echo#DisableHTTP2` can be used disable HTTP/2 protocol. | ||||
|  | ||||
| ## Read Timeout | ||||
|  | ||||
| `Echo#ReadTimeout` can be used to set the maximum duration before timing out read | ||||
| of the request. | ||||
|  | ||||
| ## Write Timeout | ||||
|  | ||||
| `Echo#WriteTimeout` can be used to set the maximum duration before timing out write | ||||
| of the response. | ||||
|  | ||||
| ## Shutdown Timeout | ||||
|  | ||||
| `Echo#ShutdownTimeout` can be used to set the maximum duration to wait until killing | ||||
| active requests and stopping the server. If timeout is 0, the server never times | ||||
| out. It waits for all active requests to finish. | ||||
|  | ||||
| ## Validator | ||||
|  | ||||
| `Echo#Validator` can be used to register a validator for performing data validation | ||||
| on request payload. | ||||
|  | ||||
| [Learn more](/guide/request#validate-data) | ||||
|  | ||||
| ## Custom Binder | ||||
|  | ||||
| `Echo#Binder` can be used to register a custom binder for binding request payload. | ||||
|  | ||||
| [Learn more](/guide/request/#custom-binder) | ||||
|  | ||||
| ## Renderer | ||||
|  | ||||
| `Echo#Renderer` can be used to register a renderer for template rendering. | ||||
|  | ||||
| [Learn more](/guide/templates) | ||||
|  | ||||
| ## HTTP Error Handler | ||||
|  | ||||
| `Echo#HTTPErrorHandler` can be used to register a custom http error handler. | ||||
|  | ||||
| [Learn more](/guide/error-handling) | ||||
|   | ||||
| @@ -162,8 +162,8 @@ $ curl http://localhost:1323/users/Joe | ||||
|  | ||||
| ## Validate Data | ||||
|  | ||||
| Echo doesn't have built-in data validation capabilities, however you can set a | ||||
| custom validator using `Echo#Validator` and leverage third-party [libraries](https://github.com/avelino/awesome-go#validation). | ||||
| Echo doesn't have a built-in data validation capabilities, however, you can register | ||||
| a custom validator using `Echo#Validator` and leverage third-party [libraries](https://github.com/avelino/awesome-go#validation). | ||||
|  | ||||
| Example below uses https://github.com/go-playground/validator framework for validation: | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user