github.com/cloudwego/kitex@v0.9.0/pkg/registry/registry.go (about) 1 /* 2 * Copyright 2021 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Package registry is the API definition of service registry. 18 // Developers can implement the interface to extend Registry, like zookeeper, consul. 19 // Use the registry extension through server.WithRegistry(registry). 20 package registry 21 22 import ( 23 "net" 24 "time" 25 ) 26 27 // Registry is extension interface of service registry. 28 type Registry interface { 29 Register(info *Info) error 30 Deregister(info *Info) error 31 } 32 33 // Info is used for registry. 34 // The fields are just suggested, which is used depends on design. 35 type Info struct { 36 // ServiceName will be set in kitex by default 37 ServiceName string 38 // Addr will be set in kitex by default 39 Addr net.Addr 40 // PayloadCodec will be set in kitex by default, like thrift, protobuf 41 PayloadCodec string 42 43 Weight int 44 StartTime time.Time 45 WarmUp time.Duration 46 47 // extend other infos with Tags. 48 Tags map[string]string 49 } 50 51 // NoopRegistry is an empty implement of Registry 52 var NoopRegistry Registry = &noopRegistry{} 53 54 // NoopRegistry 55 type noopRegistry struct{} 56 57 func (e noopRegistry) Register(*Info) error { 58 return nil 59 } 60 61 func (e noopRegistry) Deregister(*Info) error { 62 return nil 63 }