generated from cloudwego/.github
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: panic when type assertion fails at runtime
- Loading branch information
Showing
10 changed files
with
95 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/cloudwego/kitex/pkg/klog" | ||
"github.com/kitex-contrib/config-file/monitor" | ||
"github.com/kitex-contrib/config-file/parser" | ||
) | ||
|
||
// getFileConfig returns the config from the watcher. | ||
// if the config type is not *parser.ClientFileConfig, it will log an error and return nil. | ||
func getFileConfig(watcher monitor.ConfigMonitor) *parser.ClientFileConfig { | ||
config, ok := watcher.Config().(*parser.ClientFileConfig) | ||
if !ok { | ||
// This should never happen. | ||
// But if it does, we should log it and do nothing. | ||
// Otherwise, the program will panic. | ||
klog.Errorf("[local] Invalid config type: %T", watcher.Config()) | ||
return nil | ||
} | ||
return config | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/cloudwego/kitex/pkg/klog" | ||
"github.com/kitex-contrib/config-file/monitor" | ||
"github.com/kitex-contrib/config-file/parser" | ||
) | ||
|
||
// getFileConfig returns the config from the watcher. | ||
// if the config type is not *parser.ServerFileConfig, it will log an error and return nil. | ||
func getFileConfig(watcher monitor.ConfigMonitor) *parser.ServerFileConfig { | ||
config, ok := watcher.Config().(*parser.ServerFileConfig) | ||
if !ok { | ||
// This should never happen. | ||
// But if it does, we should log it and do nothing. | ||
// Otherwise, the program will panic. | ||
klog.Errorf("[local] Invalid config type: %T", watcher.Config()) | ||
return nil | ||
} | ||
return config | ||
} |