-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquery.scm
executable file
·50 lines (43 loc) · 1.41 KB
/
query.scm
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
#!/usr/bin/env gosh
;;
;; Sample of handling GET request
;;
(add-load-path ".." :relative)
(use gauche.threads)
(use gauche.parseopt)
(use srfi-1)
(use makiki)
;; Simple BBS. The app-data contains a list of postings,
;; in ((name timestamp message) ...) format.
(define (main args)
(let-args (cdr args) ([port "p|port=i" 8012])
(start-http-server :access-log #t :error-log #t :port port
:app-data (atom '())))
0)
(define-http-handler "/"
(^[req app]
(let-params req (name
message)
(when (and name message)
(atomic-update! app (cut cons `(,name ,(sys-time) ,message) <>)))
(respond/ok req (atomic app render-wall)))))
(define (render-wall msgs)
(define (render-entry name timestamp message)
`((dt (b ,name) " "
"(",(sys-strftime "%Y/%m/%d %H:%M:%S" (sys-localtime timestamp))")")
(dd ,message)))
`(sxml
(html
(head (title "wall"))
(body
(form (@ (method "GET") (action "/"))
(table (tr (th "Name:")
(td (input (@ (type "text") (name "name")))))
(tr (th "Message:")
(td (textarea (@ (name "message") (cols 60)) "")))
(tr (td)
(td (input (@ (type "submit") (name "s") (value "Write")))))))
(dl ,@(append-map (pa$ apply render-entry) msgs))))))
;; Local variables:
;; mode: scheme
;; end: