grpcclient

package
v2.4.4+incompatible Latest Latest
Warning

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

Go to latest
Published: May 11, 2018 License: MIT Imports: 7 Imported by: 1

README

数据类型

type Response struct {
	Id       int64
	Event    string
	Data     []byte
}

type Client struct {
}

func New(addr string) *Client   // addr为lainlet地址, 如"192.168.77.21:9001"

func (c *Client) Get(uri string, timeout time.Duration) ([]byte, error)  // get请求

func (c *Client) Watch(uri string, ctx context.Context) (<-chan *Response, error) // watch请求

func (c *Client) Do(uri string, timeout time.Duration, watch bool) (io.ReadCloser, error) // rawrequest

Demo

package main

import (
	"fmt"
	"golang.org/x/net/context"
	api "github.com/laincloud/lainlet/api/v2"
	"github.com/laincloud/lainlet/client"
	"log"
	"os"
	"time"
)

func main() {
	if len(os.Args) < 2 {
		fmt.Println("lainlet addr required")
		return
	}
	info := new(api.GeneralCoreInfo)

	// get request
	c := client.New(os.Args[1])
	data, err := c.Get("/coreinfowatcher/?appname=registry", 0)
	if err != nil {
		panic(err)
	}
	info.Decode(data)
	fmt.Println(info.Data)

	// watch request
	ctx, _ := context.WithTimeout(context.Background(), time.Second*30) // 30 seconds timeout
	ch, err := c.Watch("/coreinfowatcher/?appname=registry&heartbeat=5", ctx)
	if err != nil {
		panic(err)
	}
	for event := range ch {
		fmt.Println("Get a event:")
		fmt.Println("    ", event.Id)
		fmt.Println("    ", event.Event)
		if event.Id != 0 { // id == 0 means error-event or heartbeat
			if err := info.Decode(event.Data); err != nil {
				log.Println(err.Error())
			} else {
				fmt.Println("    ", info.Data)
			}
		}
	}
}

Documentation

Index

Constants

View Source
const (
	RPC_TIMEOUT = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppsWatcher

type AppsWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*AppsWatcher) Next

func (wch *AppsWatcher) Next() (*pb.AppsReply, error)

type BackupctlWatcher

type BackupctlWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*BackupctlWatcher) Next

func (wch *BackupctlWatcher) Next() (*pb.BackupctlReply, error)

type Client

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

func New

func New(cfg *Config) (*Client, error)

create a new client, addr is lainlet address such as "127.0.0.1:9001"

func (*Client) AppnameGet

func (cli *Client) AppnameGet(ip string) (*pb.AppnameReply, error)

Appname only has Get rpc

func (*Client) AppsGet

func (cli *Client) AppsGet() (*pb.AppsReply, error)

CODE GENERATION Apps START

func (*Client) AppsWatch

func (cli *Client) AppsWatch() (*AppsWatcher, error)

func (*Client) BackupctlGet

func (cli *Client) BackupctlGet(appname string) (*pb.BackupctlReply, error)

CODE GENERATION Apps END CODE GENERATION Backupctl START

func (*Client) BackupctlWatch

func (cli *Client) BackupctlWatch(appname string) (*BackupctlWatcher, error)

func (*Client) ConfigGet

func (cli *Client) ConfigGet(target string) (*pb.ConfigReply, error)

CODE GENERATION Backupctl END CODE GENERATION Config START

func (*Client) ConfigWatch

func (cli *Client) ConfigWatch(target string) (*ConfigWatcher, error)

func (*Client) ContainersGet

func (cli *Client) ContainersGet(nodename string) (*pb.ContainersReply, error)

CODE GENERATION Config END CODE GENERATION Containers START

func (*Client) ContainersWatch

func (cli *Client) ContainersWatch(nodename string) (*ContainersWatcher, error)

func (*Client) CoreinfoGet

func (cli *Client) CoreinfoGet(appname string) (*pb.CoreinfoReply, error)

CODE GENERATION Containers END CODE GENERATION Coreinfo START

func (*Client) CoreinfoWatch

func (cli *Client) CoreinfoWatch(appname string) (*CoreinfoWatcher, error)

func (*Client) DependsGet

func (cli *Client) DependsGet(target string) (*pb.DependsReply, error)

CODE GENERATION Depends START

func (*Client) DependsWatch

func (cli *Client) DependsWatch(target string) (*DependsWatcher, error)

func (*Client) LocalspecGet

func (cli *Client) LocalspecGet(nodeip string) (*pb.LocalspecReply, error)

Localspec only has Get rpc

