MCPcopy Create free account
hub / github.com/PuerNya/git-proxy / run

Function run

main.go:251–324  ·  view source on GitHub ↗
(*cobra.Command, []string)

Source from the content-addressed store, hash-verified

249}
250
251func run(*cobra.Command, []string) {
252 if bandwidthLimit > 0 {
253 BandwidthLimiter = R.NewBucketWithRate(float64(bandwidthLimit*1024*1024), int64(bandwidthLimit*1024*1024))
254 log.Info("Bandwidth limit is set as ", bandwidthLimit, "MB/s")
255 }
256 if requestLimit > 0 {
257 log.Info("Request limit is set as ", requestLimit, " each IP")
258 RequestLimiter = NewIPLimiter()
259 }
260 if denyWebPage {
261 log.Info("Denying web page requests")
262 }
263 if watcher, err := loadDomainList(); err == nil {
264 err = watcher.Start()
265 if err == nil {
266 log.Info("Watching accept domain list")
267 defer watcher.Close()
268 } else {
269 log.Error(E.Cause(err, "Start watch accept domain list"))
270 watcher.Close()
271 }
272 }
273 if watcher, err := loadBlackList(); err == nil {
274 err = watcher.Start()
275 if err == nil {
276 log.Info("Watching repository blacklist")
277 defer watcher.Close()
278 } else {
279 log.Error(E.Cause(err, "Start watch repository blacklist"))
280 watcher.Close()
281 }
282 }
283 listen := M.ParseSocksaddr(":" + strconv.Itoa(runningPort))
284 listener := listenTCP(listen)
285 if len(certPath) == 0 || len(keyPath) == 0 {
286 log.Info("Listening TCP port ", listen.Port)
287 } else if container, err := NewCertContainer(); err != nil {
288 log.Warn(E.Cause(err, "Update TCP to TLS"))
289 log.Info("Listening TCP port ", listen.Port)
290 } else {
291 log.Info("Listening TLS port ", listen.Port)
292 listener = tls.NewListener(listener, &tls.Config{
293 NextProtos: []string{"h2", "http/1.1"},
294 GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
295 return &container.Cert, nil
296 },
297 })
298 defer container.Close()
299 }
300 chiRouter := chi.NewRouter()
301 chiRouter.Group(func(r chi.Router) {
302 r.Use(middleware.RealIP)
303 r.Use(setContext)
304 r.Use(commonLog)
305 r.Use(requestLimitHandle)
306 r.Get("/", hello)
307 r.Mount("/", finalHandle())
308 })

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
NewIPLimiterFunction · 0.85
loadDomainListFunction · 0.85
loadBlackListFunction · 0.85
listenTCPFunction · 0.85
NewCertContainerFunction · 0.85
finalHandleFunction · 0.85
ErrorMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected