make httpagent a plugin
This commit is contained in:
parent
cc890642b6
commit
92d23eec09
|
@ -0,0 +1,9 @@
|
|||
// gopreload.go
|
||||
package main
|
||||
|
||||
/*
|
||||
This file is separate to make it very easy to both add into an application, but
|
||||
also very easy to remove.
|
||||
*/
|
||||
|
||||
import _ "github.com/Xe/gopreload"
|
|
@ -0,0 +1,59 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.xeserv.us/xena/route/lib/tun2"
|
||||
"github.com/Xe/ln"
|
||||
)
|
||||
|
||||
var (
|
||||
token = mustEnv("ROUTE_TOKEN", "")
|
||||
domain = mustEnv("ROUTE_DOMAIN", "")
|
||||
backend = mustEnv("ROUTE_BACKEND", "")
|
||||
method = mustEnv("ROUTE_METHOD", "")
|
||||
serverAddr = mustEnv("ROUTE_LOAD_BALANCER", "")
|
||||
connMethod = mustEnv("ROUTE_METHOD", "tcp")
|
||||
)
|
||||
|
||||
func mustEnv(key string, def string) string {
|
||||
val := os.Getenv(key)
|
||||
if val == "" {
|
||||
log.Printf("autohttpagent: %s not found, things may not work", key)
|
||||
return def
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func doHttpAgent() {
|
||||
go func() {
|
||||
cfg := &tun2.ClientConfig{
|
||||
TLSConfig: &tls.Config{},
|
||||
ConnType: connMethod,
|
||||
ServerAddr: serverAddr,
|
||||
Token: token,
|
||||
Domain: domain,
|
||||
BackendURL: backend,
|
||||
}
|
||||
|
||||
client, _ := tun2.NewClient(cfg)
|
||||
err := client.Connect()
|
||||
if err != nil {
|
||||
ln.Error(err, ln.F{
|
||||
"action": "client_running",
|
||||
})
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
doHttpAgent()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func init() {
|
||||
doHttpAgent()
|
||||
}
|
Loading…
Reference in New Issue