Procházet zdrojové kódy

go/links lists go links

Dan McKinley před 8 roky
rodič
revize
f8d9d816d2
4 změnil soubory, kde provedl 86 přidání a 14 odebrání
  1. 26 4
      pub/index.css
  2. 30 0
      pub/links.html
  3. 11 10
      web/bindata.go
  4. 19 0
      web/web.go

+ 26 - 4
pub/index.css

@@ -63,17 +63,20 @@ form {
   color: #999;
 }
 
-#cmp > a {
+#cmp > a, .links a {
   color: #09f;
   text-decoration: none;
 }
 
-#cmp > .hnt {
-  float: right;
+#cmp > .hnt, .links .full-url {
   color: #ddd;
   text-shadow: 1px 1px 0 #fff;
 }
 
+#cmp > .hnt {
+  float: right;
+}
+
 #cls {
   position: absolute;
   top: 0;
@@ -89,6 +92,25 @@ form {
   display: none;
 }
 
-#cls:hover {
+#cls:hover, .links a:hover {
   opacity: 0.6;
 }
+
+.links {
+  width: 800px;
+  margin: 0 auto;
+}
+
+.links h1 {
+  color: #333;
+  margin-bottom: 40px;
+}
+
+.links ul {
+  padding: 0;
+  list-style-type: none;
+}
+
+.links ul li {
+  margin-bottom: 20px;
+}

+ 30 - 0
pub/links.html

@@ -0,0 +1,30 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>Go :: Active Links</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+    <link href="/s/index.css"
+        rel="stylesheet"
+        type="text/css">
+    <link href="http://fonts.googleapis.com/css?family=Raleway:400,300"
+        rel="stylesheet"
+        type="text/css">
+  </head>
+  <body>
+
+    <div class="links">
+      <h1>Active links</h1>
+      <ul>
+        {{ range $key, $route := . }}
+        <li>
+          <a href="{{ $route.URL }}">go/{{ $key }}</a><br />
+          <a href="{{ $route.URL }}" class="full-url">{{ $route.URL }}</a>
+        </li>
+        {{ end }}
+      </ul>
+    </div>
+
+    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
+    <script src="/s/index.js"></script>
+  </body>
+</html>

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 11 - 10
web/bindata.go


+ 19 - 0
web/web.go

@@ -3,6 +3,7 @@ package web
 import (
 	"bytes"
 	"fmt"
+	"html/template"
 	"log"
 	"net/http"
 
@@ -52,6 +53,23 @@ func getDefault(ctx *context.Context, w http.ResponseWriter, r *http.Request) {
 
 }
 
+type listLinksHandler struct {
+	ctx *context.Context
+}
+
+func (h *listLinksHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+	t := template.New("links")
+	contents, _ := linksHtmlBytes()
+	t, err := t.Parse(string(contents))
+	if err != nil {
+		log.Printf("no template")
+		return
+	}
+
+	routes, _ := h.ctx.GetAll()
+	t.Execute(w, routes)
+}
+
 // ListenAndServe sets up all web routes, binds the port and handles incoming
 // web requests.
 func ListenAndServe(addr string, admin bool, version string, ctx *context.Context) error {
@@ -69,6 +87,7 @@ func ListenAndServe(addr string, admin bool, version string, ctx *context.Contex
 	mux.HandleFunc("/edit/", func(w http.ResponseWriter, r *http.Request) {
 		serveAsset(w, r, "index.html")
 	})
+	mux.Handle("/links", &listLinksHandler{ctx})
 	mux.HandleFunc("/s/", func(w http.ResponseWriter, r *http.Request) {
 		serveAsset(w, r, r.URL.Path[len("/s/"):])
 	})

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů