MCPcopy
hub / github.com/CodisLabs/codis / New

Function New

pkg/proxy/proxy.go:58–103  ·  view source on GitHub ↗
(config *Config)

Source from the content-addressed store, hash-verified

56var ErrClosedProxy = errors.New("use of closed proxy")
57
58func New(config *Config) (*Proxy, error) {
59 if err := config.Validate(); err != nil {
60 return nil, errors.Trace(err)
61 }
62 if err := models.ValidateProduct(config.ProductName); err != nil {
63 return nil, errors.Trace(err)
64 }
65
66 s := &Proxy{}
67 s.config = config
68 s.exit.C = make(chan struct{})
69 s.router = NewRouter(config)
70 s.ignore = make([]byte, config.ProxyHeapPlaceholder.Int64())
71
72 s.model = &models.Proxy{
73 StartTime: time.Now().String(),
74 }
75 s.model.ProductName = config.ProductName
76 s.model.DataCenter = config.ProxyDataCenter
77 s.model.Pid = os.Getpid()
78 s.model.Pwd, _ = os.Getwd()
79 if b, err := exec.Command("uname", "-a").Output(); err != nil {
80 log.WarnErrorf(err, "run command uname failed")
81 } else {
82 s.model.Sys = strings.TrimSpace(string(b))
83 }
84 s.model.Hostname = utils.Hostname
85
86 if err := s.setup(config); err != nil {
87 s.Close()
88 return nil, err
89 }
90
91 log.Warnf("[%p] create new proxy:\n%s", s, s.model.Encode())
92
93 unsafe2.SetMaxOffheapBytes(config.ProxyMaxOffheapBytes.Int64())
94
95 go s.serveAdmin()
96 go s.serveProxy()
97
98 s.startMetricsJson()
99 s.startMetricsInfluxdb()
100 s.startMetricsStatsd()
101
102 return s, nil
103}
104
105func (s *Proxy) setup(config *Config) error {
106 proto := config.ProtoType

Callers 1

openProxyFunction · 0.70

Calls 14

setupMethod · 0.95
CloseMethod · 0.95
serveAdminMethod · 0.95
serveProxyMethod · 0.95
startMetricsJsonMethod · 0.95
startMetricsInfluxdbMethod · 0.95
startMetricsStatsdMethod · 0.95
NewRouterFunction · 0.85
WarnErrorfMethod · 0.80
WarnfMethod · 0.80
ValidateMethod · 0.45
Int64Method · 0.45

Tested by 1

openProxyFunction · 0.56