func (*Client) NodesGet

func (cli *Client) NodesGet(name string) (*pb.NodesReply, error)

CODE GENERATION Coreinfo END CODE GENERATION Nodes START

func (*Client) NodesWatch

func (cli *Client) NodesWatch(name string) (*NodesWatcher, error)

func (*Client) PodgroupGet

func (cli *Client) PodgroupGet(appname string) (*pb.PodgroupReply, error)

CODE GENERATION Nodes END CODE GENERATION Podgroup START

func (*Client) PodgroupWatch

func (cli *Client) PodgroupWatch(appname string) (*PodgroupWatcher, error)

func (*Client) ProxyGet

func (cli *Client) ProxyGet(appname string) (*pb.ProxyReply, error)

CODE GENERATION Podgroup END CODE GENERATION Proxy START

func (*Client) ProxyWatch

func (cli *Client) ProxyWatch(appname string) (*ProxyWatcher, error)

func (*Client) RebellionLocalprocsGet

func (cli *Client) RebellionLocalprocsGet(appname string) (*pb.RebellionLocalprocsReply, error)

CODE GENERATION Proxy END CODE GENERATION RebellionLocalprocs START

func (*Client) RebellionLocalprocsWatch

func (cli *Client) RebellionLocalprocsWatch(appname string) (*RebellionLocalprocsWatcher, error)

func (*Client) Status

func (cli *Client) Status() (*pb.StatusReply, error)

func (*Client) StreamrouterPortsGet

func (cli *Client) StreamrouterPortsGet(appname string) (*pb.StreamrouterPortsReply, error)

CODE GENERATION RebellionLocalprocs END CODE GENERATION StreamrouterPorts START

func (*Client) StreamrouterPortsWatch

func (cli *Client) StreamrouterPortsWatch(appname string) (*StreamrouterPortsWatcher, error)

func (*Client) StreamrouterStreamprocsGet

func (cli *Client) StreamrouterStreamprocsGet(appname string) (*pb.StreamrouterStreamprocsReply, error)

CODE GENERATION StreamrouterPorts END CODE GENERATION StreamrouterStreamprocs START

func (*Client) StreamrouterStreamprocsWatch

func (cli *Client) StreamrouterStreamprocsWatch(appname string) (*StreamrouterStreamprocsWatcher, error)

func (*Client) Version

func (cli *Client) Version() (*pb.VersionReply, error)

func (*Client) WebrouterWebprocsGet

func (cli *Client) WebrouterWebprocsGet(appname string) (*pb.WebrouterWebprocsReply, error)

CODE GENERATION StreamrouterStreamprocs END CODE GENERATION WebrouterWebprocs START

func (*Client) WebrouterWebprocsWatch

func (cli *Client) WebrouterWebprocsWatch(appname string) (*WebrouterWebprocsWatcher, error)

type Config

type Config struct {
	Addr               string
	CertFile           string
	ServerNameOverride string
	Timeout            int
}

type ConfigWatcher

type ConfigWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ConfigWatcher) Next

func (wch *ConfigWatcher) Next() (*pb.ConfigReply, error)

type ContainersWatcher

type ContainersWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ContainersWatcher) Next

func (wch *ContainersWatcher) Next() (*pb.ContainersReply, error)

type CoreinfoWatcher

type CoreinfoWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*CoreinfoWatcher) Next

func (wch *CoreinfoWatcher) Next() (*pb.CoreinfoReply, error)

type DependsWatcher

type DependsWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*DependsWatcher) Next

func (wch *DependsWatcher) Next() (*pb.DependsReply, error)

type NodesWatcher

type NodesWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*NodesWatcher) Next

func (wch *NodesWatcher) Next() (*pb.NodesReply, error)

type PodgroupWatcher

type PodgroupWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*PodgroupWatcher) Next

func (wch *PodgroupWatcher) Next() (*pb.PodgroupReply, error)

type ProxyWatcher

type ProxyWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ProxyWatcher) Next

func (wch *ProxyWatcher) Next() (*pb.ProxyReply, error)

type RebellionLocalprocsWatcher

type RebellionLocalprocsWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*RebellionLocalprocsWatcher) Next

type StreamrouterPortsWatcher

type StreamrouterPortsWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*StreamrouterPortsWatcher) Next

type StreamrouterStreamprocsWatcher

type StreamrouterStreamprocsWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*StreamrouterStreamprocsWatcher) Next

type WebrouterWebprocsWatcher

type WebrouterWebprocsWatcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*WebrouterWebprocsWatcher) Next

Jump to

Keyboard shortcuts

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