optimize web service package initialize

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

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

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

Loading…
Cancel
Save