dubbo.apache.org/dubbo-go/v3@v3.1.1/config_center/dynamic_configuration.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package config_center
    19  
    20  import (
    21  	"time"
    22  )
    23  
    24  import (
    25  	gxset "github.com/dubbogo/gost/container/set"
    26  )
    27  
    28  import (
    29  	"dubbo.apache.org/dubbo-go/v3/common"
    30  	"dubbo.apache.org/dubbo-go/v3/config_center/parser"
    31  )
    32  
    33  const (
    34  	DefaultGroup         = "dubbo"
    35  	DefaultConfigTimeout = "10s"
    36  )
    37  
    38  // DynamicConfiguration is the interface which modifys listener and gets properties file.
    39  type DynamicConfiguration interface {
    40  	Parser() parser.ConfigurationParser
    41  	SetParser(parser.ConfigurationParser)
    42  	AddListener(string, ConfigurationListener, ...Option)
    43  	RemoveListener(string, ConfigurationListener, ...Option)
    44  	// GetProperties get properties file
    45  	GetProperties(string, ...Option) (string, error)
    46  
    47  	// GetRule get Router rule properties file
    48  	GetRule(string, ...Option) (string, error)
    49  
    50  	// GetInternalProperty get value by key in Default properties file(dubbo.properties)
    51  	GetInternalProperty(string, ...Option) (string, error)
    52  
    53  	// PublishConfig will publish the config with the (key, group, value) pair
    54  	// for zk: path is /$(group)/config/$(key) -> value
    55  	// for nacos: group, key -> value
    56  	PublishConfig(string, string, string) error
    57  
    58  	// RemoveConfig will remove the config white the (key, group) pair
    59  	RemoveConfig(string, string) error
    60  
    61  	// GetConfigKeysByGroup will return all keys with the group
    62  	GetConfigKeysByGroup(group string) (*gxset.HashSet, error)
    63  }
    64  
    65  // Options ...
    66  type Options struct {
    67  	Group   string
    68  	Timeout time.Duration
    69  }
    70  
    71  // Option ...
    72  type Option func(*Options)
    73  
    74  // WithGroup assigns group to opt.Group
    75  func WithGroup(group string) Option {
    76  	return func(opt *Options) {
    77  		opt.Group = group
    78  	}
    79  }
    80  
    81  // WithTimeout assigns time to opt.Timeout
    82  func WithTimeout(time time.Duration) Option {
    83  	return func(opt *Options) {
    84  		opt.Timeout = time
    85  	}
    86  }
    87  
    88  // GetRuleKey The format is '{interfaceName}:[version]:[group]'
    89  func GetRuleKey(url *common.URL) string {
    90  	return url.ColonSeparatedKey()
    91  }