fix: optimize ServerInfo() handler to avoid reading config (#10626)

fixes #10620
This commit is contained in:
Harshavardhana
2020-10-02 16:19:44 -07:00
committed by GitHub
parent 8e7c00f3d4
commit c6a9a94f94
10 changed files with 99 additions and 79 deletions

View File

@@ -37,6 +37,15 @@ func (c *Target) Validate() error {
return nil
}
// Endpoint returns the backend endpoint
func (c *Target) Endpoint() string {
return ""
}
func (c *Target) String() string {
return "console"
}
// Send log message 'e' to console
func (c *Target) Send(e interface{}, logKind string) error {
entry, ok := e.(log.Entry)

View File

@@ -39,6 +39,7 @@ type Target struct {
// Channel of log entries
logCh chan interface{}
name string
// HTTP(s) endpoint
endpoint string
// Authorization token for `endpoint`
@@ -49,6 +50,15 @@ type Target struct {
client http.Client
}
// Endpoint returns the backend endpoint
func (h *Target) Endpoint() string {
return h.endpoint
}
func (h *Target) String() string {
return h.name
}
// Validate validate the http target
func (h *Target) Validate() error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
@@ -145,6 +155,13 @@ func (h *Target) startHTTPLogger() {
// Option is a function type that accepts a pointer Target
type Option func(*Target)
// WithTargetName target name
func WithTargetName(name string) Option {
return func(t *Target) {
t.name = name
}
}
// WithEndpoint adds a new endpoint
func WithEndpoint(endpoint string) Option {
return func(t *Target) {