Skip to content
Snippets Groups Projects
factory.go 1.99 KiB
Newer Older
aliiohs's avatar
aliiohs committed
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

邹毅贤's avatar
邹毅贤 committed
package condition
aliiohs's avatar
aliiohs committed

import (
邹毅贤's avatar
邹毅贤 committed
	"github.com/apache/dubbo-go/cluster/router"
aliiohs's avatar
aliiohs committed
	"github.com/apache/dubbo-go/common"
邹毅贤's avatar
邹毅贤 committed
	"github.com/apache/dubbo-go/common/constant"
aliiohs's avatar
aliiohs committed
	"github.com/apache/dubbo-go/common/extension"
)

func init() {
邹毅贤's avatar
邹毅贤 committed
	extension.SetRouterFactory(constant.ConditionRouterName, newConditionRouterFactory)
	extension.SetRouterFactory(constant.ConditionAppRouterName, newAppRouterFactory)
邹毅贤's avatar
邹毅贤 committed
// ConditionRouterFactory Condition router factory
aliiohs's avatar
aliiohs committed
type ConditionRouterFactory struct{}
邹毅贤's avatar
邹毅贤 committed
func newConditionRouterFactory() router.RouterFactory {
邹毅贤's avatar
邹毅贤 committed
	return &ConditionRouterFactory{}
aliiohs's avatar
aliiohs committed
}
邹毅贤's avatar
邹毅贤 committed

// NewRouter Create ConditionRouterFactory by URL
邹毅贤's avatar
邹毅贤 committed
func (c *ConditionRouterFactory) NewRouter(url *common.URL) (router.Router, error) {
邹毅贤's avatar
邹毅贤 committed
	return NewConditionRouter(url)
邹毅贤's avatar
邹毅贤 committed
// NewRouter Create FileRouterFactory by Content
func (c *ConditionRouterFactory) NewFileRouter(content []byte) (router.Router, error) {
	return NewFileConditionRouter(content)
}

邹毅贤's avatar
邹毅贤 committed
// AppRouterFactory Application router factory
邹毅贤's avatar
邹毅贤 committed
type AppRouterFactory struct{}

邹毅贤's avatar
邹毅贤 committed
func newAppRouterFactory() router.RouterFactory {
邹毅贤's avatar
邹毅贤 committed
	return &AppRouterFactory{}
邹毅贤's avatar
邹毅贤 committed
}
邹毅贤's avatar
邹毅贤 committed

// NewRouter Create AppRouterFactory by URL
邹毅贤's avatar
邹毅贤 committed
func (c *AppRouterFactory) NewRouter(url *common.URL) (router.Router, error) {
邹毅贤's avatar
邹毅贤 committed
	return NewAppRouter(url)
CodingSinger's avatar
CodingSinger committed
}