github.com/gramework/gramework@v1.8.1-0.20231027140105-82555c9057f5/app_serve.go (about) 1 // Copyright 2017-present Kirill Danshin and Gramework contributors 2 // Copyright 2019-present Highload LTD (UK CN: 11893420) 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 11 package gramework 12 13 import ( 14 "net" 15 ) 16 17 // Serve app on given listener 18 func (app *App) Serve(ln net.Listener) error { 19 var err error 20 srv := app.copyServer() 21 app.runningServersMu.Lock() 22 app.runningServers = append(app.runningServers, runningServerInfo{ 23 bind: ln.Addr().String(), 24 srv: srv, 25 }) 26 app.runningServersMu.Unlock() 27 if err = srv.Serve(ln); err != nil { 28 app.internalLog.Errorf("ListenAndServe failed: %s", err) 29 } 30 31 return err 32 }