-
Notifications
You must be signed in to change notification settings - Fork 50
/
main.go
109 lines (92 loc) · 3.07 KB
/
main.go
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
/*package main
import(
"github.com/leeli73/goFileView/perview"
)
func main() {
perview.Init("/perview/","0.0.0.0:8089")
perview.StartServer()
}*/
package main
import (
"net/http"
"github.com/leeli73/goFileView/perview"
)
func index(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<!DOCTYPE html>
<html>
<head>
<title>goFileView测试服务</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>goFileView</h2>
<p>测试的预览服务</p>
<table class="table">
<thead>
<tr>
<th>文件名</th>
<th>文件类型</th>
<th>调用接口</th>
<th>预览</th>
</tr>
</thead>
<tbody>
<tr>
<td>test.docx</td>
<td>docx</td>
<td>http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.docx</td>
<td>
<a
href="http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.docx">普通预览</a>
<a
href="http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.docx&type=pdf">PDF预览</a>
</td>
</tr>
<tr>
<td>test.xlsx</td>
<td>xlsx</td>
<td>http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.xlsx</td>
<td><a
href="http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.xlsx">普通预览</a>
<a
href="http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.xlsx&type=pdf">PDF预览</a>
</td>
</tr>
<tr>
<td>test.pptx</td>
<td>pptx</td>
<td>http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.pptx</td>
<td><a
href="http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.pptx">普通预览</a>
<a
href="http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.pptx&type=pdf">PDF预览</a>
</td>
</tr>
<tr>
<td>test.pdf</td>
<td>pdf</td>
<td>http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.pdf</td>
<td><a
href="http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.pdf">普通预览</a>
<a
href="http://gofileview.onlinecode.cn/perview/onlinePreview?url=http://onlinecode.cn/test.pdf&type=pdf">PDF预览</a>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>`))
}
func main() {
perview.Init("/perview/", "no") //初始化
http.HandleFunc("/", index)
http.HandleFunc("/perview/", perview.Handle) //绑定到preview的Handle
http.ListenAndServe(":80", nil)
}