mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			35 lines
		
	
	
		
			842 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			842 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package starter
 | 
						|
 | 
						|
import (
 | 
						|
	"mayfly-go/base/biz"
 | 
						|
	"mayfly-go/base/config"
 | 
						|
	"mayfly-go/base/ctx"
 | 
						|
	"mayfly-go/base/global"
 | 
						|
	"mayfly-go/server/initialize"
 | 
						|
)
 | 
						|
 | 
						|
func RunWebServer() {
 | 
						|
	// 权限处理器
 | 
						|
	ctx.UseBeforeHandlerInterceptor(ctx.PermissionHandler)
 | 
						|
	// 日志处理器
 | 
						|
	ctx.UseAfterHandlerInterceptor(ctx.LogHandler)
 | 
						|
	// 注册路由
 | 
						|
	web := initialize.InitRouter()
 | 
						|
 | 
						|
	server := config.Conf.Server
 | 
						|
	port := server.GetPort()
 | 
						|
	if app := config.Conf.App; app != nil {
 | 
						|
		global.Log.Infof("%s- Listening and serving HTTP on %s", app.GetAppInfo(), port)
 | 
						|
	} else {
 | 
						|
		global.Log.Infof("Listening and serving HTTP on %s", port)
 | 
						|
	}
 | 
						|
 | 
						|
	var err error
 | 
						|
	if server.Tls != nil && server.Tls.Enable {
 | 
						|
		err = web.RunTLS(port, server.Tls.CertFile, server.Tls.KeyFile)
 | 
						|
	} else {
 | 
						|
		err = web.Run(port)
 | 
						|
	}
 | 
						|
	biz.ErrIsNilAppendErr(err, "服务启动失败: %s")
 | 
						|
}
 |