本文整理汇总了Golang中ngrok/log.Info函数的典型用法代码示例。如果您正苦于以下问题:Golang Info函数的具体用法?Golang Info怎么用?Golang Info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: autoUpdate
func autoUpdate(s mvc.State, token string) {
up, err := update.New().VerifySignatureWithPEM([]byte(publicKey))
if err != nil {
log.Error("Failed to create update with signature: %v", err)
return
}
update := func() (tryAgain bool) {
log.Info("Checking for update")
params := check.Params{
AppId: appId,
AppVersion: version.MajorMinor(),
UserId: token,
}
result, err := params.CheckForUpdate(updateEndpoint, up)
if err == check.NoUpdateAvailable {
log.Info("No update available")
return true
} else if err != nil {
log.Error("Error while checking for update: %v", err)
return true
}
if result.Initiative == check.INITIATIVE_AUTO {
if err := up.CanUpdate(); err != nil {
log.Error("Can't update: insufficient permissions: %v", err)
// tell the user to update manually
s.SetUpdateStatus(mvc.UpdateAvailable)
} else {
applyUpdate(s, result)
}
} else if result.Initiative == check.INITIATIVE_MANUAL {
// this is the way the server tells us to update manually
log.Info("Server wants us to update manually")
s.SetUpdateStatus(mvc.UpdateAvailable)
} else {
log.Info("Update available, but ignoring")
}
// stop trying after a single download attempt
// XXX: improve this so the we can:
// 1. safely update multiple times
// 2. only retry after temporary errors
return false
}
// try to update immediately and then at a set interval
for {
if tryAgain := update(); !tryAgain {
break
}
time.Sleep(updateCheckInterval)
}
}
示例2: NewWebView
func NewWebView(ctl *ui.Controller, state ui.State, port int) *WebView {
w := &WebView{}
switch p := state.GetProtocol().(type) {
case *proto.Http:
NewWebHttpView(ctl, p)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/http/in", 302)
})
http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
parts := strings.Split(r.URL.Path, "/")
name := parts[len(parts)-1]
fn, ok := static.AssetMap[name]
if !ok {
http.NotFound(w, r)
return
}
w.Write(fn())
})
log.Info("Serving web interface on localhost:%d", port)
go http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
return w
}
示例3: init
func init() {
metrics.windowsCounter = gometrics.NewCounter()
metrics.linuxCounter = gometrics.NewCounter()
metrics.osxCounter = gometrics.NewCounter()
metrics.otherCounter = gometrics.NewCounter()
/*
metrics.bytesInCount = gometrics.NewCounter()
metrics.bytesOutCount = gometrics.NewCounter()
*/
/*
metrics.tunnelGauge = gometrics.NewGauge()
metrics.tcpTunnelGauge = gometrics.NewGauge()
metrics.requestGauge = gometrics.NewGauge()
*/
metrics.tunnelMeter = gometrics.NewMeter()
metrics.tcpTunnelMeter = gometrics.NewMeter()
metrics.requestMeter = gometrics.NewMeter()
metrics.lostHeartbeatMeter = gometrics.NewMeter()
metrics.requestTimer = gometrics.NewTimer()
go func() {
time.Sleep(reportInterval)
log.Info("Server metrics: %s", MetricsJson())
}()
}
示例4: tunnelListener
// Listen for incoming control and proxy connections
// We listen for incoming control and proxy connections on the same port
// for ease of deployment. The hope is that by running on port 443, using
// TLS and running all connections over the same port, we can bust through
// restrictive firewalls.
func tunnelListener(addr string, tlsConfig *tls.Config) {
// listen for incoming connections
listener, err := conn.Listen(addr, "tun", tlsConfig)
if err != nil {
panic(err)
}
log.Info("Listening for control and proxy connections on %s", listener.Addr.String())
for c := range listener.Conns {
go func(tunnelConn conn.Conn) {
tunnelConn.SetReadDeadline(time.Now().Add(connReadTimeout))
var rawMsg msg.Message
if rawMsg, err = msg.ReadMsg(tunnelConn); err != nil {
tunnelConn.Error("Failed to read message: %v", err)
tunnelConn.Close()
return
}
// don't timeout after the initial read, tunnel heartbeating will kill
// dead connections
tunnelConn.SetReadDeadline(time.Time{})
switch m := rawMsg.(type) {
case *msg.Auth:
NewControl(tunnelConn, m)
case *msg.RegProxy:
NewProxy(tunnelConn, m)
default:
tunnelConn.Close()
}
}(c)
}
}
示例5: tunnelListener
// Listen for incoming control and proxy connections
// We listen for incoming control and proxy connections on the same port
// for ease of deployment. The hope is that by running on port 443, using
// TLS and running all connections over the same port, we can bust through
// restrictive firewalls.
func tunnelListener(addr string, tlsConfig *tls.Config, secret string) {
// listen for incoming connections
listener, err := conn.Listen(addr, "tun", tlsConfig)
if err != nil {
panic(err)
}
log.Info("Listening for control and proxy connections on %s", listener.Addr.String())
if secret != "" {
log.Info("Clients should use '%s' as secret", secret)
}
for c := range listener.Conns {
go func(tunnelConn conn.Conn) {
// don't crash on panics
defer func() {
if r := recover(); r != nil {
tunnelConn.Info("tunnelListener failed with error %v: %s", r, debug.Stack())
}
}()
tunnelConn.SetReadDeadline(time.Now().Add(connReadTimeout))
var rawMsg msg.Message
if rawMsg, err = msg.ReadMsg(tunnelConn); err != nil {
tunnelConn.Warn("Failed to read message: %v", err)
tunnelConn.Close()
return
}
// don't timeout after the initial read, tunnel heartbeating will kill
// dead connections
tunnelConn.SetReadDeadline(time.Time{})
switch m := rawMsg.(type) {
case *msg.Auth:
NewControl(tunnelConn, m, secret)
case *msg.RegProxy:
NewProxy(tunnelConn, m)
default:
tunnelConn.Close()
}
}(c)
}
}
示例6: httpListener
/**
* Listens for new http connections from the public internet
*/
func httpListener(addr *net.TCPAddr) {
// bind/listen for incoming connections
listener, err := conn.Listen(addr, "pub", nil)
if err != nil {
panic(err)
}
log.Info("Listening for public http connections on %v", listener.Port)
for conn := range listener.Conns {
go httpHandler(conn)
}
}
示例7: controlListener
/**
* Listens for new control connections from tunnel clients
*/
func controlListener(addr *net.TCPAddr, domain string) {
// listen for incoming connections
listener, err := conn.Listen(addr, "ctl", tls.Config)
if err != nil {
panic(err)
}
log.Info("Listening for control connections on %d", listener.Port)
for c := range listener.Conns {
NewControl(c)
}
}
示例8: NewWebView
func NewWebView(ctl *ui.Controller, state ui.State, port int) *WebView {
v := &WebView{
wsMessages: util.NewBroadcast(),
}
switch p := state.GetProtocol().(type) {
case *proto.Http:
NewWebHttpView(v, ctl, p)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/http/in", 302)
})
http.HandleFunc("/_ws", func(w http.ResponseWriter, r *http.Request) {
conn, err := websocket.Upgrade(w, r.Header, nil, 1024, 1024)
if err != nil {
http.Error(w, "Failed websocket upgrade", 400)
log.Warn("Failed websocket upgrade: %v", err)
return
}
msgs := v.wsMessages.Reg()
defer v.wsMessages.UnReg(msgs)
for m := range msgs {
err := conn.WriteMessage(websocket.OpText, m.([]byte))
if err != nil {
// connection is closed
break
}
}
})
http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
parts := strings.Split(r.URL.Path, "/")
name := parts[len(parts)-1]
fn, ok := static.AssetMap[name]
if !ok {
http.NotFound(w, r)
return
}
w.Write(fn())
})
log.Info("Serving web interface on localhost:%d", port)
go http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
return v
}
示例9: applyUpdate
func applyUpdate(s mvc.State, result *check.Result) {
err, errRecover := result.Update()
if err == nil {
log.Info("Update ready!")
s.SetUpdateStatus(mvc.UpdateReady)
return
}
log.Error("Error while updating ngrok: %v", err)
if errRecover != nil {
log.Error("Error while recovering from failed ngrok update, your binary may be missing: %v", errRecover.Error())
}
// tell the user to update manually
s.SetUpdateStatus(mvc.UpdateAvailable)
}
示例10: progressWatcher
func progressWatcher(s mvc.State, progress chan int, complete chan int) {
for {
select {
case pct, ok := <-progress:
if !ok {
close(complete)
return
} else if pct == 100 {
s.SetUpdateStatus(mvc.UpdateInstalling)
close(complete)
return
} else {
if pct%25 == 0 {
log.Info("Downloading update %d%% complete", pct)
}
s.SetUpdateStatus(mvc.UpdateStatus(pct))
}
}
}
}
示例11: startHttpListener
// Listens for new http(s) connections from the public internet
func startHttpListener(addr string, tlsCfg *tls.Config) (listener *conn.Listener) {
// bind/listen for incoming connections
var err error
if listener, err = conn.Listen(addr, "pub", tlsCfg); err != nil {
panic(err)
}
proto := "http"
if tlsCfg != nil {
proto = "https"
}
log.Info("Listening for public %s connections on %v", proto, listener.Addr.String())
go func() {
for conn := range listener.Conns {
go httpHandler(conn, proto)
}
}()
return
}
示例12: reconnectingControl
func reconnectingControl(s *State, ctl *ui.Controller) {
// how long we should wait before we reconnect
maxWait := 30 * time.Second
wait := 1 * time.Second
for {
control(s, ctl)
if s.status == "online" {
wait = 1 * time.Second
}
log.Info("Waiting %d seconds before reconnecting", int(wait.Seconds()))
time.Sleep(wait)
// exponentially increase wait time
wait = 2 * wait
wait = time.Duration(math.Min(float64(wait), float64(maxWait)))
s.status = "reconnecting"
ctl.Update(s)
}
}
示例13: progressWatcher
func progressWatcher(s *State, ctl *ui.Controller, progress chan int, complete chan int) {
for {
select {
case pct, ok := <-progress:
if !ok {
close(complete)
return
} else if pct == 100 {
s.update = ui.UpdateInstalling
ctl.Update(s)
close(complete)
return
} else {
if pct%25 == 0 {
log.Info("Downloading update %d%% complete", pct)
}
s.update = ui.UpdateStatus(pct)
ctl.Update(s)
}
}
}
}
示例14: Run
func (c *ClientModel) Run() {
// how long we should wait before we reconnect
maxWait := 30 * time.Second
wait := 1 * time.Second
for {
// run the control channel
c.control()
// control oonly returns when a failure has occurred, so we're going to try to reconnect
if c.connStatus == mvc.ConnOnline {
wait = 1 * time.Second
}
log.Info("Waiting %d seconds before reconnecting", int(wait.Seconds()))
time.Sleep(wait)
// exponentially increase wait time
wait = 2 * wait
wait = time.Duration(math.Min(float64(wait), float64(maxWait)))
c.connStatus = mvc.ConnReconnecting
c.update()
}
}
示例15: proxyListener
/**
* Listens for new proxy connections from tunnel clients
*/
func proxyListener(addr *net.TCPAddr, domain string) {
listener, err := conn.Listen(addr, "pxy", tls.Config)
if err != nil {
panic(err)
}
// set global proxy addr variable
proxyAddr = fmt.Sprintf("%s:%d", domain, listener.Port)
log.Info("Listening for proxy connection on %d", listener.Port)
for proxyConn := range listener.Conns {
go func(conn conn.Conn) {
// fail gracefully if the proxy connection dies
defer func() {
if r := recover(); r != nil {
conn.Warn("Failed with error: %v", r)
conn.Close()
}
}()
// read the proxy register message
var regPxy msg.RegProxyMsg
if err = msg.ReadMsgInto(conn, ®Pxy); err != nil {
panic(err)
}
// look up the tunnel for this proxy
conn.Info("Registering new proxy for %s", regPxy.Url)
tunnel := tunnels.Get(regPxy.Url)
if tunnel == nil {
panic("No tunnel found for: " + regPxy.Url)
}
// register the proxy connection with the tunnel
tunnel.RegisterProxy(conn)
}(proxyConn)
}
}