Compare commits

..

10 Commits

Author SHA1 Message Date
Bel LaPointe
308fa2f73d no more logger 2019-05-02 09:36:03 -06:00
Bel LaPointe
cf77fa4696 no more local123 2018-10-21 08:49:25 -06:00
Bel LaPointe
f3613ac956 shhh 2018-10-13 19:25:18 -06:00
Bel LaPointe
7945901bcc anti vendor 2018-06-28 19:08:17 -06:00
Bel LaPointe
a4e1103885 vendor 2018-06-28 19:05:18 -06:00
Bel LaPointe
890fbaca60 chmod 2018-06-24 15:04:44 -06:00
Bel LaPointe
cb58ae5c8f remove exe 2018-06-21 14:09:45 -06:00
Bel LaPointe
81f3621cf8 gitignore executable 2018-06-21 14:03:21 -06:00
Bel LaPointe
e28cbfe5ce Only main catches signals 2018-06-21 13:51:57 -06:00
Bel LaPointe
b5de257f60 renamed other packages 2018-06-19 14:39:59 -06:00
2 changed files with 22 additions and 9 deletions

1
.gitignore vendored Executable file
View File

@@ -0,0 +1 @@
vpntorfeed

30
main.go Normal file → Executable file
View File

@@ -5,12 +5,15 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"local/jbtServiceDiscovery/jbt" "local/jbtserve/jbt"
"local/logger" "local/natsc"
natsc "local/nats-client"
"local/system/sysconf" "local/system/sysconf"
"log"
"net/http" "net/http"
"os"
"os/signal"
"regexp" "regexp"
"syscall"
"time" "time"
) )
@@ -18,14 +21,14 @@ func main() {
exit := make(chan bool) exit := make(chan bool)
config := sysconf.Get("vpntorfeed") config := sysconf.Get("vpntorfeed")
go jbt.RegisterDeregister(config.Name, config.Port, exit) go jbt.RegisterDeregister(config.Name, config.Port, exit)
logger.Log("Register attempted") log.Print("Register attempted")
// get from nats // get from nats
go func() { go func() {
client := &http.Client{Timeout: time.Second * 30} client := &http.Client{Timeout: time.Second * 30}
sub, err := natsc.NewSubscriber(config.DB) sub, err := natsc.NewSubscriber(config.DB)
if err != nil { if err != nil {
exit <- true <-exit
panic(err) panic(err)
} }
defer sub.Close() defer sub.Close()
@@ -34,17 +37,26 @@ func main() {
panic(err) panic(err)
} }
for msg := range ch { for msg := range ch {
logger.Logf("Topic %s received: %s\n", config.DB, msg) log.Printf("Topic %s received: %s\n", config.DB, msg)
err := doReq(client, msg) err := doReq(client, msg)
if err != nil { if err != nil {
logger.Log(err) log.Print(err)
} }
} }
}() }()
//magnets <- "magnet:?xt=urn:btih:64b2b05f61d2b9ef3213fce9860fb45c844d77fb&dn=checkmyiptorrent&tr=http%3A%2F%2F34.204.227.31%2Fcheckmytorrentipaddress.php" //magnets <- "magnet:?xt=urn:btih:64b2b05f61d2b9ef3213fce9860fb45c844d77fb&dn=checkmyiptorrent&tr=http%3A%2F%2F34.204.227.31%2Fcheckmytorrentipaddress.php"
sigc := make(chan os.Signal)
signal.Notify(sigc,
syscall.SIGINT,
)
<-sigc
<-exit <-exit
logger.Log("Exit received") select {
case <-exit:
case <-time.After(time.Second * 10):
}
log.Print("Exit received")
} }
func getSessionID() string { func getSessionID() string {
@@ -86,7 +98,7 @@ func doReq(client *http.Client, magnet string) error {
panic(err) panic(err)
} }
logger.Log(resp.StatusCode, magnet) log.Print(resp.StatusCode, magnet)
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
return errors.New("err failed request") return errors.New("err failed request")
} }