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后台运维服务|
|`SpaceX` | 子服务 | WIP | 开启SpaceX服务|
|`Bot` | 子服务 | WIP | 开启Bot服务|
|`NativeOBS` | 子服务 | WIP | 开启NativeOBS服务|
|`Docs` | 子服务 | WIP | 开启开发者文档服务|
|`Frontend:Web` | 子服务 | 内测 | 开启独立前端服务|
|`Frontend:EmbedWeb` | 子服务 | 内测 | 开启内嵌于后端Web API服务中的前端服务|
|`Deprecated:Web` | 子服务 | 稳定 | 开启旧的Web服务|
|`Gorm` | 数据库 | 稳定(默认) | 使用[gorm](https://github.com/go-gorm/gorm)作为数据库的ORM默认使用 `Gorm` + `MySQL`组合|
|`Sqlx`| 数据库 | WIP | 使用[sqlx](https://github.com/jmoiron/sqlx)作为数据库的ORM|

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

@ -11,8 +11,8 @@
* `Web` 开启Web服务(目前状态: WIP)
* [ ] 提按文档
* [x] 服务初始化逻辑
* [ ] 接口定义
* [ ] 业务逻辑实现
* [x] 接口定义
* [x] 业务逻辑实现
* `Admin` 开启Admin后台运维服务(目前状态: WIP)
* [ ] 提按文档
* [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] 服务初始化逻辑

@ -29,6 +29,7 @@ var (
SpaceXServerSetting *HttpServerSettingS
BotServerSetting *HttpServerSettingS
LocalossServerSetting *HttpServerSettingS
FrontendWebSetting *HttpServerSettingS
DocsServerSetting *HttpServerSettingS
MobileServerSetting *GRPCServerSettingS
AppSetting *AppSettingS
@ -65,40 +66,41 @@ func setupSetting(suite []string, noDefault bool) error {
}
objects := map[string]any{
"App": &AppSetting,
"Server": &ServerSetting,
"WebServer": &WebServerSetting,
"AdminServer": &AdminServerSetting,
"SpaceXServer": &SpaceXServerSetting,
"BotServer": &BotServerSetting,
"LocalossServer": &LocalossServerSetting,
"DocsServer": &DocsServerSetting,
"MobileServer": &MobileServerSetting,
"CacheIndex": &CacheIndexSetting,
"SimpleCacheIndex": &SimpleCacheIndexSetting,
"BigCacheIndex": &BigCacheIndexSetting,
"Alipay": &AlipaySetting,
"SmsJuhe": &SmsJuheSetting,
"Logger": &loggerSetting,
"LoggerFile": &loggerFileSetting,
"LoggerZinc": &loggerZincSetting,
"LoggerMeili": &loggerMeiliSetting,
"Database": &DatabaseSetting,
"MySQL": &MysqlSetting,
"Postgres": &PostgresSetting,
"Sqlite3": &Sqlite3Setting,
"TweetSearch": &TweetSearchSetting,
"Zinc": &ZincSetting,
"Meili": &MeiliSetting,
"Redis": &redisSetting,
"JWT": &JWTSetting,
"ObjectStorage": &ObjectStorage,
"AliOSS": &AliOSSSetting,
"COS": &COSSetting,
"HuaweiOBS": &HuaweiOBSSetting,
"MinIO": &MinIOSetting,
"LocalOSS": &LocalOSSSetting,
"S3": &S3Setting,
"App": &AppSetting,
"Server": &ServerSetting,
"WebServer": &WebServerSetting,
"AdminServer": &AdminServerSetting,
"SpaceXServer": &SpaceXServerSetting,
"BotServer": &BotServerSetting,
"LocalossServer": &LocalossServerSetting,
"FrontendWebServer": &FrontendWebSetting,
"DocsServer": &DocsServerSetting,
"MobileServer": &MobileServerSetting,
"CacheIndex": &CacheIndexSetting,
"SimpleCacheIndex": &SimpleCacheIndexSetting,
"BigCacheIndex": &BigCacheIndexSetting,
"Alipay": &AlipaySetting,
"SmsJuhe": &SmsJuheSetting,
"Logger": &loggerSetting,
"LoggerFile": &loggerFileSetting,
"LoggerZinc": &loggerZincSetting,
"LoggerMeili": &loggerMeiliSetting,
"Database": &DatabaseSetting,
"MySQL": &MysqlSetting,
"Postgres": &PostgresSetting,
"Sqlite3": &Sqlite3Setting,
"TweetSearch": &TweetSearchSetting,
"Zinc": &ZincSetting,
"Meili": &MeiliSetting,
"Redis": &redisSetting,
"JWT": &JWTSetting,
"ObjectStorage": &ObjectStorage,
"AliOSS": &AliOSSSetting,
"COS": &COSSetting,
"HuaweiOBS": &HuaweiOBSSetting,
"MinIO": &MinIOSetting,
"LocalOSS": &LocalOSSSetting,
"S3": &S3Setting,
}
if err = setting.Unmarshal(objects); err != nil {
return err

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

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

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

@ -14,12 +14,12 @@ import (
"github.com/rocboss/paopao-ce/web"
)
// RegisterStatick register static assets route
func RegisterStatick(e *gin.Engine) {
routeStatic(e, "/", "/index.html", "/favicon.ico", "/assets/*filepath")
// RegisterWebStatick register web static assets route
func RegisterWebStatick(e *gin.Engine) {
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())
handler := func(c *gin.Context) {
staticHandler.ServeHTTP(c.Writer, c.Request)

@ -119,15 +119,15 @@ func NewRouter() *gin.Engine {
}
func RegisterRoute(e *gin.Engine) {
// 按需注册 docs、静态资源、LocalOSS 路由
{
registerDocs(e)
// 按需注册 Web前端静态资源
cfg.Be("Frontend:EmbedWeb", func() {
registerStatick(e)
})
cfg.Be("LocalOSS", func() {
routeLocalOSS(e)
})
}
// 按需注册 LocalOSS 路由
cfg.Be("LocalOSS", func() {
routeLocalOSS(e)
})
// v1 group api
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) {
// add all service if declared in features on config.yaml
cfg.In(cfg.Actions{
"Deprecated:OldWeb": func() {
ss = append(ss, newOldWebService())
},
"Web": func() {
ss = append(ss, newWebService())
},
@ -81,6 +78,15 @@ func newService() (ss []Service) {
"Mobile": func() {
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
}

Loading…
Cancel
Save