feat: refactor.

This commit is contained in:
tx7do
2024-05-14 16:37:22 +08:00
parent edbcad5973
commit 5e85934e35
3 changed files with 50 additions and 4 deletions

View File

@@ -1,19 +1,57 @@
package bootstrap
import (
"testing"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/registry"
v1 "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
"testing"
"github.com/tx7do/kratos-bootstrap/config"
)
func initApp(logger log.Logger, registrar registry.Registrar, bootstrap *v1.Bootstrap) (*kratos.App, func(), error) {
func initApp(logger log.Logger, registrar registry.Registrar, _ *v1.Bootstrap) (*kratos.App, func(), error) {
app := NewApp(logger, registrar)
return app, func() {
}, nil
}
func TestBootstrap(t *testing.T) {
Bootstrap(initApp)
serviceName := "test"
version := "v0.0.1"
Bootstrap(initApp, &serviceName, &version)
}
type CustomConfig struct {
Cfg string `protobuf:"bytes,1,opt,name=cfg,proto3" json:"cfg,omitempty"`
}
func initAppEx(logger log.Logger, registrar registry.Registrar, _ *v1.Bootstrap, _ *CustomConfig) (*kratos.App, func(), error) {
app := NewApp(logger, registrar)
return app, func() {
}, nil
}
func TestCustomBootstrap(t *testing.T) {
customCfg := &CustomConfig{}
config.RegisterConfig(customCfg)
Service.SetName("test")
Service.SetVersion("v0.0.1")
// bootstrap
cfg, ll, reg := DoBootstrap(Service)
// init app
app, cleanup, err := initAppEx(ll, reg, cfg, customCfg)
if err != nil {
panic(err)
}
defer cleanup()
// run the app.
if err = app.Run(); err != nil {
panic(err)
}
}

View File

@@ -21,6 +21,14 @@ func NewServiceInfo(name, version, id string) *ServiceInfo {
}
}
func (s *ServiceInfo) SetName(name string) {
s.Name = name
}
func (s *ServiceInfo) SetVersion(version string) {
s.Version = version
}
func (s *ServiceInfo) GetInstanceId() string {
return s.Id + "." + s.Name
}

View File

@@ -1,4 +1,4 @@
git tag v0.3.8
git tag v0.3.9
git tag api/v0.0.2 --force