optimize web service package initialize

pull/199/head
Michael Li 3 years ago
parent c1f497696c
commit 70b53ffede
No known key found for this signature in database

@ -11,7 +11,6 @@ import (
"time" "time"
"unicode/utf8" "unicode/utf8"
"github.com/alimy/cfg"
"github.com/alimy/mir/v3" "github.com/alimy/mir/v3"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1" api "github.com/rocboss/paopao-ce/auto/api/v1"
@ -34,8 +33,6 @@ var (
_ api.Core = (*coreSrv)(nil) _ api.Core = (*coreSrv)(nil)
_ api.CoreBinding = (*coreBinding)(nil) _ api.CoreBinding = (*coreBinding)(nil)
_ api.CoreRender = (*coreRender)(nil) _ api.CoreRender = (*coreRender)(nil)
_EnablePhoneVerify = cfg.If("Sms")
) )
type coreSrv struct { type coreSrv struct {

@ -5,6 +5,8 @@
package web package web
import ( import (
"sync"
"github.com/alimy/cfg" "github.com/alimy/cfg"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1" api "github.com/rocboss/paopao-ce/auto/api/v1"
@ -15,8 +17,14 @@ import (
"github.com/smartwalle/alipay/v3" "github.com/smartwalle/alipay/v3"
) )
var (
_EnablePhoneVerify bool
_onceInitial sync.Once
)
// RouteWeb register web route // RouteWeb register web route
func RouteWeb(e *gin.Engine) { func RouteWeb(e *gin.Engine) {
initial()
oss := dao.ObjectStorageService() oss := dao.ObjectStorageService()
ds := &base.DaoServant{ ds := &base.DaoServant{
Redis: conf.Redis, Redis: conf.Redis,
@ -66,3 +74,10 @@ func mustAlipayClient() *alipay.Client {
} }
return client return client
} }
// initial do some package lazy initialize for performance
func initial() {
_onceInitial.Do(func() {
_EnablePhoneVerify = cfg.If("Sms")
})
}

Loading…
Cancel
Save