Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. /* tick-tock.go */
  2. package main
  3.  
  4. import (
  5. "fmt"
  6. "io/ioutil"
  7. "log"
  8. "net/http"
  9. )
  10.  
  11. // Content for the main html page..
  12. var page = `<html>
  13. <head>
  14. <script type="text/javascript"
  15. src="http://localhost:8081/jquery.min.js">
  16. </script>
  17. <style>
  18. div {
  19. font-family: "Times New Roman", Georgia, Serif;
  20. font-size: 1em;
  21. width: 13.3em;
  22. padding: 8px 8px;
  23. border: 2px solid #2B1B17;
  24. color: #2B1B17;
  25. text-shadow: 1px 1px #E5E4E2;
  26. background: #FFFFFF;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <h2 align=center>Go Timer </h2>
  32. <div id="output" style="width: 30%; height: 63%; overflow-y: scroll; float:left;"></div>
  33. <div id="v1" style="width: 50%; height: 30%; overflow-y: scroll; float:left;"></div>
  34. <div id="v2" style="width: 50%; height: 30%; overflow-y: scroll; float:left;"></div>
  35. <input id="sett" type="submit" name="sett" value="Settings" onclick="changeUrl()">
  36.  
  37. <script type="text/javascript">
  38.  
  39. var myDelay;
  40.  
  41. $(document).ready(function ()
  42. {
  43. $("#output").append("Waiting for system time..");
  44.  
  45. myDelay = setInterval("delayedPost()", 1000);
  46.  
  47. });
  48.  
  49. function delayedPost()
  50. {
  51. $.post("http://localhost:9999/dev", "", function(data, status)
  52. {
  53. //$("#output").empty();
  54. $("#output").prepend(data);
  55. });
  56.  
  57. $.post("http://localhost:9999/v1", "", function(data, status) {
  58. //$("#output").empty();
  59. $("#v1").prepend(data);
  60. });
  61.  
  62. $.post("http://localhost:9999/v2", "", function(data, status) {
  63. //$("#output").empty();
  64. $("#v2").prepend(data);
  65. });
  66. }
  67.  
  68. function delayedPost1()
  69. {
  70. $.post("http://localhost:9999/dev", "", function(data, status)
  71. {
  72. $("#output").prepend(data);
  73. });
  74.  
  75. $.post("http://localhost:9999/v1", "", function(data, status)
  76. {
  77. $("#v1").prepend(data);
  78. });
  79.  
  80. $.post("http://localhost:9999/v3", "", function(data, status)
  81. {
  82. $("#v2").prepend(data);
  83. });
  84. }
  85.  
  86. function changeUrl()
  87. {
  88. alert('salom');
  89. clearInterval(myDelay);
  90.  
  91. window.location.replace("http://beta.biotrack.uz");
  92.  
  93. }
  94.  
  95. </script>
  96. </body>
  97. </html>`
  98.  
  99. // handler for the main page.
  100. func handler(w http.ResponseWriter, r *http.Request) {
  101. fmt.Fprint(w, page)
  102. }
  103.  
  104. // handler to cater AJAX requests
  105. func handlerDevs(w http.ResponseWriter, r *http.Request) {
  106. //fmt.Fprint(w, time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST"))
  107. fmt.Fprint(w, "<font color=red>Dev1<br></font>")
  108. }
  109.  
  110. func handlerV1(w http.ResponseWriter, r *http.Request) {
  111. //fmt.Fprint(w, time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST"))
  112. fmt.Fprint(w, "<font color=blue>Vertical1<br></font>")
  113. }
  114.  
  115. func handlerV2(w http.ResponseWriter, r *http.Request) {
  116. //fmt.Fprint(w, time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST"))
  117. fmt.Fprint(w, "<font color=green>Vertical2<br></font>")
  118. }
  119.  
  120. func main() {
  121. http.HandleFunc("/", handler)
  122. http.HandleFunc("/dev", handlerDevs)
  123. http.HandleFunc("/v1", handlerV1)
  124. http.HandleFunc("/v2", handlerV2)
  125. log.Fatal(http.ListenAndServe(":9999", nil))
  126. http.HandleFunc("/jquery.min.js", SendJqueryJs)
  127. panic(http.ListenAndServe(":8081", nil))
  128. }
  129. func SendJqueryJs(w http.ResponseWriter, r *http.Request) {
  130. data, err := ioutil.ReadFile("jquery.min.js")
  131. if err != nil {
  132. http.Error(w, "Couldn't read file", http.StatusInternalServerError)
  133. return
  134. }
  135. w.Header().Set("Content-Type", "application/javascript")
  136. w.Write(data)
  137. }
  138.  
  139. func SendJqueryJs(w http.ResponseWriter, r *http.Request) {
  140. data, err := ioutil.ReadFile("jquery.min.js")
  141. if err != nil {
  142. http.Error(w, "Couldn't read file", http.StatusInternalServerError)
  143. return
  144. }
  145. w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
  146. w.Write(data)
  147. }
  148.  
  149. func main() {
  150. http.HandleFunc("/jquery.min.js", SendJqueryJs)
  151. panic(http.ListenAndServe(":8081", nil))
  152. }
  153.  
  154. http://localhost:8081/jquery.min.js
  155.  
  156. func SendJqueryJs(w http.ResponseWriter, r *http.Request) {
  157. http.ServeFile(w, r, "jquery.min.js")
  158. }
  159.  
  160. http.Handle("/tmpfiles/",
  161. http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
  162.  
  163. <script type="text/javascript" src="/tmpfiles/jquery.min.js">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement