-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdrawCase.go
More file actions
195 lines (129 loc) · 5.48 KB
/
drawCase.go
File metadata and controls
195 lines (129 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package main
import (
//"html/template"
"net/http"
//"time"
"google.golang.org/appengine"
"google.golang.org/appengine/datastore"
//"appengine/user"
)
// Drawing cases has been temporarily moved to drawPageCustomize.go
// ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
func drawCase(r *http.Request) (string) {
output := ""
// ========== ========== ========== ========== ==========
// New Context - opaque value used by many functions in the Go App Engine SDK to communicate with the App Engine service
// [START new_context]
ctx := appengine.NewContext(r) // c or ctx
// [END new_context]
// ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ==========
// [START query]
query := datastore.NewQuery("Case").Ancestor(caseKey(ctx)).Order("-Date").Limit(10)
// [END query]
// ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ==========
// [START getall]
cases := make([]Case, 0, 10)
if _, err := query.GetAll(ctx, &cases); err != nil {
/*
http.Error(w, err.Error(), http.StatusInternalServerError)
return
*/
}
// [END getall]
// ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ==========
/*
if err := guestbookTemplate.Execute(w, greetings); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
*/
// ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ==========
output = `
<a href="/case/1" class="case-block">
<img src="/caseuploads/blankcase1.jpg" />
<span class="name-container">CASENAME</span>
<span class="watt-container"><span class="watts">123</span> Watt BoomCase</span>
<span class="price-container">$<span class="price">1500</span></span>
</a>
`
// ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ==========
// New Context - opaque value used by many functions in the Go App Engine SDK to communicate with the App Engine service
// [START new_context]
//c := appengine.NewContext(r)
// [END new_context]
// ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ==========
// Getting current user
/*
// If the user is already signed in to your application, user.Current returns a pointer to a user.User value. Otherwise, it returns nil:
if u := user.Current(c); u != nil {
g.Author = u.Email
}
// We set the same parent key on every Greeting entity to ensure each Greeting is in the same entity group.
// Queries across the single entity group will be consistent.
// However, the write rate to a single entity group should be limited to ~1/second.
key := datastore.NewIncompleteKey(c, "Greeting", guestbookKey(c))
_, err := datastore.Put(c, key, &g)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/", http.StatusFound)
*/
// ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ==========
// func root
/*
// Ancestor queries, as shown here, are strongly consistent with the High Replication Datastore.
// Queries that span entity groups are eventually consistent.
// If we omitted the .Ancestor from this query there would be a slight chance that Greeting that had just been written would not show up in a query.
// The following code constructs a Query value that requests the 10 most recent Greeting objects that are descendants of the root guestbook key in Date-descending order
// [START query]
q := datastore.NewQuery("Greeting").Ancestor(guestbookKey(c)).Order("-Date").Limit(10)
// [END query]
// The following code calls q.GetAll(c, &greetings) to run the query and append the results to the greetings slice:
// [START getall]
greetings := make([]Greeting, 0, 10)
if _, err := q.GetAll(c, &greetings); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// [END getall]
if err := guestbookTemplate.Execute(w, greetings); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
*/
// ========== ========== ========== ========== ==========
// ========== ========== ========== ========== ==========
// func sign
/*
g := Greeting{
Content: r.FormValue("content"),
Date: time.Now(),
}
// [START if_user]
if u := user.Current(c); u != nil {
g.Author = u.Email
}
// We set the same parent key on every Greeting entity to ensure each Greeting is in the same entity group.
// Queries across the single entity group will be consistent.
// However, the write rate to a single entity group should be limited to ~1/second.
key := datastore.NewIncompleteKey(c, "Greeting", guestbookKey(c))
_, err := datastore.Put(c, key, &g)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/", http.StatusFound)
// [END if_user]
*/
// ========== ========== ========== ========== ==========
return output
}
// ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========