Browse Source

refactor remove web pacakge

Xiang Li 12 years ago
parent
commit
01bbad31c7
6 changed files with 0 additions and 243 deletions
  1. 0 30
      web/conn.go
  2. 0 28
      web/file2gostring.sh
  3. 0 61
      web/hub.go
  4. 0 4
      web/index.go
  5. 0 70
      web/index.html
  6. 0 50
      web/web.go

+ 0 - 30
web/conn.go

@@ -1,30 +0,0 @@
-package web
-
-import (
-	"code.google.com/p/go.net/websocket"
-)
-
-type connection struct {
-	// The websocket connection.
-	ws *websocket.Conn
-
-	// Buffered channel of outbound messages.
-	send chan string
-}
-
-func (c *connection) writer() {
-	for message := range c.send {
-		err := websocket.Message.Send(c.ws, message)
-		if err != nil {
-			break
-		}
-	}
-	c.ws.Close()
-}
-
-func wsHandler(ws *websocket.Conn) {
-	c := &connection{send: make(chan string, 256), ws: ws}
-	h.register <- c
-	defer func() { h.unregister <- c }()
-	c.writer()
-}

+ 0 - 28
web/file2gostring.sh

@@ -1,28 +0,0 @@
-#!/bin/sh
-
-# this file is copied from doozerd. 
-
-set -e
-
-munge() {
-    printf %s "$1" | tr . _ | tr -d -c '[:alnum:]_'
-}
-
-quote() {
-    sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/$/\\n/' | tr -d '\n'
-}
-
-pkg_path=$1 ; shift
-file=$1     ; shift
-
-pkg=`basename $pkg_path`
-
-printf 'package %s\n' "$pkg"
-printf '\n'
-printf '// This file was generated from %s.\n' "$file"
-printf '\n'
-printf 'var '
-munge "`basename $file`"
-printf ' string = "'
-quote
-printf '"\n'

+ 0 - 61
web/hub.go

@@ -1,61 +0,0 @@
-package web
-
-type hub struct {
-	// status
-	open bool
-
-	// Registered connections.
-	connections map[*connection]bool
-
-	// Inbound messages from the connections.
-	broadcast chan string
-
-	// Register requests from the connections.
-	register chan *connection
-
-	// Unregister requests from connections.
-	unregister chan *connection
-}
-
-var h = hub{
-	open:        false,
-	broadcast:   make(chan string),
-	register:    make(chan *connection),
-	unregister:  make(chan *connection),
-	connections: make(map[*connection]bool),
-}
-
-func Hub() *hub {
-	return &h
-}
-
-func HubOpen() bool {
-	return h.open
-}
-
-func (h *hub) run() {
-	h.open = true
-	for {
-		select {
-		case c := <-h.register:
-			h.connections[c] = true
-		case c := <-h.unregister:
-			delete(h.connections, c)
-			close(c.send)
-		case m := <-h.broadcast:
-			for c := range h.connections {
-				select {
-				case c.send <- m:
-				default:
-					delete(h.connections, c)
-					close(c.send)
-					go c.ws.Close()
-				}
-			}
-		}
-	}
-}
-
-func (h *hub) Send(msg string) {
-	h.broadcast <- msg
-}

File diff suppressed because it is too large
+ 0 - 4
web/index.go


+ 0 - 70
web/index.html

@@ -1,70 +0,0 @@
-<html>
-<head>
-<title>etcd Web Interface</title>
-<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
-<script type="text/javascript">
-    $(function() {
-
-    var conn;
-    var content = $("#content");
-
-    function update(response) {
-        // if set
-        if (response.action == "SET") {
-
-            if (response.expiration > "1970") {
-                t = response.key + "=" + response.value
-                        + "  " + response.expiration
-            } else {
-                t = response.key + "=" + response.value
-            }
-
-            id = response.key.replace(new RegExp("/", 'g'), "\\/");
-
-            if ($("#store_" + id).length == 0) {
-                if (response.expiration > "1970") {
-                    t = response.key + "=" + response.value
-                        + "  " + response.expiration
-                } else {
-                    t = response.key + "=" + response.value
-                }
-
-                var e = $('<div id="store_' + response.key + '"/>')
-                    .text(t)
-                e.appendTo(content)
-            }
-            else {
-
-                $("#store_" + id)
-                    .text(t)
-            }
-        }
-        // if delete
-        else if (response.action == "DELETE") {
-            id = response.key.replace(new RegExp("/", 'g'), "\\/");
-
-            $("#store_" + id).remove()
-        }
-    }
-
-
-    if (window["WebSocket"]) {
-        conn = new WebSocket("ws://{{.Address}}/ws");
-        conn.onclose = function(evt) {
-
-        }
-        conn.onmessage = function(evt) {
-            var response = JSON.parse(evt.data)
-            update(response)
-        }
-    } else {
-        appendLog($("<div><b>Your browser does not support WebSockets.</b></div>"))
-    }
-    });
-</script>
-</head>
-<body>
-    <div id="leader">Leader: {{.Leader}}</div>
-    <div id="content"></div>
-</body>
-</html>

+ 0 - 50
web/web.go

@@ -1,50 +0,0 @@
-package web
-
-import (
-	"code.google.com/p/go.net/websocket"
-	"fmt"
-	"github.com/coreos/go-raft"
-	"html/template"
-	"net/http"
-	"net/url"
-)
-
-var mainTempl *template.Template
-var mainPage *MainPage
-
-type MainPage struct {
-	Leader  string
-	Address string
-}
-
-func mainHandler(c http.ResponseWriter, req *http.Request) {
-	p := mainPage
-
-	mainTempl.Execute(c, p)
-}
-
-func Start(raftServer raft.Server, webURL string) {
-	u, _ := url.Parse(webURL)
-
-	webMux := http.NewServeMux()
-
-	server := &http.Server{
-		Handler: webMux,
-		Addr:    u.Host,
-	}
-
-	mainPage = &MainPage{
-		Leader:  raftServer.Leader(),
-		Address: u.Host,
-	}
-
-	mainTempl = template.Must(template.New("index.html").Parse(index_html))
-
-	go h.run()
-	webMux.HandleFunc("/", mainHandler)
-	webMux.Handle("/ws", websocket.Handler(wsHandler))
-
-	fmt.Printf("etcd web server [%s] listening on %s\n", raftServer.Name(), u)
-
-	server.ListenAndServe()
-}

Some files were not shown because too many files changed in this diff