etcd

package
v0.0.0-...-5b4c1f5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Expire = "EXPIRE"
	Put    = "PUT"
	Del    = "DELETE"
)

Variables

View Source
var (
	EtcdNoAuthClientError = errors.New("etcd auth client is nil")
)

Functions

func AddUser

func AddUser(role, user, pass string) error

*

*
* 新增用户

func Close

func Close() error

func CreateRoleWithPermission

func CreateRoleWithPermission(role string, perms []*Permission) (err error)

*

 *
 * perms := []*Permission{
		&Permission{Key:"/warden/", RangeEnd:"/warden/z", Type: clientv3.PermReadWrite},
		&Permission{Key:"/web/", RangeEnd:"/web/z", Type: clientv3.PermReadWrite},
	}
	if err := createRoleWithPermission("web", perms , authAPI); err != nil {
		log.Fatal(err)
	}
 *

func Get

func Get(serviceKey string, withPrefix bool) (err error, vals []string)

func GetWithPrefix

func GetWithPrefix(serviceKey string) (err error, vals []string)

func GrantUser

func GrantUser(user, role string) error

*

*
* 给用户赋予权限

func NewEtcd

func NewEtcd(options *Options) error

*

  • 生成etcd 实例,在一个实例服务器中,有且只有一个etcd client实例

func Register

func Register(serviceKey string, val string, interval time.Duration, ttl time.Duration)

注册自己到etcd服务

func Set

func Set(key, val string) error

func Unregister

func Unregister(serviceKey string)

func Watcher

func Watcher(serviceKey string, callback EtcdWatchCallback)

*

  • callback的处理必须是非阻塞的

Types

type AuthOptions

type AuthOptions struct {
	UserName string
	Password string
}

type EtcdWatchCallback

type EtcdWatchCallback func(action string, key, val []byte)

type Options

type Options struct {
	Tls         *tls.Config
	Endpoints   []string
	DialTimeout time.Duration
	Auth        *AuthOptions
}

func NewOption

func NewOption() *Options

type Permission

type Permission struct {
	Key      string
	RangeEnd string
	Type     authpb.Permission_Type
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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