github.com/pbberlin/tools@v0.0.0-20160910141205-7aa5421c2169/appengine/backend/backend.go (about) 1 // Package backend ties together 2 // the visual controls and utils. 3 package backend 4 5 import ( 6 "bytes" 7 "fmt" 8 "io" 9 "net/http" 10 11 "github.com/pbberlin/tools/appengine/login" 12 "github.com/pbberlin/tools/net/http/coinbase" 13 "github.com/pbberlin/tools/net/http/dedup" 14 "github.com/pbberlin/tools/net/http/htmlfrag" 15 "github.com/pbberlin/tools/net/http/loghttp" 16 "github.com/pbberlin/tools/net/http/repo" 17 "github.com/pbberlin/tools/net/http/routes" 18 "github.com/pbberlin/tools/net/http/tplx" 19 "github.com/pbberlin/tools/net/http/upload" 20 // _ "github.com/pbberlin/tools/os/fsi/dsfs" 21 "github.com/pbberlin/tools/os/fsi/webapi" 22 "github.com/pbberlin/tools/stringspb" 23 "github.com/pbberlin/tools/util" 24 ) 25 26 var pf func(format string, a ...interface{}) (int, error) = fmt.Printf 27 var pfRestore func(format string, a ...interface{}) (int, error) = fmt.Printf 28 var spf func(format string, a ...interface{}) string = fmt.Sprintf 29 var wpf func(w io.Writer, format string, a ...interface{}) (int, error) = fmt.Fprintf 30 31 func init() { 32 upload.InitHandlers() 33 webapi.InitHandlers() 34 repo.InitHandlers() 35 dedup.InitHandlers() 36 coinbase.InitHandlers() 37 tplx.InitHandlers() 38 login.InitHandlers() 39 40 } 41 42 func backend(w http.ResponseWriter, r *http.Request, m map[string]interface{}) { 43 44 w.Header().Set("Content-type", "text/html; charset=utf-8") 45 w.WriteHeader(http.StatusOK) 46 47 if ok, _, msg := login.CheckForAdminUser(r); !ok { 48 w.Write([]byte(msg)) 49 return 50 } 51 52 b1 := new(bytes.Buffer) 53 b1.WriteString(tplx.ExecTplHelper(tplx.Head, map[string]interface{}{"HtmlTitle": "Backend V1"})) 54 55 htmlfrag.Wb(b1, "Debug pprof", "/debug/pprof") 56 57 htmlfrag.Wb(b1, "Diverse", "nobr") 58 htmlfrag.Wb(b1, "Schreib-Methoden", "/write-methods") 59 htmlfrag.Wb(b1, "Letzte Email", "/email-view") 60 htmlfrag.Wb(b1, "Blob List", "/blob2") 61 62 htmlfrag.Wb(b1, "fetch via proxy", routes.ProxifyURI) 63 htmlfrag.Wb(b1, "Instance Info", "/instance-info/view") 64 65 htmlfrag.Wb(b1, "Fulltext put", "/fulltext-search/put") 66 htmlfrag.Wb(b1, "Fulltext get", "/fulltext-search/get") 67 68 htmlfrag.Wb(b1, "datastore object view quoted printabe", "/dsu/show") 69 70 htmlfrag.Wb(b1, "Statistics", "/_ah/stats") 71 72 htmlfrag.Wb(b1, "Request Images ", "") 73 htmlfrag.Wb(b1, "WrapBlob from Datastore", "/image/img-from-datastore?p=chart1") 74 htmlfrag.Wb(b1, "base64 from Datastore", "/image/base64-from-datastore?p=chart1") 75 htmlfrag.Wb(b1, "base64 from Variable", "/image/base64-from-var?p=1") 76 htmlfrag.Wb(b1, "base64 from File", "/image/base64-from-file?p=static/pberg1.png") 77 htmlfrag.Wb(b1, "Drawing a static chart", "/image/draw-lines-example") 78 79 htmlfrag.Wb(b1, "Big Query ...", "") 80 htmlfrag.Wb(b1, "Get real data", "/big-query/query-into-datastore") 81 htmlfrag.Wb(b1, "Get mocked data", "/big-query/mock-data-into-datastore") 82 htmlfrag.Wb(b1, " ... with Chart", "") 83 htmlfrag.Wb(b1, "Process Data 1 (mock=1)", "/big-query/regroup-data-01?mock=0") 84 htmlfrag.Wb(b1, "Process Data 2", "/big-query/regroup-data-02?f=table") 85 htmlfrag.Wb(b1, "Show as Table", "/big-query/show-table") 86 htmlfrag.Wb(b1, "Show as Chart", "/big-query/show-chart") 87 htmlfrag.Wb(b1, "As HTML", "/big-query/html") 88 89 htmlfrag.Wb(b1, "Namespaces + Task Queues", "") 90 htmlfrag.Wb(b1, "Increment", "/namespaced-counters/increment") 91 htmlfrag.Wb(b1, "Read", "/namespaced-counters/read") 92 htmlfrag.Wb(b1, "Push to task-queue", "/namespaced-counters/queue-push") 93 94 htmlfrag.Wb(b1, "URLs with/without ancestors", "nobr") 95 htmlfrag.Wb(b1, "Backend", "/save-url/backend") 96 97 htmlfrag.Wb(b1, "Guest Book", "") 98 htmlfrag.Wb(b1, "Eintrag hinzufügen", "/guest-entry") 99 htmlfrag.Wb(b1, "Einträge auflisten", "/guest-view") 100 htmlfrag.Wb(b1, "Einträge auflisten - paged - serialized cursor", "/guest-view-cursor") 101 102 b1.WriteString("<hr>\n") 103 104 uiDsFs := webapi.BackendUIRendered() 105 b1.Write(uiDsFs.Bytes()) 106 107 b1.WriteString("<hr>\n") 108 109 b1.Write(upload.BackendUIRendered().Bytes()) 110 111 b1.Write(repo.BackendUIRendered().Bytes()) 112 113 b1.Write(dedup.BackendUIRendered().Bytes()) 114 115 b1.Write(coinbase.BackendUIRendered().Bytes()) 116 117 b1.Write(tplx.BackendUIRendered().Bytes()) 118 119 b1.Write(login.BackendUIRendered().Bytes()) 120 121 b1.WriteString("<br>\n") 122 b1.WriteString("<hr>\n") 123 124 urlLocalAdmin := fmt.Sprintf("http://localhost:%v/mail", routes.DevAdminPort()) 125 ancLocalAdmin := fmt.Sprintf(" <a target='_gae' href='%v' >local app console</a><br>\n", urlLocalAdmin) 126 b1.WriteString(ancLocalAdmin) 127 128 urlConsole := fmt.Sprintf("https://console.developers.google.com/project/%v", routes.AppID()) 129 ancConsole := fmt.Sprintf("<a target='_gae' href='%v' ><b>global</b> developer console</a>\n", urlConsole) 130 b1.WriteString(ancConsole) 131 132 urlOldAdmin := fmt.Sprintf("https://appengine.google.com/settings?&app_id=s~%v", routes.AppID()) 133 ancOldAdmin := fmt.Sprintf(" <a target='_gae' href='%v' >old admin UI</a><br>\n ", urlOldAdmin) 134 b1.WriteString(ancOldAdmin) 135 136 b1.WriteString(` <a target='_gae' 137 href='http://go-lint.appspot.com/github.com/pbberlin/tools/dsu' 138 >lint a package</a><br>`) 139 140 dir := m["dir"].(string) 141 base := m["base"].(string) 142 b1.WriteString("<br>\n") 143 b1.WriteString("Dir: --" + dir + "-- Base: --" + base + "-- <br>\n") 144 145 b1.WriteString("<br>\n") 146 s := fmt.Sprintf("IntegerSequenes a, b: %v %v %v<br>\n", util.MyIntSeq01(), util.MyIntSeq01(), util.MyIntSeq02()) 147 b1.WriteString(s) 148 149 // b1.WriteString("<br>\n") 150 // b1.WriteString(fmt.Sprintf("Temp dir is %s<br>\n", os.TempDir())) 151 152 b1.WriteString("<br>\n") 153 154 io.WriteString(b1, "Date: "+util.TimeMarker()+" - ") 155 b1.WriteString(fmt.Sprintf("Last Month %q - 24 Months ago is %q<br>\n", util.MonthsBack(0), 156 util.MonthsBack(24))) 157 158 b1.WriteString("<br>\n") 159 x1 := " z" + stringspb.IncrementString("--z") 160 x2 := " Z" + stringspb.IncrementString("--Z") 161 x3 := " 9" + stringspb.IncrementString("--9") 162 x4 := stringspb.IncrementString(" --Peter") 163 sEnc := "Łódź < " + stringspb.IncrementString("Łódź") + x1 + x2 + x3 + x4 164 b1.WriteString(fmt.Sprint(string([]byte(sEnc)), "<br>")) 165 166 b1.WriteString(tplx.Foot) 167 168 w.Write(b1.Bytes()) 169 170 } 171 172 func init() { 173 http.HandleFunc("/backend", loghttp.Adapter(backend)) 174 }