add frontend:web / frontend:embedweb / docs service

pull/196/head
Michael Li 2 years ago
parent 275e132927
commit 6576d74f4d
No known key found for this signature in database

@ -316,11 +316,14 @@ release/paopao-ce --no-default-features --features sqlite3,localoss,loggerfile,r
目前支持的功能集合: 目前支持的功能集合:
| 功能项 | 类别 | 状态 | 备注 | | 功能项 | 类别 | 状态 | 备注 |
| ----- | ----- | ----- | ----- | | ----- | ----- | ----- | ----- |
|`Web` | 子服务 | WIP | 开启Web服务| |`Web` | 子服务 | 内测 | 开启Web服务|
|`Admin` | 子服务 | WIP | 开启Admin后台运维服务| |`Admin` | 子服务 | WIP | 开启Admin后台运维服务|
|`SpaceX` | 子服务 | WIP | 开启SpaceX服务| |`SpaceX` | 子服务 | WIP | 开启SpaceX服务|
|`Bot` | 子服务 | WIP | 开启Bot服务| |`Bot` | 子服务 | WIP | 开启Bot服务|
|`NativeOBS` | 子服务 | WIP | 开启NativeOBS服务| |`NativeOBS` | 子服务 | WIP | 开启NativeOBS服务|
|`Docs` | 子服务 | WIP | 开启开发者文档服务|
|`Frontend:Web` | 子服务 | 内测 | 开启独立前端服务|
|`Frontend:EmbedWeb` | 子服务 | 内测 | 开启内嵌于后端Web API服务中的前端服务|
|`Deprecated:Web` | 子服务 | 稳定 | 开启旧的Web服务| |`Deprecated:Web` | 子服务 | 稳定 | 开启旧的Web服务|
|`Gorm` | 数据库 | 稳定(默认) | 使用[gorm](https://github.com/go-gorm/gorm)作为数据库的ORM默认使用 `Gorm` + `MySQL`组合| |`Gorm` | 数据库 | 稳定(默认) | 使用[gorm](https://github.com/go-gorm/gorm)作为数据库的ORM默认使用 `Gorm` + `MySQL`组合|
|`Sqlx`| 数据库 | WIP | 使用[sqlx](https://github.com/jmoiron/sqlx)作为数据库的ORM| |`Sqlx`| 数据库 | WIP | 使用[sqlx](https://github.com/jmoiron/sqlx)作为数据库的ORM|

@ -19,7 +19,7 @@ Features:
Base: ["Redis", "PhoneBind"] Base: ["Redis", "PhoneBind"]
Docs: ["Docs:OpenAPI"] Docs: ["Docs:OpenAPI"]
Deprecated: ["Deprecated:OldWeb"] Deprecated: ["Deprecated:OldWeb"]
Service: ["Web", "Admin", "SpaceX", "Bot", "LocalOSS", "Mobile"] Service: ["Web", "Admin", "SpaceX", "Bot", "LocalOSS", "Mobile", "Frontend:Web", "Fronetend:EmbedWeb", "Docs"]
Option: ["SimpleCacheIndex"] Option: ["SimpleCacheIndex"]
Sms: "SmsJuhe" Sms: "SmsJuhe"
WebServer: # Web服务 WebServer: # Web服务
@ -47,6 +47,11 @@ LocalossServer: # Localoss服务
HttpPort: 8018 HttpPort: 8018
ReadTimeout: 60 ReadTimeout: 60
WriteTimeout: 60 WriteTimeout: 60
FrontendWebServer: # Web前端服务
HttpIp: 0.0.0.0
HttpPort: 8006
ReadTimeout: 60
WriteTimeout: 60
DocsServer: # 开发文档服务 DocsServer: # 开发文档服务
HttpIp: 0.0.0.0 HttpIp: 0.0.0.0
HttpPort: 8011 HttpPort: 8011

@ -11,8 +11,8 @@
* `Web` 开启Web服务(目前状态: WIP) * `Web` 开启Web服务(目前状态: WIP)
* [ ] 提按文档 * [ ] 提按文档
* [x] 服务初始化逻辑 * [x] 服务初始化逻辑
* [ ] 接口定义 * [x] 接口定义
* [ ] 业务逻辑实现 * [x] 业务逻辑实现
* `Admin` 开启Admin后台运维服务(目前状态: WIP) * `Admin` 开启Admin后台运维服务(目前状态: WIP)
* [ ] 提按文档 * [ ] 提按文档
* [x] 服务初始化逻辑 * [x] 服务初始化逻辑
@ -33,7 +33,16 @@
* [ ] 服务初始化逻辑 * [ ] 服务初始化逻辑
* [ ] 接口定义 * [ ] 接口定义
* [ ] 业务逻辑实现 * [ ] 业务逻辑实现
* `Deprecated:OldWeb` Deprecated(关闭)旧的Web服务(目前状态: WIP) * `Docs` 开启NativeOBS服务(目前状态: WIP)
* [ ] 提按文档
* [x] 服务初始化逻辑
* `Frontend:Web` 开启独立前端服务(目前状态: 内测)
* [ ] 提按文档
* [x] 服务初始化逻辑
* `Frontend:EmbedWeb` 开启内嵌于后端Web API服务中的前端服务(目前状态: 内测)
* [ ] 提按文档
* [x] 服务初始化逻辑
* `Deprecated:OldWeb` 开启旧的Web服务(目前状态: 内测)
* [ ] 提按文档 * [ ] 提按文档
* [x] 服务初始化逻辑 * [x] 服务初始化逻辑

@ -29,6 +29,7 @@ var (
SpaceXServerSetting *HttpServerSettingS SpaceXServerSetting *HttpServerSettingS
BotServerSetting *HttpServerSettingS BotServerSetting *HttpServerSettingS
LocalossServerSetting *HttpServerSettingS LocalossServerSetting *HttpServerSettingS
FrontendWebSetting *HttpServerSettingS
DocsServerSetting *HttpServerSettingS DocsServerSetting *HttpServerSettingS
MobileServerSetting *GRPCServerSettingS MobileServerSetting *GRPCServerSettingS
AppSetting *AppSettingS AppSetting *AppSettingS
@ -72,6 +73,7 @@ func setupSetting(suite []string, noDefault bool) error {
"SpaceXServer": &SpaceXServerSetting, "SpaceXServer": &SpaceXServerSetting,
"BotServer": &BotServerSetting, "BotServer": &BotServerSetting,
"LocalossServer": &LocalossServerSetting, "LocalossServer": &LocalossServerSetting,
"FrontendWebServer": &FrontendWebSetting,
"DocsServer": &DocsServerSetting, "DocsServer": &DocsServerSetting,
"MobileServer": &MobileServerSetting, "MobileServer": &MobileServerSetting,
"CacheIndex": &CacheIndexSetting, "CacheIndex": &CacheIndexSetting,

@ -38,6 +38,11 @@ LocalossServer: # Localoss服务
HttpPort: 8018 HttpPort: 8018
ReadTimeout: 60 ReadTimeout: 60
WriteTimeout: 60 WriteTimeout: 60
FrontendWebServer: # Web前端静态资源服务
HttpIp: 0.0.0.0
HttpPort: 8006
ReadTimeout: 60
WriteTimeout: 60
DocsServer: # 开发文档服务 DocsServer: # 开发文档服务
HttpIp: 0.0.0.0 HttpIp: 0.0.0.0
HttpPort: 8011 HttpPort: 8011

@ -20,13 +20,12 @@ import (
// RegisterWebServants register all the servants to gin.Engine // RegisterWebServants register all the servants to gin.Engine
func RegisterWebServants(e *gin.Engine) { func RegisterWebServants(e *gin.Engine) {
docs.RegisterDocs(e) cfg.Be("Frontend:EmbedWeb", func() {
statick.RegisterStatick(e) statick.RegisterWebStatick(e)
})
cfg.Be("LocalOSS", func() { cfg.Be("LocalOSS", func() {
localoss.RouteLocalOSS(e) localoss.RouteLocalOSS(e)
}) })
web.RouteWeb(e) web.RouteWeb(e)
} }
@ -50,6 +49,16 @@ func RegisterLocalossServants(e *gin.Engine) {
localoss.RouteLocaloss(e) localoss.RouteLocaloss(e)
} }
// RegisterDocsServants register all the servants to gin.Engine
func RegisterDocsServants(e *gin.Engine) {
docs.RegisterDocs(e)
}
// RegisterFrontendWebServants register all the servants to gin.Engine
func RegisterFrontendWebServants(e *gin.Engine) {
statick.RegisterWebStatick(e)
}
// RegisterMobileServants register all the servants to grpc.Server // RegisterMobileServants register all the servants to grpc.Server
func RegisterMobileServants(s *grpc.Server) { func RegisterMobileServants(s *grpc.Server) {
mobile.RegisterServants(s) mobile.RegisterServants(s)

@ -11,7 +11,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
// RegisterStatick stub function for register static asset route // RegisterWebStatick stub function for register static asset route
func RegisterStatick(e *gin.Engine) { func RegisterWebStatick(e *gin.Engine) {
// empty // empty
} }

@ -14,12 +14,12 @@ import (
"github.com/rocboss/paopao-ce/web" "github.com/rocboss/paopao-ce/web"
) )
// RegisterStatick register static assets route // RegisterWebStatick register web static assets route
func RegisterStatick(e *gin.Engine) { func RegisterWebStatick(e *gin.Engine) {
routeStatic(e, "/", "/index.html", "/favicon.ico", "/assets/*filepath") routeWebStatic(e, "/", "/index.html", "/favicon.ico", "/assets/*filepath")
} }
func routeStatic(e *gin.Engine, paths ...string) { func routeWebStatic(e *gin.Engine, paths ...string) {
staticHandler := http.FileServer(web.NewFileSystem()) staticHandler := http.FileServer(web.NewFileSystem())
handler := func(c *gin.Context) { handler := func(c *gin.Context) {
staticHandler.ServeHTTP(c.Writer, c.Request) staticHandler.ServeHTTP(c.Writer, c.Request)

@ -119,15 +119,15 @@ func NewRouter() *gin.Engine {
} }
func RegisterRoute(e *gin.Engine) { func RegisterRoute(e *gin.Engine) {
// 按需注册 docs、静态资源、LocalOSS 路由 // 按需注册 Web前端静态资源
{ cfg.Be("Frontend:EmbedWeb", func() {
registerDocs(e)
registerStatick(e) registerStatick(e)
})
// 按需注册 LocalOSS 路由
cfg.Be("LocalOSS", func() { cfg.Be("LocalOSS", func() {
routeLocalOSS(e) routeLocalOSS(e)
}) })
}
// v1 group api // v1 group api
r := e.Group("/v1") r := e.Group("/v1")

@ -0,0 +1,63 @@
// Copyright 2022 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package service
import (
"fmt"
"net/http"
"github.com/Masterminds/semver/v3"
"github.com/fatih/color"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/servants"
)
var (
_ Service = (*docsService)(nil)
)
type docsService struct {
*baseHttpService
}
func (s *docsService) Name() string {
return "DocsService"
}
func (s *docsService) Version() *semver.Version {
return semver.MustParse("v0.1.0")
}
func (s *docsService) OnInit() error {
s.registerRoute(servants.RegisterDocsServants)
return nil
}
func (s *docsService) String() string {
return fmt.Sprintf("listen on %s\n", color.GreenString("http://%s:%s", conf.DocsServerSetting.HttpIp, conf.DocsServerSetting.HttpPort))
}
func newDocsService() Service {
addr := conf.DocsServerSetting.HttpIp + ":" + conf.DocsServerSetting.HttpPort
server := httpServers.from(addr, func() *httpServer {
engine := newWebEngine()
return &httpServer{
baseServer: newBaseServe(),
e: engine,
server: &http.Server{
Addr: addr,
Handler: engine,
ReadTimeout: conf.DocsServerSetting.GetReadTimeout(),
WriteTimeout: conf.DocsServerSetting.GetWriteTimeout(),
MaxHeaderBytes: 1 << 20,
},
}
})
return &docsService{
baseHttpService: &baseHttpService{
server: server,
},
}
}

@ -0,0 +1,63 @@
// Copyright 2022 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package service
import (
"fmt"
"net/http"
"github.com/Masterminds/semver/v3"
"github.com/fatih/color"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/servants"
)
var (
_ Service = (*frontendWebService)(nil)
)
type frontendWebService struct {
*baseHttpService
}
func (s *frontendWebService) Name() string {
return "FrontendWebService"
}
func (s *frontendWebService) Version() *semver.Version {
return semver.MustParse("v0.1.0")
}
func (s *frontendWebService) OnInit() error {
s.registerRoute(servants.RegisterFrontendWebServants)
return nil
}
func (s *frontendWebService) String() string {
return fmt.Sprintf("listen on %s\n", color.GreenString("http://%s:%s", conf.FrontendWebSetting.HttpIp, conf.FrontendWebSetting.HttpPort))
}
func newFrontendWebServiceService() Service {
addr := conf.FrontendWebSetting.HttpIp + ":" + conf.FrontendWebSetting.HttpPort
server := httpServers.from(addr, func() *httpServer {
engine := newWebEngine()
return &httpServer{
baseServer: newBaseServe(),
e: engine,
server: &http.Server{
Addr: addr,
Handler: engine,
ReadTimeout: conf.FrontendWebSetting.GetReadTimeout(),
WriteTimeout: conf.FrontendWebSetting.GetWriteTimeout(),
MaxHeaderBytes: 1 << 20,
},
}
})
return &frontendWebService{
baseHttpService: &baseHttpService{
server: server,
},
}
}

@ -60,9 +60,6 @@ func MaxSidSize(ss []Service) int {
func newService() (ss []Service) { func newService() (ss []Service) {
// add all service if declared in features on config.yaml // add all service if declared in features on config.yaml
cfg.In(cfg.Actions{ cfg.In(cfg.Actions{
"Deprecated:OldWeb": func() {
ss = append(ss, newOldWebService())
},
"Web": func() { "Web": func() {
ss = append(ss, newWebService()) ss = append(ss, newWebService())
}, },
@ -81,6 +78,15 @@ func newService() (ss []Service) {
"Mobile": func() { "Mobile": func() {
ss = append(ss, newMobileService()) ss = append(ss, newMobileService())
}, },
"Frontend:Web": func() {
ss = append(ss, newFrontendWebServiceService())
},
"Docs": func() {
ss = append(ss, newDocsService())
},
"Deprecated:OldWeb": func() {
ss = append(ss, newOldWebService())
},
}) })
return return
} }

Loading…
Cancel
Save