deving
This commit is contained in:
26
internal/config/config.go
Normal file
26
internal/config/config.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
)
|
||||
|
||||
var (
|
||||
Spec SrvConfig
|
||||
)
|
||||
|
||||
type SrvConfig struct {
|
||||
conf.Base `yaml:",inline"`
|
||||
BsmEndpoint string `yaml:"BsmEndpoint"`
|
||||
Databases *conf.DBConf `yaml:"Databases"`
|
||||
}
|
||||
|
||||
func New(srvKey string) {
|
||||
// 初始化配置 创建一个新的配置实例,用于服务配置
|
||||
conf.New(srvKey, &Spec)
|
||||
|
||||
// 配置校验 服务端口如果不合规,则随机分配端口
|
||||
Spec.Port = conf.CheckPort(Spec.Port)
|
||||
|
||||
// 配置校验 服务名称地址及监听地址不能为空
|
||||
conf.NotNil(Spec.Service, Spec.Cache)
|
||||
}
|
||||
24
internal/impl/impl.go
Normal file
24
internal/impl/impl.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
"git.apinb.com/bsm-sdk/core/with"
|
||||
"git.apinb.com/senlinai/site/internal/config"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
RedisService *redis.RedisClient
|
||||
DBService *gorm.DB
|
||||
MemoryService *cache.Cache
|
||||
)
|
||||
|
||||
func NewImpl() {
|
||||
// with activating
|
||||
MemoryService = cache.New(5*time.Minute, 10*time.Minute)
|
||||
RedisService = with.RedisCache(config.Spec.Cache) // redis cache
|
||||
DBService = with.Databases(config.Spec.Databases, nil) // model
|
||||
}
|
||||
14
internal/logic/index.go
Normal file
14
internal/logic/index.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Index(c *gin.Context) {
|
||||
data := gin.H{
|
||||
"Title": "Welcome to " + c.Request.Host,
|
||||
"Message": "This is " + c.Request.Host + " index page.",
|
||||
}
|
||||
|
||||
c.HTML(200, "index.html", data)
|
||||
}
|
||||
11
internal/routers/public.go
Normal file
11
internal/routers/public.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Register public 注册路由
|
||||
func Registers_Public(engine *gin.Engine) {
|
||||
//fmt.Println("Register public")
|
||||
|
||||
}
|
||||
13
internal/tmpl/new.go
Normal file
13
internal/tmpl/new.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package tmpl
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func New(app *gin.Engine) {
|
||||
app.Static("/assets", "./res/assets")
|
||||
html := template.Must(template.ParseFiles("file1", "file2"))
|
||||
app.SetHTMLTemplate(html)
|
||||
}
|
||||
Reference in New Issue
Block a user