This repository was archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (49 loc) · 1.31 KB
/
main.go
File metadata and controls
59 lines (49 loc) · 1.31 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
package main
import (
"bytes"
"image/jpeg"
"github.com/aofei/air"
"github.com/aofei/cameron"
)
var a = air.Default
func main() {
a.DebugMode = true
a.GET("/", index)
a.GET("/identicons/:Name", identicon)
a.Serve()
}
func index(req *air.Request, res *air.Response) error {
return res.WriteHTML(`
<!DOCTYPE html>
<html>
<head>
<title>Cameron</title>
<meta name="description" content="Cameron - An avatar generator for Go.">
</head>
<body>
<h1>Cameron - An avatar generator for Go.</h1>
<h2>Identicons</h2>
<ul>
<li><a href="/identicons/Robb Stark">Robb Stark's identicon</a></li>
<li><a href="/identicons/Jon Snow">Jon Snow's identicon</a></li>
<li><a href="/identicons/Sansa Stark">Sansa Stark's identicon</a></li>
<li><a href="/identicons/Arya Stark">Arya Stark's identicon</a></li>
<li><a href="/identicons/Bran Stark">Bran Stark's identicon</a></li>
<li><a href="/identicons/Rickon Stark">Rickon Stark's identicon</a></li>
</ul>
</body>
</html>
`)
}
func identicon(req *air.Request, res *air.Response) error {
buf := bytes.Buffer{}
jpeg.Encode(
&buf,
cameron.Identicon(req.ParamValue("Name").Bytes(), 540, 60),
&jpeg.Options{
Quality: 100,
},
)
res.Header.Set("Content-Type", "image/jpeg")
return res.Write(bytes.NewReader(buf.Bytes()))
}