Documentation ¶
Index ¶
- Constants
- Variables
- func FormatOutput(in string) string
- func GRPCClient(address string) (*grpc.ClientConn, error)
- func GRPCClientNoTrace(address string) (*grpc.ClientConn, error)
- func GRPCServer(port string) (*grpc.Server, error)
- func GRPCServerNoTrace(port string) (*grpc.Server, error)
- func GoDiscoveryBroadcast(ctx context.Context, multicastAddress, port string, ipVersion IPVersion, ...)
- func HttpFileASyncDownloadWithProcess(url, path string) ...
- func HttpFileDownload(url, path string) error
- func MustGRPCClient(address string) *grpc.ClientConn
- func NewPkgTcpClient(address string, fun TcpHandler) (*pkgTCPclient, error)
- func NewPkgTcpServer(port string, fun TcpHandler) (*pkgAsyncTCPServer, error)
- func NewTcpServer(port string, fun TcpHandler) (*asyncTCPServer, error)
- func ProcessInput(buffer string) (left string, output string)
- func PublicIP() string
- type Client
- type ClientOptions
- type DiscoverSettings
- type Discovered
- type HttpResponse
- func HttpDelete(url string) (*HttpResponse, error)
- func HttpGet(url string) (*HttpResponse, error)
- func HttpPost(url string, data []byte) (*HttpResponse, error)
- func HttpPostWithReader(url string, data io.Reader) (*HttpResponse, error)
- func HttpPutJson(url string, data interface{}) (*HttpResponse, error)
- func ParseHttpResponse(r *http.Response) (*HttpResponse, error)
- type IPVersion
- type KV
- type NetPacketConn
- type PacketConn4
- type PacketConn6
- type TcpClient
- type TcpHandler
Constants ¶
const BufferSize uint16 = 200
BufferSize 服务器数据读写buffer大小
const HeaderSize int = 8
const Index string = "^"
Index 包头识别符,格式(^)(size)(data), `^`后跟数据包长度,占位长度为PKG_SIZE 例如^6 abc123
Variables ¶
Functions ¶
func GRPCClient ¶
func GRPCClient(address string) (*grpc.ClientConn, error)
func GRPCClientNoTrace ¶
func GRPCClientNoTrace(address string) (*grpc.ClientConn, error)
func GoDiscoveryBroadcast ¶
func HttpFileASyncDownloadWithProcess ¶
HttpFileASyncDownloadWithProcess http下载,并实时返回下载的大小
func MustGRPCClient ¶ added in v0.9.0
func MustGRPCClient(address string) *grpc.ClientConn
func NewPkgTcpClient ¶
func NewPkgTcpClient(address string, fun TcpHandler) (*pkgTCPclient, error)
func NewPkgTcpServer ¶
func NewPkgTcpServer(port string, fun TcpHandler) (*pkgAsyncTCPServer, error)
func NewTcpServer ¶
func NewTcpServer(port string, fun TcpHandler) (*asyncTCPServer, error)
Types ¶
type Client ¶
type Client interface { Put(ctx context.Context, key, value string) error Get(ctx context.Context, key string) (string, error) //GetWithPrefix 按前缀获取数据 GetWithPrefix(ctx context.Context, prefix string) ([]KV, error) Delete(ctx context.Context, key string) error Watch(ctx context.Context, key string) (<-chan struct{}, error) WatchPrefix(ctx context.Context, prefix string) (<-chan struct{}, error) WatchFunc(ctx context.Context, key string, f func()) error WatchFuncPrefix(ctx context.Context, prefix string, f func()) error //WatchOnce 针对某个key有且只能watch一次 WatchOnce(ctx context.Context, key string) (<-chan struct{}, error) //WatchOncePrefix 针对某个前缀有且只能watch一次 // <-chan struct{}触发时,可以用GetWithPrefix获取最新数据 WatchOncePrefix(ctx context.Context, prefix string) (<-chan struct{}, error) Close() }
func NewETCDClientV3 ¶
func NewETCDClientV3(endpoints []string, options ClientOptions) (Client, error)
type ClientOptions ¶
type DiscoverSettings ¶
type DiscoverSettings struct { // Limit is the number of peers to discover, use < 1 for unlimited. Limit int // Port is the port to broadcast on (the peers must also broadcast using the same port). // The default port is 9999. Port string // MulticastAddress specifies the multicast address. // You should be able to use any of 224.0.0.0/4 or ff00::/8. // By default it uses the Simple Service Discovery Protocol // address (239.255.255.250 for IPv4 or ff02::c for IPv6). MulticastAddress string // Payload is the bytes that are sent out with each broadcast. Must be short. Payload []byte // PayloadFunc is the function that will be called to dynamically generate payload // before every broadcast. If this pointer is nil `Payload` field will be broadcasted instead. PayloadFunc func() []byte // Delay is the amount of time between broadcasts. The default delay is 1 second. Delay time.Duration // TimeLimit is the amount of time to spend discovering, if the limit is not reached. // A negative limit indiciates scanning until the limit was reached or, if an // unlimited scanning was requested, no timeout. // The default time limit is 10 seconds. TimeLimit time.Duration // StopChan is a channel to stop the peer discvoery immediatley after reception. StopChan chan struct{} // AllowSelf will allow discovery the local machine (default false) AllowSelf bool // DisableBroadcast will not allow sending out a broadcast DisableBroadcast bool // IPVersion specifies the version of the Internet Protocol (default IPv4) IPVersion IPVersion // Notify will be called each time a new peer was discovered. // The default is nil, which means no notification whatsoever. Notify func(Discovered) // contains filtered or unexported fields }
Settings are the settings that can be specified for doing peer discovery.
type Discovered ¶
type Discovered struct { // Address is the local address of a discovered peer. Address string // Payload is the associated payload from discovered peer. Payload []byte }
Discovered is the structure of the discovered peers, which holds their local address (port removed) and a payload if there is one.
func Discover ¶
func Discover(s DiscoverSettings) (discoveries []Discovered, err error)
Discover will use the created settings to scan for LAN peers. It will return an array of the discovered peers and their associate payloads. It will not return broadcasts sent to itself.
func (Discovered) String ¶
func (d Discovered) String() string
type HttpResponse ¶
type HttpResponse struct {
// contains filtered or unexported fields
}
func HttpDelete ¶
func HttpDelete(url string) (*HttpResponse, error)
func HttpGet ¶
func HttpGet(url string) (*HttpResponse, error)
func HttpPost ¶
func HttpPost(url string, data []byte) (*HttpResponse, error)
func HttpPostWithReader ¶
func HttpPostWithReader(url string, data io.Reader) (*HttpResponse, error)
func HttpPutJson ¶
func HttpPutJson(url string, data interface{}) (*HttpResponse, error)
func ParseHttpResponse ¶
func ParseHttpResponse(r *http.Response) (*HttpResponse, error)
func (*HttpResponse) GetBody ¶
func (res *HttpResponse) GetBody() []byte
func (*HttpResponse) GetBodyString ¶
func (res *HttpResponse) GetBodyString() string
func (*HttpResponse) GetCode ¶
func (res *HttpResponse) GetCode() int
func (*HttpResponse) GetHeader ¶
func (res *HttpResponse) GetHeader(key string) ([]string, bool)
type IPVersion ¶
type IPVersion uint
IPVersion specifies the version of the Internet Protocol to be used.
type NetPacketConn ¶
type PacketConn4 ¶
type PacketConn4 struct {
*ipv4.PacketConn
}
func (PacketConn4) ReadFrom ¶
ReadFrom wraps the ipv4 ReadFrom without a control message
type PacketConn6 ¶
type PacketConn6 struct {
*ipv6.PacketConn
}
func (PacketConn6) ReadFrom ¶
ReadFrom wraps the ipv6 ReadFrom without a control message
func (PacketConn6) SetMulticastTTL ¶
func (pc6 PacketConn6) SetMulticastTTL(i int) error
SetMulticastTTL wraps the hop limit of ipv6