Fetch the repository succeeded.
This action will force synchronization from WuKongDev/WuKongIM, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
package server
import (
"fmt"
"io/fs"
"net/http"
"strings"
"github.com/WuKongIM/WuKongIM/pkg/wkhttp"
"github.com/WuKongIM/WuKongIM/pkg/wklog"
"github.com/WuKongIM/WuKongIM/version"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type DemoServer struct {
r *wkhttp.WKHttp
addr string
s *Server
wklog.Log
}
// NewDemoServer new一个demo server
func NewDemoServer(s *Server) *DemoServer {
r := wkhttp.New()
r.Use(wkhttp.CORSMiddleware())
ds := &DemoServer{
r: r,
addr: s.opts.Demo.Addr,
s: s,
Log: wklog.NewWKLog("DemoServer"),
}
return ds
}
// Start 开始
func (s *DemoServer) Start() {
s.r.GetGinRoute().Use(gzip.Gzip(gzip.DefaultCompression))
st, _ := fs.Sub(version.DemoFs, "demo/chatdemo/dist")
s.r.GetGinRoute().NoRoute(func(c *gin.Context) {
if c.Request.URL.Path == "" || c.Request.URL.Path == "/" {
c.Redirect(http.StatusFound, fmt.Sprintf("/chatdemo?apiurl=%s", s.s.opts.External.APIUrl))
c.Abort()
return
}
if strings.HasPrefix(c.Request.URL.Path, "/chatdemo") {
c.FileFromFS("./", http.FS(st))
return
}
})
s.r.GetGinRoute().StaticFS("/chatdemo", http.FS(st))
s.setRoutes()
go func() {
err := s.r.Run(s.addr) // listen and serve
if err != nil {
panic(err)
}
}()
s.Info("Demo server started", zap.String("addr", s.addr))
_, port := parseAddr(s.addr)
s.Info(fmt.Sprintf("Chat demo address: http://localhost:%d/chatdemo", port))
}
// Stop 停止服务
func (s *DemoServer) Stop() {
}
func (s *DemoServer) setRoutes() {
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。