netservice

package
v1.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: May 23, 2017 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultReverseProxy = &ReverseProxy{Cfg: &ReverseProxyConfigData{}}

Functions

func ListenAndServePProf

func ListenAndServePProf(addr string, handler http.Handler)

func LoadClientConfig

func LoadClientConfig(configFilePath string)
{
	"cluster":"测集群",
	"router_list":[
		"127.0.0.1:8888",
		"172.16.200.202:8888"
	]
}

load client json config file

func LoadServerJsonConfig

func LoadServerJsonConfig(config string)

loade serverConfig

func StartNetworkService

func StartNetworkService()

start networkservice

func StopNetworkService

func StopNetworkService()

stop service

Types

type CertificateConfig

type CertificateConfig struct {
	Domain   string
	CertFile string
	KeyFile  string
}

certificate config

type Client

type Client struct {
	Host        string
	Port        string
	TaskFlag    chan bool //syn channel
	ConnectFlag chan bool //connect syn channel
	Closed      bool
	ConnSocket  net.Conn
}

func NewClient

func NewClient(host, port string) *Client

create client agent

func (*Client) ConnectToServer

func (self *Client) ConnectToServer(addr string)

connect to server

func (*Client) Disconnect

func (self *Client) Disconnect()

Disconnnect

func (*Client) Run

func (self *Client) Run()

Connect to remote routing server

type ClientConfig

type ClientConfig struct {
	ClusterName string   `json:"cluster"`
	RouterList  []string `json:"router_list"`
}

client config

var ClientConfigData ClientConfig

type HostInfo

type HostInfo struct {
	Port string `json:"port"`
	Host string `json:"host"`
}

type Http

type Http struct {
	Host string
	Port string
}

func NewHttp

func NewHttp(host, port string) *Http

create http service

func (*Http) ActiveClientInfos

