DMwangnima commented on code in PR #2379:
URL: https://github.com/apache/dubbo-go/pull/2379#discussion_r1292747395


##########
provider/provider.go:
##########
@@ -0,0 +1,48 @@
+package provider
+
+import (
+       "context"
+       "dubbo.apache.org/dubbo-go/v3/protocol"
+)
+
+type Provider struct {
+       invoker protocol.Invoker
+       info    *ServiceInfo
+       cfg     *ServiceConfig
+}
+
+// Register assemble invoker chains like ProviderConfig.Load, init a service 
per call
+func (pro *Provider) Register(handler interface{}, info *ServiceInfo, opts 
...RegisterOptions) error {
+       // put information from info to url
+       // ProviderConfig.Load
+
+       // url
+       return nil
+}
+
+// meta
+type ServiceInfo struct {
+       InterfaceName string
+       ServiceType   interface{}
+       Methods       []MethodInfo
+       Meta          map[string]interface{}
+}
+
+type MethodInfo struct {
+       Name           string
+       Type           string
+       ReqInitFunc    func() interface{}
+       StreamInitFunc func(baseStream interface{}) interface{}
+       MethodFunc     func(ctx context.Context, args []interface{}, handler 
interface{}) (interface{}, error)
+       Meta           map[string]interface{}
+}
+
+func NewProvider(opts ...ServiceOption) (*Provider, error) {

Review Comment:
   Change the name of package and struct from provider to server. 
Refer(https://github.com/apache/dubbo-go/pull/2378).



##########
provider/service_config.go:
##########
@@ -0,0 +1,483 @@
+/*
+ * 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.
+ */
+
+package provider
+
+import (
+       "container/list"
+       commonCfg "dubbo.apache.org/dubbo-go/v3/common/config"
+       "dubbo.apache.org/dubbo-go/v3/config"
+       "dubbo.apache.org/dubbo-go/v3/registry"
+       "fmt"
+       "net/url"
+       "os"
+       "strconv"
+       "strings"
+       "sync"
+       "time"
+)
+
+import (
+       "github.com/creasty/defaults"
+
+       "github.com/dubbogo/gost/log/logger"
+       gxnet "github.com/dubbogo/gost/net"
+
+       perrors "github.com/pkg/errors"
+
+       "go.uber.org/atomic"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/common"
+       "dubbo.apache.org/dubbo-go/v3/common/constant"
+       "dubbo.apache.org/dubbo-go/v3/common/extension"
+       "dubbo.apache.org/dubbo-go/v3/protocol"
+       "dubbo.apache.org/dubbo-go/v3/protocol/protocolwrapper"
+)
+
+// ServiceConfig is the configuration of the service provider
+type ServiceConfig struct {
+       Id                          string
+       Filter                      string            `yaml:"filter" 
json:"filter,omitempty" property:"filter"`
+       ProtocolIDs                 []string          `yaml:"protocol-ids"  
json:"protocol-ids,omitempty" property:"protocol-ids"` // multi protocolIDs 
support, split by ','
+       Interface                   string            `yaml:"interface"  
json:"interface,omitempty" property:"interface"`
+       RegistryIDs                 []string          `yaml:"registry-ids"  
json:"registry-ids,omitempty"  property:"registry-ids"`
+       Cluster                     string            `default:"failover" 
yaml:"cluster"  json:"cluster,omitempty" property:"cluster"`
+       Loadbalance                 string            `default:"random" 
yaml:"loadbalance"  json:"loadbalance,omitempty"  property:"loadbalance"`
+       Group                       string            `yaml:"group"  
json:"group,omitempty" property:"group"`
+       Version                     string            `yaml:"version"  
json:"version,omitempty" property:"version" `
+       Methods                     []*MethodConfig   `yaml:"methods"  
json:"methods,omitempty" property:"methods"`
+       Warmup                      string            `yaml:"warmup"  
json:"warmup,omitempty"  property:"warmup"`
+       Retries                     string            `yaml:"retries"  
json:"retries,omitempty" property:"retries"`
+       Serialization               string            `yaml:"serialization" 
json:"serialization" property:"serialization"`
+       Params                      map[string]string `yaml:"params"  
json:"params,omitempty" property:"params"`
+       Token                       string            `yaml:"token" 
json:"token,omitempty" property:"token"`
+       AccessLog                   string            `yaml:"accesslog" 
json:"accesslog,omitempty" property:"accesslog"`
+       TpsLimiter                  string            `yaml:"tps.limiter" 
json:"tps.limiter,omitempty" property:"tps.limiter"`
+       TpsLimitInterval            string            
`yaml:"tps.limit.interval" json:"tps.limit.interval,omitempty" 
property:"tps.limit.interval"`
+       TpsLimitRate                string            `yaml:"tps.limit.rate" 
json:"tps.limit.rate,omitempty" property:"tps.limit.rate"`
+       TpsLimitStrategy            string            
`yaml:"tps.limit.strategy" json:"tps.limit.strategy,omitempty" 
property:"tps.limit.strategy"`
+       TpsLimitRejectedHandler     string            
`yaml:"tps.limit.rejected.handler" json:"tps.limit.rejected.handler,omitempty" 
property:"tps.limit.rejected.handler"`
+       ExecuteLimit                string            `yaml:"execute.limit" 
json:"execute.limit,omitempty" property:"execute.limit"`
+       ExecuteLimitRejectedHandler string            
`yaml:"execute.limit.rejected.handler" 
json:"execute.limit.rejected.handler,omitempty" 
property:"execute.limit.rejected.handler"`
+       Auth                        string            `yaml:"auth" 
json:"auth,omitempty" property:"auth"`
+       NotRegister                 bool              `yaml:"not_register" 
json:"not_register,omitempty" property:"not_register"`
+       ParamSign                   string            `yaml:"param.sign" 
json:"param.sign,omitempty" property:"param.sign"`
+       Tag                         string            `yaml:"tag" 
json:"tag,omitempty" property:"tag"`
+       TracingKey                  string            `yaml:"tracing-key" 
json:"tracing-key,omitempty" propertiy:"tracing-key"`
+
+       RCProtocolsMap  map[string]*config.ProtocolConfig
+       RCRegistriesMap map[string]*registry.RegistryConfig
+       ProxyFactoryKey string
+       AdaptiveService bool
+       Unexported      *atomic.Bool
+       Exported        *atomic.Bool
+       Export          bool // a flag to control whether the current service 
should export or not
+       RPCService      common.RPCService
+       cacheMutex      sync.Mutex
+       cacheProtocol   protocol.Protocol
+       exportersLock   sync.Mutex
+       exporters       []protocol.Exporter
+
+       MetadataType string
+
+       application *commonCfg.ApplicationConfig
+
+       meshEnabled  bool
+       proxyFactory string
+       registries   map[string]*registry.RegistryConfig
+}
+
+// Prefix returns dubbo.service.${InterfaceName}.
+func (s *ServiceConfig) Prefix() string {
+       return strings.Join([]string{constant.ServiceConfigPrefix, s.Id}, ".")
+}
+
+func (s *ServiceConfig) Init(opts ...ServiceOption) error {
+       if err := initProviderMethodConfig(s); err != nil {
+               return err
+       }
+       if err := defaults.Set(s); err != nil {
+               return err
+       }
+       for _, opt := range opts {
+               opt(s)
+       }
+       s.Exported = atomic.NewBool(false)
+       s.MetadataType = s.application.MetadataType
+       if s.Version == "" {
+               s.Version = s.application.Version
+       }
+       if s.Group == "" {
+               s.Group = s.application.Group
+       }
+       s.Unexported = atomic.NewBool(false)
+       err := s.check()
+       if err != nil {
+               panic(err)
+       }
+       s.Export = true
+       return commonCfg.Verify(s)
+}
+
+func (s *ServiceConfig) check() error {
+       // check if the limiter has been imported
+       if s.TpsLimiter != "" {
+               _, err := extension.GetTpsLimiter(s.TpsLimiter)
+               if err != nil {
+                       panic(err)
+               }
+       }
+       if s.TpsLimitStrategy != "" {
+               _, err := 
extension.GetTpsLimitStrategyCreator(s.TpsLimitStrategy)
+               if err != nil {
+                       panic(err)
+               }
+       }
+       if s.TpsLimitRejectedHandler != "" {
+               _, err := 
extension.GetRejectedExecutionHandler(s.TpsLimitRejectedHandler)
+               if err != nil {
+                       panic(err)
+               }
+       }
+
+       if s.TpsLimitInterval != "" {
+               tpsLimitInterval, err := strconv.ParseInt(s.TpsLimitInterval, 
0, 0)
+               if err != nil {
+                       return fmt.Errorf("[ServiceConfig] Cannot parse the 
configuration tps.limit.interval for service %s, please check your 
configuration", s.Interface)
+               }
+               if tpsLimitInterval < 0 {
+                       return fmt.Errorf("[ServiceConfig] The configuration 
tps.limit.interval for service %s must be positive, please check your 
configuration", s.Interface)
+               }
+       }
+
+       if s.TpsLimitRate != "" {
+               tpsLimitRate, err := strconv.ParseInt(s.TpsLimitRate, 0, 0)
+               if err != nil {
+                       return fmt.Errorf("[ServiceConfig] Cannot parse the 
configuration tps.limit.rate for service %s, please check your configuration", 
s.Interface)
+               }
+               if tpsLimitRate < 0 {
+                       return fmt.Errorf("[ServiceConfig] The configuration 
tps.limit.rate for service %s must be positive, please check your 
configuration", s.Interface)
+               }
+       }
+       return nil
+}
+
+// InitExported will set exported as false atom bool
+func (s *ServiceConfig) InitExported() {
+       s.Exported = atomic.NewBool(false)
+}
+
+// IsExport will return whether the service config is exported or not
+func (s *ServiceConfig) IsExport() bool {
+       return s.Exported.Load()
+}
+
+// Get Random Port
+func getRandomPort(protocolConfigs []*config.ProtocolConfig) *list.List {
+       ports := list.New()
+       for _, proto := range protocolConfigs {
+               if len(proto.Port) > 0 {
+                       continue
+               }
+
+               tcp, err := gxnet.ListenOnTCPRandomPort(proto.Ip)
+               if err != nil {
+                       panic(perrors.New(fmt.Sprintf("Get tcp port error, err 
is {%v}", err)))
+               }
+               defer tcp.Close()
+               ports.PushBack(strings.Split(tcp.Addr().String(), ":")[1])
+       }
+       return ports
+}
+
+// ExportMethod exports the service
+func (s *ServiceConfig) ExportMethod() error {

Review Comment:
   There should be Export and ExportWithInfo like Refer and ReferWithInfo.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to