소스 검색

Web UI: handle home page.

Frederic G. MARAND 5 년 전
부모
커밋
62ebbad56e
4개의 변경된 파일18개의 추가작업 그리고 6개의 파일을 삭제
  1. 0 1
      go.mod
  2. 15 2
      web/get_root.go
  3. 0 2
      web/get_short.go
  4. 3 1
      web/web.go

+ 0 - 1
go.mod

@@ -2,7 +2,6 @@ module code.osinet.fr/fgm/kurz
 
 require (
 	github.com/BurntSushi/toml v0.3.1 // indirect
-	github.com/davecgh/go-spew v1.1.1
 	github.com/go-sql-driver/mysql v1.4.0
 	github.com/gorilla/context v1.1.1 // indirect
 	github.com/gorilla/mux v1.6.2

+ 15 - 2
web/get_root.go

@@ -1,8 +1,21 @@
 package web
 
-import "net/http"
+import (
+	"io"
+	"log"
+	"net/http"
+	"strings"
+)
 
 // handleGetRoot handles path /
 func handleGetRoot(w http.ResponseWriter, r *http.Request) {
-	w.Write([]byte("Hello Kurz"))
+	sw := &strings.Builder{}
+	err := tmpl.ExecuteTemplate(sw, "home", nil)
+	if err != nil {
+		log.Println(err)
+		w.WriteHeader(http.StatusInternalServerError)
+	} else {
+		w.WriteHeader(http.StatusOK)
+		io.Copy(w, strings.NewReader(sw.String()))
+	}
 }

+ 0 - 2
web/get_short.go

@@ -21,8 +21,6 @@ Template variables:
   - SiteName                    PlusVite
 */
 
-type bytes = []byte
-
 func build403(w http.ResponseWriter, short string) {
 	data := struct {
 		FullyQualifiedShortURL string

+ 3 - 1
web/web.go

@@ -124,7 +124,9 @@ To build URLs for assets, use URLForAsset().
   - path: the asset path relative to the project root
 */
 func URLFromRoute(router mux.Router, name string, params map[string]string) string {
-	return ""
+	log.Println(name, params)
+	//url, err := router.Get(name).URL(params
+	return name
 }
 
 /*