SHARE
TWEET

Untitled

a guest Jun 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func run (appName string) (err error) {
  2.  
  3.  
  4.         done = make(chan bool)
  5.         defer close(done)
  6.  
  7.  
  8.         serviceURL, e := GetContext().getServiceURL(appName)
  9.  
  10.         if e != nil {
  11.             err = errors.New("process failed" + err.Error())
  12.             LogDebug("Exiting %v func[err =%v]", methodName, err)
  13.             return err
  14.         }
  15.  
  16.         url := "wss://" + serviceURL + route
  17.  
  18.         stateMachine = 0
  19.  
  20.         socket := gowebsocket.New(url)
  21.         addPass(&socket, user, pass)
  22.  
  23.  
  24.         socket.OnConnectError = OnConnectErrorHandler
  25.         socket.OnConnected = OnConnectedHandler
  26.         socket.OnTextMessage = socketTextMessageHandler
  27.         socket.OnDisconnected = OnDisconnectedHandler
  28.  
  29.         LogDebug("In %v func connecting to URL  %v", methodName, url)
  30.         socket.Connect()
  31.  
  32.         jsonBytes, e := json.Marshal(payload)
  33.         if e != nil {
  34.             err = errors.New("build process failed" + e.Error())
  35.             LogDebug("Exiting %v func[err =%v]", methodName, err)
  36.             return err
  37.         }
  38.  
  39.         jsonStr := string(jsonBytes)
  40.  
  41.         LogDebug("In %v Connecting to payload JSON is  %v", methodName, jsonStr)
  42.         socket.SendText(jsonStr)
  43.  
  44.         <-done
  45.         LogDebug("Exiting %v func[err =%v]", methodName, err)
  46.         return err
  47.  
  48.     }
  49.  
  50.  
  51.     func OnConnectErrorHandler(err error, socket gowebsocket.Socket) {
  52.         methodName := "OnConnectErrorHandler"
  53.         LogDebug("Starting %v parameters [err = %v , socket = %v]", methodName, err, socket)
  54.         LogInfo("Disconnected from server ")
  55.         done <- true
  56.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top