rubbishclass-srv/server.go

53 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"flag"
"net/http"
"os"
"github.com/gin-gonic/gin"
"yyjishu.com/rubbish-class/admin"
"yyjishu.com/rubbish-class/app"
)
var (
endpoint = flag.String("s", "localhost:8080", "service endpoint")
)
func main() {
flag.Parse()
//启动时检查与创建文件夹video用于存放用户上传的视频文件
_, err := os.Stat("video")
if err != nil {
if os.IsNotExist(err) {
os.Mkdir("./video", os.ModePerm)
os.Chmod("./video", 0755)
}
}
r := gin.Default()
r.Use(gin.Recovery())
r.StaticFS(`/video`, http.Dir("./video"))
authorized := r.Group(`/admin`, gin.BasicAuth(gin.Accounts{
"foo": "bar",
"admin": "admin",
}))
{
authorized.GET(`/index`, admin.HomeHandle)
}
appGroup := r.Group(`/app`)
{
appGroup.POST(`/index`, app.Indexhandle)
appGroup.GET(`/code2session/:jscode`, app.Code2SessionHandler)
appGroup.POST(`/upload`, app.UploadHandler)
appGroup.POST(`/uploadvideo`, app.UploadfileAndFormHandler)
appGroup.GET(`/history/:openid`, app.HistoryVideoHandler)
}
r.Run(*endpoint)
}