-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (44 loc) · 1.95 KB
/
main.go
File metadata and controls
51 lines (44 loc) · 1.95 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
package main
import (
// "cloudstorage-server/assets"
cfg "cloudstorage-server/config"
"cloudstorage-server/handler"
"fmt"
"net/http"
)
func main() {
// 静态资源处理
http.Handle("/static/",
http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
// 文件存取接口
http.HandleFunc("/file/upload", handler.HTTPInterceptor(handler.UploadHandler))
http.HandleFunc("/file/upload/suc", handler.HTTPInterceptor(handler.UploadSucHandler))
http.HandleFunc("/file/meta", handler.HTTPInterceptor(handler.GetFileMetaHandler))
http.HandleFunc("/file/query", handler.HTTPInterceptor(handler.FileQueryHandler))
http.HandleFunc("/file/download", handler.HTTPInterceptor(handler.DownloadHandler))
http.HandleFunc("/file/update", handler.HTTPInterceptor(handler.FileMetaUpdateHandler))
http.HandleFunc("/file/delete", handler.HTTPInterceptor(handler.FileDeleteHandler))
// 秒传接口
http.HandleFunc("/file/fastupload", handler.HTTPInterceptor(
handler.TryFastUploadHandler))
http.HandleFunc("/file/downloadurl", handler.HTTPInterceptor(
handler.DownloadURLHandler))
// 分块上传接口
http.HandleFunc("/file/mpupload/init",
handler.HTTPInterceptor(handler.InitialMultipartUploadHandler))
http.HandleFunc("/file/mpupload/uppart",
handler.HTTPInterceptor(handler.UploadPartHandler))
http.HandleFunc("/file/mpupload/complete",
handler.HTTPInterceptor(handler.CompleteUploadHandler))
// 用户相关接口
http.HandleFunc("/", handler.SignInHandler)
http.HandleFunc("/user/signup", handler.SignupHandler)
http.HandleFunc("/user/signin", handler.SignInHandler)
http.HandleFunc("/user/info", handler.HTTPInterceptor(handler.UserInfoHandler))
fmt.Printf("服务启动中,开始监听[%s]...\n", cfg.UploadServiceHost)
// 启动服务并监听端口
err := http.ListenAndServe(cfg.UploadServiceHost, nil)
if err != nil {
fmt.Printf("Failed to start server, err:%s", err.Error())
}
}