registry

package
v0.0.0-...-0dfa492 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2025 License: MulanPSL-2.0 Imports: 12 Imported by: 1

Documentation

Overview

* Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. * PilotGo licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: zhanghan2021 <zhanghan@kylinos.cn> * Date: Thu Dec 12 17:36:05 2024 +0800

* Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. * PilotGo licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: zhanghan2021 <zhanghan@kylinos.cn> * Date: Thu Dec 12 17:36:05 2024 +0800

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type  EventType
	Key   string
	Value string
}

Event represents a service registry event

type EventType

type EventType int32

EventType represents the type of service registry events

const (
	EventTypePut    EventType = 0
	EventTypeDelete EventType = 1
)

type Options

type Options struct {
	Endpoints   []string            // etcd address
	ServiceName string              // 服务地址
	ServiceAddr string              // 服务名称
	DialTimeout time.Duration       // 超时时间
	Version     string              // 服务版本
	MenuName    string              // 菜单名称
	Icon        string              // 菜单图标
	Extentions  []common.Extention  // 用于平台扩展点功能
	Permissions []common.Permission //用于权限校验
}

Options represents the configuration options for service registry

type Registry

type Registry interface {
	// Register registers a service
	Register(info *ServiceInfo) error
	// Deregister removes a service registration
	Deregister() error
	// Get retrieves service information
	Get(key string) (*ServiceInfo, error)
	// Put stores service information
	Put(key string, value string) error
	// Delete removes service information
	Delete(key string) error
	// List retrieves all service information
	List() ([]*ServiceInfo, error)
	// Watch watches for service changes
	Watch(ctx context.Context, key string, callback WatchCallback) error
	// Close closes the registry client
	Close() error
}

Registry defines the interface for service registry operations

func NewRegistry

func NewRegistry(registryType RegistryType, opts *Options) (Registry, error)

NewRegistry creates a new registry client based on the registry type

type RegistryType

type RegistryType string

RegistryType represents the type of registry

const (
	RegistryTypeEtcd RegistryType = "etcd"
)

type ServiceInfo

type ServiceInfo struct {
	ServiceName string                 `json:"serviceName"`
	Address     string                 `json:"address"`
	Port        string                 `json:"port"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

ServiceInfo represents the basic information of a service

type ServiceRegistrar

type ServiceRegistrar struct {
	Registry    Registry
	ServiceInfo *ServiceInfo
}

ServiceRegistrar handles service registration and lifecycle management

func NewServiceRegistrar

func NewServiceRegistrar(opts *Options) (*ServiceRegistrar, error)

NewServiceRegistrar creates a new service registrar

func (*ServiceRegistrar) Start

func (s *ServiceRegistrar) Start() error

Start registers the service and starts keeping it alive

func (*ServiceRegistrar) Stop

func (s *ServiceRegistrar) Stop() error

Stop deregisters the service and cleans up resources

type WatchCallback

type WatchCallback func(event Event)

WatchCallback is the callback function for watch events

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL