Browse Source

Update README.md

Volodymyr Tkach 2 years ago
parent
commit
194db78a01
1 changed files with 51 additions and 6 deletions
  1. 51 6
      README.md

+ 51 - 6
README.md

@@ -7,25 +7,70 @@ Different kind of functions for second reusage
 Web server, which can use regular expressions in path. Designed to be simple and for project with API
 Web server, which can use regular expressions in path. Designed to be simple and for project with API
 
 
 ```go
 ```go
-package server
+package base
 
 
 import (
 import (
-    "context"
-    "fmt"
     "net/http"
     "net/http"
     ...
     ...
 )
 )
 
 
-// External package
-type base.Handler struct {
+type Handler struct {
     Ctx      context.Context
     Ctx      context.Context
     DB       *database.DataBase
     DB       *database.DataBase
     Shutdown context.CancelFunc
     Shutdown context.CancelFunc
 }
 }
 
 
-func (h base.Handler) FuncMap(w http.ResponseWriter, r *http.Request) template.FuncMap {
+type ServerData struct {
+    ...
+}
+
+func (h Handler) FuncMap(w http.ResponseWriter, r *http.Request) template.FuncMap {
     return template.FuncMap{}
     return template.FuncMap{}
 }
 }
+```
+
+```go
+package page_index
+
+import (
+    "net/http"
+    ...
+)
+
+type Handler struct {
+    base.Handler
+}
+
+func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+    sess := h.SessionStart(w, r)
+    if sess == nil {
+        return
+    }
+    defer sess.Close()
+
+    // /api/v1/aliases/{i}
+    // apiserv.GetParams(r)[1].Integer()
+
+    // /api/v1/aliases/{s}
+    // apiserv.GetParams(r)[1].String()
+
+    ...
+
+    data := &base.ServerData{}
+
+    if !render.HTML(w, r, h.FuncMap(w, r), data, web.IndexHtml, http.StatusOK) {
+        return
+    }
+}
+```
+
+```go
+package server
+
+import (
+    "net/http"
+    ...
+)
 
 
 func NewMux(ctx context.Context, shutdown context.CancelFunc, db *database.DataBase) *apiserv.ServeMux {
 func NewMux(ctx context.Context, shutdown context.CancelFunc, db *database.DataBase) *apiserv.ServeMux {
     mux := apiserv.NewServeMux()
     mux := apiserv.NewServeMux()