eidola

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 12 Imported by: 0

README

Eidola

介绍

Eidola 是一个用Go语言编写的微服务框架,专用于解决在微服务体系结构中常见的一些问题,包括服务注册、服务发现,以及简化微服务之间的通信。

特色

  • 服务注册:允许服务实例在启动时自动注册到服务中心。
  • 服务发现:客户端能够发现网络中可用的服务实例,并进行连接。
  • 负载均衡:内置了多种负载均衡策略,可根据需求进行选择和定制。
  • 服务限流:防止过载,保证服务质量(SLA)的机制。
  • 服务路由:根据客户端请求的特性路由请求到合适的服务实例。
  • 分布式跟踪: 提供了强大的API来为您的应用程序添加对分布式跟踪的支持。

快速开始

安装

首先,确保您已安装Go。然后执行以下命令:

go github.com/dormoron/eidola
创建服务端
package main

import (
	"github.com/dormoron/eidola"
	"github.com/dormoron/eidola/registry/etcd"
	clientv3 "go.etcd.io/etcd/client/v3"
	"time"
)

func main() {
	// 连接etcd
	etcdClient, err := clientv3.New(clientv3.Config{
		Endpoints: []string{"localhost:2379"},
	})
	r, err := etcd.NewRegistry(etcdClient)
	// 创建server
	server, err := eidola.NewServer("your_server_name", eidola.ServerWithRegistry(r),
		eidola.ServerWithRegisterTimeout(time.Second*10))
	// 启动服务	
	err = server.Start(":8081")
	if err != nil {
	    // 处理错误
	}
}
创建客户端
package main

import (
	"context"
	"github.com/dormoron/eidola"
	"github.com/dormoron/eidola/registry/etcd"
	clientv3 "go.etcd.io/etcd/client/v3"
	"time"
)

func main() {
	// 连接etcd
	etcdClient, err := clientv3.New(clientv3.Config{
		Endpoints: []string{"82.156.204.14:2379"},
	})
	r, err := etcd.NewRegistry(etcdClient)
	// 创建客户端实例
	client, err := eidola.NewClient(eidola.ClientInsecure(), eidola.ClientWithResolver(r, time.Second*3))
	if err != nil {
	    // 处理错误
	}
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
	defer cancel()
	// 连接到服务
	conn, err := client.Dial(ctx, "your_server_name")
	if err != nil {
	    // 处理错误
	}
	
	// 现在你可以使用conn来进行RPC调用
}

贡献

欢迎任何形式的贡献,包括报告bug,提出新功能,以及直接向代码库提交代码。

许可证

Mist是在MIT许可下发行的。有关详细信息,请查阅 LICENSE 文件。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the configuration for a gRPC client.

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient initializes a new gRPC client with the provided options.

func (*Client) Dial

func (c *Client) Dial(ctx context.Context, target string, dialOptions ...grpc.DialOption) (*grpc.ClientConn, error)

Dial creates a client connection to the given target.

type ClientOption

type ClientOption func(c *Client)

ClientOption defines an option for configuring the Client.

func ClientInsecure

func ClientInsecure() ClientOption

ClientInsecure returns a ClientOption that configures the client to use insecure connections.

func ClientWithPickerBuilder

func ClientWithPickerBuilder(name string, b base.PickerBuilder) ClientOption

ClientWithPickerBuilder returns a ClientOption that sets a custom picker builder for load balancing.

func ClientWithResolver

func ClientWithResolver(registry registry.Registry, timeout time.Duration) ClientOption

ClientWithResolver returns a ClientOption that configures the client to use a specific registry for service resolution.

type ResolverBuilder added in v0.0.4

type ResolverBuilder struct {
	// contains filtered or unexported fields
}

ResolverBuilder constructs a grpcResolver with registry and timeout settings.

func NewResolverBuilder added in v0.0.4

func NewResolverBuilder(registry registry.Registry, opts ...ResolverOptions) (*ResolverBuilder, error)

NewResolverBuilder creates a new ResolverBuilder and applies any additional options.

func (*ResolverBuilder) Build added in v0.0.4

Build constructs a grpcResolver for a given target and client connection with additional resolver build options.

func (*ResolverBuilder) Scheme added in v0.0.4

func (b *ResolverBuilder) Scheme() string

Scheme returns the scheme this builder is responsible for.

type ResolverOptions added in v0.0.4

type ResolverOptions func(r *ResolverBuilder)

ResolverOptions defines a functional option for configuring a ResolverBuilder.

func ResolverWithTimeout added in v0.0.4

func ResolverWithTimeout(timeout time.Duration) ResolverOptions

ResolverWithTimeout creates a ResolverOptions which sets a custom timeout for a ResolverBuilder.

type Server

type Server struct {
	*grpc.Server
	// contains filtered or unexported fields
}

Server represents a gRPC server

func NewServer

func NewServer(name string, opts ...ServerOption) (*Server, error)

NewServer intializes a new server

func (*Server) Close

func (s *Server) Close() error

Close gracefully stops the server

func (*Server) Start

func (s *Server) Start(addr string) (err error)

Start starts the server

type ServerOption

type ServerOption func(s *Server)

func ServerWithGroup

func ServerWithGroup(group string) ServerOption

ServerWithGroup sets the group for the server

func ServerWithRegisterTimeout

func ServerWithRegisterTimeout(d time.Duration) ServerOption

ServerWithRegisterTimeout sets the register timeout for the server

func ServerWithRegistry

func ServerWithRegistry(reg registry.Registry) ServerOption

ServerWithRegistry sets the registry for the server

func ServerWithWeight

func ServerWithWeight(weight uint32) ServerOption

ServerWithWeight sets the weight for the server

Jump to

Keyboard shortcuts

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