-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Changelog ## Improvements - ⚙️ [config] Added validation for config file content #40 (@roma-glushko) - ⚙️ [config] Allowed to pass HTTP server configs from config file #41 (@roma-glushko) - 👷 [build] Allowed building Homebrew taps for release candidates #99 (@roma-glushko)
- Loading branch information
1 parent
16db2ad
commit 2c8ca01
Showing
27 changed files
with
434 additions
and
66 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
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
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
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
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,28 +1,66 @@ | ||
package http | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/cloudwego/hertz/pkg/common/config" | ||
|
||
"github.com/cloudwego/hertz/pkg/app/server" | ||
"github.com/cloudwego/hertz/pkg/network/netpoll" | ||
) | ||
|
||
type ServerConfig struct { | ||
HostPort string | ||
Host string `yaml:"host"` | ||
Port int `yaml:"port"` | ||
ReadTimeout *time.Duration `yaml:"read_timeout"` | ||
WriteTimeout *time.Duration `yaml:"write_timeout"` | ||
IdleTimeout *time.Duration `yaml:"idle_timeout"` | ||
MaxRequestBodySize *int `yaml:"max_request_body_size"` | ||
} | ||
|
||
func DefaultServerConfig() *ServerConfig { | ||
maxReqBodySize := 4 * 1024 * 1024 | ||
readTimeout := 3 * time.Second | ||
writeTimeout := 3 * time.Second | ||
idleTimeout := 1 * time.Second | ||
|
||
return &ServerConfig{ | ||
HostPort: "127.0.0.1:9099", | ||
Host: "127.0.0.1", | ||
Port: 9099, | ||
IdleTimeout: &idleTimeout, | ||
ReadTimeout: &readTimeout, | ||
WriteTimeout: &writeTimeout, | ||
MaxRequestBodySize: &maxReqBodySize, | ||
} | ||
} | ||
|
||
func (cfg *ServerConfig) Address() string { | ||
return fmt.Sprintf("%s:%v", cfg.Host, cfg.Port) | ||
} | ||
|
||
func (cfg *ServerConfig) ToServer() *server.Hertz { | ||
// TODO: do real server build based on provided config | ||
return server.Default( | ||
server.WithIdleTimeout(1*time.Second), | ||
server.WithHostPorts(cfg.HostPort), | ||
server.WithMaxRequestBodySize(20<<20), | ||
// More configs are listed on https://www.cloudwego.io/docs/hertz/tutorials/basic-feature/engine/ | ||
serverOptions := []config.Option{ | ||
server.WithHostPorts(cfg.Address()), | ||
server.WithTransport(netpoll.NewTransporter), | ||
) | ||
} | ||
|
||
if cfg.IdleTimeout != nil { | ||
serverOptions = append(serverOptions, server.WithIdleTimeout(*cfg.IdleTimeout)) | ||
} | ||
|
||
if cfg.ReadTimeout != nil { | ||
serverOptions = append(serverOptions, server.WithReadTimeout(*cfg.ReadTimeout)) | ||
} | ||
|
||
if cfg.WriteTimeout != nil { | ||
serverOptions = append(serverOptions, server.WithWriteTimeout(*cfg.WriteTimeout)) | ||
} | ||
|
||
if cfg.MaxRequestBodySize != nil { | ||
serverOptions = append(serverOptions, server.WithMaxRequestBodySize(*cfg.MaxRequestBodySize)) | ||
} | ||
|
||
return server.Default(serverOptions...) | ||
} |
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.