MCPcopy Index your code
hub / github.com/puma/puma-dev / readProxy

Method readProxy

dev/app.go:366–424  ·  view source on GitHub ↗
(name, path string)

Source from the content-addressed store, hash-verified

364}
365
366func (pool *AppPool) readProxy(name, path string) (*App, error) {
367 data, err := ioutil.ReadFile(path)
368 if err != nil {
369 return nil, err
370 }
371
372 app := &App{
373 Name: name,
374 Events: pool.Events,
375 pool: pool,
376 readyChan: make(chan struct{}),
377 lastUse: time.Now(),
378 }
379
380 data = bytes.TrimSpace(data)
381
382 port, err := strconv.Atoi(string(data))
383 if err == nil {
384 app.SetAddress("http", "127.0.0.1", port)
385 } else {
386 u, err := url.Parse(string(data))
387 if err != nil {
388 return nil, err
389 }
390
391 var (
392 sport, host string
393 port int
394 )
395
396 host, sport, err = net.SplitHostPort(u.Host)
397 if err == nil {
398 port, err = strconv.Atoi(sport)
399 if err != nil {
400 return nil, err
401 }
402 } else {
403 host = u.Host
404 }
405
406 app.SetAddress(u.Scheme, host, port)
407 }
408
409 app.eventAdd("proxy_created",
410 "destination", fmt.Sprintf("%s://%s", app.Scheme, app.Address()))
411
412 fmt.Printf("* Generated proxy connection for '%s' to %s://%s\n",
413 name, app.Scheme, app.Address())
414
415 // to satisfy the tomb
416 app.t.Go(func() error {
417 <-app.t.Dying()
418 return nil
419 })
420
421 close(app.readyChan)
422
423 return app, nil

Callers 1

lookupAppMethod · 0.95

Calls 3

SetAddressMethod · 0.95
eventAddMethod · 0.95
AddressMethod · 0.95

Tested by

no test coverage detected