-
Notifications
You must be signed in to change notification settings - Fork 61
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
dd56f3c
commit ca98b72
Showing
119 changed files
with
6,450 additions
and
5,291 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,87 @@ | ||
/** | ||
* Tencent is pleased to support the open source community by making polaris-go available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* 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 api | ||
|
||
import ( | ||
"github.com/polarismesh/polaris-go/pkg/config" | ||
"github.com/polarismesh/polaris-go/pkg/model" | ||
) | ||
|
||
// CircuitBreakerAPI . | ||
type CircuitBreakerAPI interface { | ||
SDKOwner | ||
// Check | ||
Check(model.Resource) (*model.CheckResult, error) | ||
// Report | ||
Report(*model.ResourceStat) error | ||
// MakeFunctionDecorator | ||
MakeFunctionDecorator(model.CustomerFunction, *RequestContext) model.DecoratorFunction | ||
// MakeInvokeHandler | ||
MakeInvokeHandler(*RequestContext) model.InvokeHandler | ||
} | ||
|
||
type ResultToErrorCode interface { | ||
model.ResultToErrorCode | ||
} | ||
|
||
type RequestContext struct { | ||
model.RequestContext | ||
} | ||
|
||
type ResponseContext struct { | ||
model.ResponseContext | ||
} | ||
|
||
var ( | ||
// NewConsumerAPI 通过以默认域名为埋点server的默认配置创建 CircuitBreakerAPI | ||
NewCircuitBreakerAPI = newCircuitBreakerAPI | ||
// NewCircuitBreakerByFile 通过配置文件创建SDK CircuitBreakerAPI 对象 | ||
NewCircuitBreakerByFile = newCircuitBreakerAPIByFile | ||
// NewCircuitBreakerByConfig 通过配置对象创建SDK CircuitBreakerAPI 对象 | ||
NewCircuitBreakerByConfig = newCircuitBreakerAPIByConfig | ||
// NewCircuitBreakerByContext 通过上下文创建SDK CircuitBreakerAPI 对象 | ||
NewCircuitBreakerByContext = newCircuitBreakerAPIByContext | ||
) | ||
|
||
// 通过以默认域名为埋点server的默认配置创建 CircuitBreakerAPI | ||
func newCircuitBreakerAPI() (CircuitBreakerAPI, error) { | ||
return newCircuitBreakerAPIByConfig(config.NewDefaultConfigurationWithDomain()) | ||
} | ||
|
||
// newCircuitBreakerAPIByFile 通过配置文件创建SDK CircuitBreakerAPI 对象 | ||
func newCircuitBreakerAPIByFile(path string) (CircuitBreakerAPI, error) { | ||
context, err := InitContextByFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &circuitBreakerAPI{context}, nil | ||
} | ||
|
||
// newCircuitBreakerAPIByConfig 通过配置对象创建SDK CircuitBreakerAPI 对象 | ||
func newCircuitBreakerAPIByConfig(cfg config.Configuration) (CircuitBreakerAPI, error) { | ||
context, err := InitContextByConfig(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &circuitBreakerAPI{context}, nil | ||
} | ||
|
||
// newCircuitBreakerAPIByContext 通过上下文创建SDK CircuitBreakerAPI 对象 | ||
func newCircuitBreakerAPIByContext(context SDKContext) CircuitBreakerAPI { | ||
return &circuitBreakerAPI{context} | ||
} |
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,48 @@ | ||
/** | ||
* Tencent is pleased to support the open source community by making polaris-go available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* 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 api | ||
|
||
import ( | ||
"github.com/polarismesh/polaris-go/pkg/model" | ||
_ "github.com/polarismesh/polaris-go/pkg/plugin/register" | ||
) | ||
|
||
type circuitBreakerAPI struct { | ||
context SDKContext | ||
} | ||
|
||
// SDKContext 获取SDK上下文 | ||
func (c *circuitBreakerAPI) SDKContext() SDKContext { | ||
return c.context | ||
} | ||
|
||
func (c *circuitBreakerAPI) Check(resource model.Resource) (*model.CheckResult, error) { | ||
return c.context.GetEngine().Check(resource) | ||
} | ||
|
||
func (c *circuitBreakerAPI) Report(reportStat *model.ResourceStat) error { | ||
return c.context.GetEngine().Report(reportStat) | ||
} | ||
|
||
func (c *circuitBreakerAPI) MakeFunctionDecorator(f model.CustomerFunction, reqCtx *RequestContext) model.DecoratorFunction { | ||
return c.context.GetEngine().MakeFunctionDecorator(f, &reqCtx.RequestContext) | ||
} | ||
|
||
func (c *circuitBreakerAPI) MakeInvokeHandler(reqCtx *RequestContext) model.InvokeHandler { | ||
return c.context.GetEngine().MakeInvokeHandler(&reqCtx.RequestContext) | ||
} |
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,98 @@ | ||
/** | ||
* Tencent is pleased to support the open source community by making polaris-go available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* 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 polaris | ||
|
||
import ( | ||
"github.com/polarismesh/polaris-go/api" | ||
"github.com/polarismesh/polaris-go/pkg/config" | ||
"github.com/polarismesh/polaris-go/pkg/model" | ||
) | ||
|
||
// NewCircuitBreakerAPI 获取 CircuitBreakerAPI | ||
func NewCircuitBreakerAPI() (CircuitBreakerAPI, error) { | ||
rawAPI, err := api.NewCircuitBreakerAPI() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &circuitBreakerAPI{ | ||
rawAPI: rawAPI, | ||
}, nil | ||
} | ||
|
||
// NewCircuitBreakerAPIByConfig 通过配置对象获取 CircuitBreakerAPI | ||
func NewCircuitBreakerAPIByConfig(cfg config.Configuration) (CircuitBreakerAPI, error) { | ||
rawAPI, err := api.NewCircuitBreakerByConfig(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &circuitBreakerAPI{ | ||
rawAPI: rawAPI, | ||
}, nil | ||
} | ||
|
||
// NewCircuitBreakerAPIByFile 通过配置文件获取 CircuitBreakerAPI | ||
func NewCircuitBreakerAPIByFile(path string) (CircuitBreakerAPI, error) { | ||
rawAPI, err := api.NewCircuitBreakerByFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &circuitBreakerAPI{ | ||
rawAPI: rawAPI, | ||
}, nil | ||
} | ||
|
||
// NewCircuitBreakerAPIByContext 通过上下文对象获取 CircuitBreakerAPI | ||
func NewCircuitBreakerAPIByContext(context api.SDKContext) CircuitBreakerAPI { | ||
rawAPI := api.NewCircuitBreakerByContext(context) | ||
return &circuitBreakerAPI{ | ||
rawAPI: rawAPI, | ||
} | ||
} | ||
|
||
type circuitBreakerAPI struct { | ||
rawAPI api.CircuitBreakerAPI | ||
} | ||
|
||
// Check | ||
func (c *circuitBreakerAPI) Check(res model.Resource) (*model.CheckResult, error) { | ||
return c.rawAPI.Check(res) | ||
} | ||
|
||
// Report | ||
func (c *circuitBreakerAPI) Report(stat *model.ResourceStat) error { | ||
return c.rawAPI.Report(stat) | ||
} | ||
|
||
// MakeFunctionDecorator | ||
func (c *circuitBreakerAPI) MakeFunctionDecorator(f model.CustomerFunction, reqCtx *api.RequestContext) model.DecoratorFunction { | ||
return c.rawAPI.MakeFunctionDecorator(f, reqCtx) | ||
} | ||
|
||
// MakeInvokeHandler | ||
func (c *circuitBreakerAPI) MakeInvokeHandler(reqCtx *api.RequestContext) model.InvokeHandler { | ||
return c.rawAPI.MakeInvokeHandler(reqCtx) | ||
} | ||
|
||
func (c *circuitBreakerAPI) SDKContext() api.SDKContext { | ||
return c.rawAPI.SDKContext() | ||
} | ||
|
||
// Destroy the api is destroyed and cannot be called again | ||
func (c *circuitBreakerAPI) Destroy() { | ||
c.rawAPI.SDKContext().Destroy() | ||
} |
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.