func (self *Http) ActiveClientInfos(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

Active ClientInfos

func (*Http) AddDomain

func (self *Http) AddDomain(w http.ResponseWriter, r *http.Request, prms httprouter.Params)

func (*Http) AddProxyClient

func (self *Http) AddProxyClient(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

func (*Http) BestClients

func (self *Http) BestClients(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

The highest weight of the server

func (*Http) ClientInfos

func (self *Http) ClientInfos(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

ClientInfos All servers info include active and inactive

func (*Http) DelDomain

func (self *Http) DelDomain(w http.ResponseWriter, r *http.Request, prms httprouter.Params)

func (*Http) DeleteProxyClient

func (self *Http) DeleteProxyClient(w http.ResponseWriter, r *http.Request, prms httprouter.Params)

func (*Http) DomainInfos

func (self *Http) DomainInfos(w http.ResponseWriter, r *http.Request, prms httprouter.Params)

func (*Http) Index

func (self *Http) Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

index redirect to static

func (*Http) ProxyInfos

func (self *Http) ProxyInfos(w http.ResponseWriter, r *http.Request, prms httprouter.Params)

Reverse Proxy infp

func (*Http) RouterInfo

func (self *Http) RouterInfo(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

router server info

func (*Http) Run

func (self *Http) Run()

run router server

func (*Http) Statistics

func (self *Http) Statistics(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

statistics

func (*Http) UpdateDomain

func (self *Http) UpdateDomain(w http.ResponseWriter, r *http.Request, prms httprouter.Params)

change proxy domain

func (*Http) WriteJsonInterface

func (self *Http) WriteJsonInterface(w http.ResponseWriter, data interface{})

func (*Http) WriteJsonString

func (self *Http) WriteJsonString(w http.ResponseWriter, str string)

type HttpsServer

type HttpsServer struct {
	http.Server
	//If GetCertificate is set, the leaf certificate is returned by calling this function.
	GetCertificate func(*tls.ClientHelloInfo) (*tls.Certificate, error)
}

https server

func NewHttpsServer

func NewHttpsServer() *HttpsServer

func (*HttpsServer) AddDomainCertificateConfig

func (self *HttpsServer) AddDomainCertificateConfig(config []*CertificateConfig) error

Add the certificate to the tls.Config.Certificates list, and add the domain name mapping

func (*HttpsServer) AddDomainCertificateItem

func (self *HttpsServer) AddDomainCertificateItem(domain, certFile, keyFile string) error

Add the certificate to the tls.Config.Certificates list, and add the domain name mapping

func (*HttpsServer) RunHttpsService

func (self *HttpsServer) RunHttpsService(addr, certFile, keyFile string, handler http.Handler) error

Start the https server If the two parameters certFile and keyFile are empty, you must call the addDomainCertificate function or the addDomainCertificate function to add a list of digital certificates to multiple certificates list

type LbNode

type LbNode struct {
	Domain      string      `json:"domain"`
	HttpsSwitch string      `json:"https_switch"`
	HttpSwitch  string      `json:"http_switch"`
	Clients     []*HostInfo `json:"clients"`
}

Load Balance Node

type ReverseProxy

type ReverseProxy struct {
	DomainHostList cache.Cacher
	Cfg            *ReverseProxyConfigData

	//certificate config
	CertificateConfigData []*CertificateConfig
	ProxyCongfigFile      string
	ProxyMethod           string
	// contains filtered or unexported fields
}

reverse proxy handler

func NewReverseProxy

func NewReverseProxy() *ReverseProxy

Create new reverse proxy instance

func (*ReverseProxy) AddDomainConfig

func (this *ReverseProxy) AddDomainConfig(domain string) bool

Add the domain name to the configuration

func (*ReverseProxy) AddProxyClient

func (this *ReverseProxy) AddProxyClient(domain, hostip, port, httsSwitch, httpSwitch string) int

Add the reverse proxy client to the specified domain name Return Value -1 Repeat

0  Failure
1  Success

func (*ReverseProxy) BeginHttpStatistics

func (this *ReverseProxy) BeginHttpStatistics()

Run the http statistics service

func (*ReverseProxy) ChangeSwitchStatus

func (this *ReverseProxy) ChangeSwitchStatus(domain, protocol, switchStatus string)

func (*ReverseProxy) DeleteDomainConig

func (this *ReverseProxy) DeleteDomainConig(domain string) bool

Delete the domain name and sync to the configuration file

func (*ReverseProxy) DeleteProxyClient

func (this *ReverseProxy) DeleteProxyClient(domain, hostip, port string) bool

delete reverse proxydomain

func (*ReverseProxy) DomainInfos

func (this *ReverseProxy) DomainInfos() []string

domain list

func (*ReverseProxy) GetDomainHostList

func (this *ReverseProxy) GetDomainHostList(domain string) []*HostInfo

hostlist by domain

func (*ReverseProxy) LoadCertificateConfig

func (this *ReverseProxy) LoadCertificateConfig(certificateConfigFile string)

Load Certificate Config

func (*ReverseProxy) LoadProxyConfig

func (this *ReverseProxy) LoadProxyConfig(proxyConfigFile string)

Load proxy config

func (*ReverseProxy) SaveToFile

func (this *ReverseProxy) SaveToFile() bool

save to file

func (*ReverseProxy) ServeHTTP

func (self *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

Http and Https reverse proxy handeler

func (*ReverseProxy) StartAllHttpService

func (this *ReverseProxy) StartAllHttpService() bool

start all http service

func (*ReverseProxy) StartAllHttpsService

func (this *ReverseProxy) StartAllHttpsService() bool

start all https service

func (*ReverseProxy) StartProxyServer

func (self *ReverseProxy) StartProxyServer()

Run Reverse Proxy

func (*ReverseProxy) StopAllHttpsService

func (this *ReverseProxy) StopAllHttpsService() bool

stop all https service

func (*ReverseProxy) StoptAllHttpService

func (this *ReverseProxy) StoptAllHttpService() bool

stop all http service

func (*ReverseProxy) UpdateDomain

func (this *ReverseProxy) UpdateDomain(preDomain, updateDomain, httpsSwitch, httpSwitch string) bool

update domain

func (*ReverseProxy) UpdateProxyClient

func (this *ReverseProxy) UpdateProxyClient(domain, preHost, prePort, updateHost, updatePort, httpsSwitch, httpSwitch string) bool

Update Reverse Proxy Client Info

type ReverseProxyConfigData

type ReverseProxyConfigData struct {
	ProxyMethod   string `json:"proxy_method"`
	HttpProxyAddr string `json:"http_proxy_addr"`
	//global http switch
	GlobalHttpSwitch string `json:"http_switch"`
	//global https switch
	GlobalHttpsSwitch string                       `json:"https_switch"`
	HttpsProxyAddr    string                       `json:"https_proxy_addr"`
	ReverseProxy      []*LbNode                    `json:"reserve_proxy"`
	DomainProxySwitch map[string]map[string]string `json:"-"`
}

ReverseProxy Config

type Server

type Server struct {
	Host         string
	Port         string
	TaskFlag     chan bool    //syn channel
	ListenSocket net.Listener //conn
}

Router server infomational encapsulation

func NewServer

func NewServer() *Server

create server

func (*Server) OnDataRecv

func (self *Server) OnDataRecv(c net.Conn)

Data Receive

func (*Server) Run

func (self *Server) Run(host, port string)

run router server

func (*Server) StopServer

func (self *Server) StopServer()

Send Service Stop Message We Shoule Close all connections before stopping the server。

type ServerConfig

type ServerConfig struct {
	Host       string `json:"host"`
	Port       string `json:"port"`
	ServerMode string `json:"srvmode"`
	HttpHost   string `json:"httphost"`
	HttpPort   string `json:"httpport"`
}

server config mapping struct

var ServerConfigData ServerConfig

server config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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