server

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2015 License: MIT Imports: 13 Imported by: 40

README

the server framework.

includes:

  • tcp/http service framework
  • rpc helper
  • stats api
  • timer task interface

Documentation

Overview

http server library.

log provides log api. thanks to the helpful log tool logrus(https://github.com/Sirupsen/logrus)

RPCClient implements a rpc client tool with reconnect and load balance.

rpc server

package server provides service interfaces and libraries. including: tcp/http server library. rpc service library with addon functionality. service discory and registration Logic. statistic lib.

tcp server library.

Index

Constants

View Source
const (
	FlagTCPHost  = "tcphost"
	FlagUseTls   = "usetls"
	FlagHTTPHost = "httphost"
	FlagUseHttps = "usehttps"
	FlagCAFile   = "cafile"
	FlagKeyFile  = "keyfile"
	FlagRPCHost  = "rpchost"
	FlagEtcd     = "etcd"
	FlagLogLevel = "loglevel"
)
View Source
const (
	EtcdServersPrefix    = "/pando/servers/"
	EtcdServersPrefixCnt = 2
)

Variables

View Source
var (
	InternalIP string
	ExternalIP string
)

Functions

func GetRPCHost

func GetRPCHost() string

get this server's rpc host

func GetServerHosts

func GetServerHosts(serverName string, hostType string) ([]string, error)

get server's hosts by server name and service type

func Init

func Init(name string) error

init the server with specific name.

func RPCCallByHost

func RPCCallByHost(host string, serverMethod string, args interface{}, reply interface{}) error

rpc call by host

func RPCCallByName

func RPCCallByName(serverName string, serverMethod string, args interface{}, reply interface{}) error

rpc call by name

func RegisterHTTPHandler

func RegisterHTTPHandler(handler http.Handler) error

register HTTP handler class

func RegisterRPCHandler

func RegisterRPCHandler(rcvr interface{}) error

register RPC handler class

func RegisterTCPHandler

func RegisterTCPHandler(handler TCPHandler) error

register TCP handler class

func RegisterTimerTask

func RegisterTimerTask(task TimerTask) error

register timer task

func Run

func Run() error

start service

Types

type HTTPServer

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

func (*HTTPServer) Start

func (hs *HTTPServer) Start() error

type RPCClient

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

func NewRPCClient

func NewRPCClient() (*RPCClient, error)

func (*RPCClient) Call

func (client *RPCClient) Call(severName string, serverMethod string, args interface{}, reply interface{}) error

RPC call with reconnect and retry.

func (*RPCClient) CallHost

func (client *RPCClient) CallHost(host string, serverMethod string, args interface{}, reply interface{}) error

RPC call by host

type RPCServer

type RPCServer struct {
	TCPServer
}

type Server

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

Server

type ServerManager

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

func NewServerManager

func NewServerManager(name string, etcd string) (*ServerManager, error)

etcd hosts is config as http://ip1:port1;http://ip2:port2;http://ip3:port3

func (*ServerManager) GetServerHosts

func (mgr *ServerManager) GetServerHosts(serverName string, hostType string) ([]string, error)

get host ips for the server, now return all hosts

func (*ServerManager) RegisterServer

func (mgr *ServerManager) RegisterServer() error

register server to etcd

func (*ServerManager) UpdateServerHosts

func (mgr *ServerManager) UpdateServerHosts() error

update server hosts

type TCPHandler

type TCPHandler interface {
	Handle(net.Conn)
}

type TCPServer

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

func (*TCPServer) Start

func (ts *TCPServer) Start() error

start will keep accepting and serving tcp connections.

type TimerTask

type TimerTask interface {
	DoTask()
}

Jump to

Keyboard shortcuts

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