-
Notifications
You must be signed in to change notification settings - Fork 31
Make HTTP timeout configurable, raise default to 30s #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ad1f51d
5a7cd2e
960882b
23a5f5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ type Settings struct { | |
| Debug bool `json:"debug"` | ||
| AcID string `json:"acId"` | ||
| Campus bool `json:"campusOnly"` | ||
| Timeout int `json:"timeout"` | ||
| } | ||
|
|
||
| var logger = loggo.GetLogger("auth-thu") | ||
|
|
@@ -99,7 +100,14 @@ func mergeCliSettings(c *cli.Command) { | |
| merged.AcID = settings.AcID | ||
| } | ||
| merged.Campus = settings.Campus || c.Bool("campus-only") | ||
| merged.Timeout = c.Int("timeout") | ||
| if !c.IsSet("timeout") && settings.Timeout != 0 { | ||
| merged.Timeout = settings.Timeout | ||
| } | ||
| settings = merged | ||
| if settings.Timeout > 0 { | ||
| libauth.HttpTimeout = time.Duration(settings.Timeout) * time.Second | ||
| } | ||
| logger.Debugf("Settings Username: \"%s\"\n", settings.Username) | ||
| logger.Debugf("Settings Ip: \"%s\"\n", settings.Ip) | ||
| logger.Debugf("Settings Host: \"%s\"\n", settings.Host) | ||
|
|
@@ -114,6 +122,7 @@ func mergeCliSettings(c *cli.Command) { | |
| logger.Debugf("Settings Debug: %t\n", settings.Debug) | ||
| logger.Debugf("Settings AcID: \"%s\"\n", settings.AcID) | ||
| logger.Debugf("Settings Campus: %t\n", settings.Campus) | ||
| logger.Debugf("Settings Timeout: %d\n", settings.Timeout) | ||
| } | ||
|
|
||
| func requestUser() (err error) { | ||
|
|
@@ -424,6 +433,7 @@ func main() { | |
| &cli.StringFlag{Name: "config-file", Aliases: []string{"c"}, Usage: "`path` to your config file, default ~/.auth-thu"}, | ||
| &cli.StringFlag{Name: "hook-success", Usage: "command line to be executed in shell after successful login/out"}, | ||
| &cli.IntFlag{Name: "online-interval", Aliases: []string{"I"}, Usage: "the interval between each keepAlive request (s)", Value: 3}, | ||
| &cli.IntFlag{Name: "timeout", Aliases: []string{"t"}, Usage: "HTTP request timeout in seconds for the auth server", Value: 30}, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This default should be change to 2s as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不过已经在 960882b 里改回 2s。 |
||
| &cli.BoolFlag{Name: "daemonize", Aliases: []string{"D"}, Usage: "run without reading username/password from standard input; less log"}, | ||
| &cli.BoolFlag{Name: "debug", Usage: "print debug messages"}, | ||
| &cli.BoolFlag{Name: "help, h", Usage: "print the help"}, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个感觉有点意义不明,命令行参数允许
--timeout 0,但是配置文件的timeout: 0是无效的会被忽略,感觉这样才更迷惑了。其实完全可以不改,explicit "--timeout 0" will be silently ignored本来也不算什么大问题