discover

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0 Imports: 4 Imported by: 1

README

服务发现

package main

import (
    "github.com/joshqu1985/fireman/configor"
    "github.com/joshqu1985/fireman/discover"
    "github.com/joshqu1985/protos/sdk"
)

type Config struct {
    Name     string
    Port     int
    Discover discover.Config
}

var (
    Conf Config
)

func init() {
    if err := configor.Load("./configs/conf.toml", &Conf); err != nil {
        panic(err)
    }

    if err := discover.Init(Conf.Discover); err != nil {
        panic(err)
    }
}

func main() {
    // 注册自己
    if err := discover.Register(Conf.Name, Conf.Port); err != nil {
        panic(err)
    }

    // Resolver注入到grpc, 通过client调用Services定义的方法[board, uauth, feed]
    client := sdk.NewGrpcClient(discover.Resolver(), Conf.Discover.Resolver.Services)
}
#conf.toml
name = "uauth"
port = 18094

[discover]
    endpoints = ["127.0.0.1:2379"]        #etcd 地址
    [discover.register]
        ttl      = 10000                  # 10s
        interval = 10000                  # 10s
    [discover.resolver]
        services = ["board", "uauth", "feed"]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(conf Config) (err error)

func Register

func Register(name string, port int) error

func Resolver

func Resolver() naming.Resolver

Types

type Config

type Config struct {
	Endpoints []string       `toml:"endpoints"`
	Register  RegisterConfig `toml:"register"`
	Resolver  ResolverConfig `toml:"resolver"`
}

type Discover

type Discover interface {
	Register(name string, port int) error
	Resolver() naming.Resolver
}

type RegisterConfig

type RegisterConfig struct {
	TTL      int `toml:"ttl"`
	Interval int `toml:"interval"`
}

type ResolverConfig

type ResolverConfig struct {
	Services []string `toml:"services"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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