Files
2023-12-26 10:46:42 +08:00

58 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
stdhttp "net/http"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/transport/http"
"github.com/quarkcloudio/quark-go/v2/pkg/adapter/kratosadapter"
"github.com/quarkcloudio/quark-go/v2/pkg/app/admin/install"
"github.com/quarkcloudio/quark-go/v2/pkg/app/admin/middleware"
"github.com/quarkcloudio/quark-go/v2/pkg/app/admin/service"
"github.com/quarkcloudio/quark-go/v2/pkg/builder"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func main() {
hs := http.NewServer(
http.Address(":3000"),
)
// 数据库配置信息
dsn := "root:fK7xPGJi1gJfIief@tcp(127.0.0.1:3306)/quarkgo?charset=utf8&parseTime=True&loc=Local"
// 配置资源
config := &builder.Config{
AppKey: "123456",
Providers: service.Providers,
DBConfig: &builder.DBConfig{
Dialector: mysql.Open(dsn),
Opts: &gorm.Config{},
},
}
// 创建对象
b := builder.New(config)
// 初始化安装
install.Handle()
// 中间件
b.Use(middleware.Handle)
// 适配kratos
kratosadapter.Adapter(b, hs)
// WEB根目录只能放在后面否则与其他路由有冲突
hs.HandlePrefix("/", stdhttp.FileServer(stdhttp.Dir("./web/app")))
// 创建服务
app := kratos.New(
kratos.Server(hs),
)
// 启动服务
app.Run()
}