generated from cloudwego/.github
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1383aba
commit 0eccb48
Showing
17 changed files
with
230 additions
and
264 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2024 CloudWeGo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package parser | ||
|
||
import ( | ||
"github.com/cloudwego/kitex/pkg/circuitbreak" | ||
"github.com/cloudwego/kitex/pkg/retry" | ||
"github.com/cloudwego/kitex/pkg/rpctimeout" | ||
) | ||
|
||
// ClientFileConfig is config of a client/service pair | ||
type ClientFileConfig struct { | ||
Timeout map[string]*rpctimeout.RPCTimeout `mapstructure:"timeout"` // key: method, "*" for default | ||
Retry map[string]*retry.Policy `mapstructure:"retry"` // key: method, "*" for default | ||
Circuitbreaker map[string]*circuitbreak.CBConfig `mapstructure:"circuitbreaker"` // key: method | ||
} | ||
|
||
// ClientFileManager is a map of client/service pairs to ClientFileConfig | ||
type ClientFileManager map[string]*ClientFileConfig | ||
|
||
// GetConfig returns the config from Manager by key | ||
func (s *ClientFileManager) GetConfig(key string) interface{} { | ||
config, exist := (*s)[key] | ||
|
||
if !exist { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2024 CloudWeGo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package parser | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bytedance/sonic" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
type ConfigParam struct { | ||
Type ConfigType | ||
} | ||
|
||
type ConfigType string | ||
|
||
const ( | ||
JSON ConfigType = "json" | ||
YAML ConfigType = "yaml" | ||
) | ||
|
||
// ConfigParser the parser for config file. | ||
type ConfigParser interface { | ||
Decode(kind ConfigType, data []byte, config interface{}) error | ||
} | ||
|
||
type Parser struct{} | ||
|
||
type ConfigManager interface { | ||
GetConfig(key string) interface{} | ||
} | ||
|
||
var _ ConfigParser = &Parser{} | ||
|
||
// Decode decodes the data to struct in specified format. | ||
func (p *Parser) Decode(kind ConfigType, data []byte, config interface{}) error { | ||
switch kind { | ||
case JSON: | ||
return sonic.Unmarshal(data, config) | ||
case YAML: | ||
return yaml.Unmarshal(data, config) | ||
default: | ||
return fmt.Errorf("unsupported config data type %s", kind) | ||
} | ||
} | ||
|
||
func DefaultConfigParser() ConfigParser { | ||
return &Parser{} | ||
} | ||
|
||
func DefaultConfigParam() *ConfigParam { | ||
return &ConfigParam{ | ||
Type: JSON, | ||
} | ||
} |
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,36 @@ | ||
// Copyright 2024 CloudWeGo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package parser | ||
|
||
import "github.com/cloudwego/kitex/pkg/limiter" | ||
|
||
// ServerFileConfig is config of a service | ||
type ServerFileConfig struct { | ||
Limit limiter.LimiterConfig `mapstructure:"limit"` | ||
} | ||
|
||
// ServerFileManager is a map of service names to ServerFileConfig | ||
type ServerFileManager map[string]*ServerFileConfig | ||
|
||
// GetConfig returns the config from Manager by key | ||
func (s *ServerFileManager) GetConfig(key string) interface{} { | ||
config, exist := (*s)[key] | ||
|
||
if !exist { | ||
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
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
Oops, something went wrong.