Projects STRLCPY goc2 Commits 7ac79ae1
🤬
  • ■ ■ ■ ■ ■ ■
    web/server.go
    skipped 5 lines
    6 6   "goc2/internal/app/api"
    7 7   "io/ioutil"
    8 8   "log"
     9 + "net"
    9 10   "net/http"
     11 + "os"
     12 + "time"
    10 13   
    11 14   //"text/template"
    12 15   
    skipped 12 lines
    25 28   
    26 29  //Start the Web Server
    27 30  func Start(port string) {
     31 + status := rawConnect("127.0.0.1", "27017")
     32 + if status == false {
     33 + fmt.Println("Mongo is not running")
     34 + os.Exit(0)
     35 + }
    28 36   router := httprouter.New()
    29 37   
    30 38   router.ServeFiles("/files/*filepath", http.Dir("/tmp/c2"))
    skipped 228 lines
    259 267   fmt.Fprintf(w, json)
    260 268  }
    261 269   
     270 +func rawConnect(host string, port string) bool {
     271 + timeout := time.Second
     272 + conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, port), timeout)
     273 + if err != nil {
     274 + fmt.Println("Connecting error:", err)
     275 + return false
     276 + }
     277 + if conn != nil {
     278 + defer conn.Close()
     279 + fmt.Println("Opened", net.JoinHostPort(host, port))
     280 + return true
     281 + }
     282 + return false
     283 +}
     284 + 
Please wait...
Page is in error, reload to recover