console

  1. import (
  2. "github.com/yoyofx/yoyogo/abstractions"
  3. "github.com/yoyofx/yoyogo/console"
  4. )
  5. func main() {
  6. // -f ./conf/test_conf.yml 指定配置文件 , 默认读取 config_{profile}.yml , -profile [dev,test,prod]
  7. config := abstractions.NewConfigurationBuilder().
  8. AddEnvironment().
  9. AddYamlFile("config").Build()
  10. console.NewHostBuilder().
  11. UseConfiguration(config).
  12. UseStartup(Startup).
  13. Build().
  14. Run()
  15. }

Startup

  1. import (
  2. "github.com/yoyofx/yoyogo/abstractions"
  3. "github.com/yoyofx/yoyogo/abstractions/hosting"
  4. "github.com/yoyofxteam/dependencyinjection"
  5. )
  6. type AppStartup struct {
  7. }
  8. func Startup() abstractions.IStartup {
  9. return &AppStartup{}
  10. }
  11. func (s *AppStartup) ConfigureServices(collection *dependencyinjection.ServiceCollection) {
  12. hosting.AddHostService(collection, NewService)
  13. }
  14. // HostService 用于管理程序生命周期
  15. type Service1 struct {
  16. }
  17. func NewService() *Service1 {
  18. return &Service1{}
  19. }
  20. func (s *Service1) Run() error {
  21. fmt.Println("host service Running")
  22. return nil
  23. }
  24. func (s *Service1) Stop() error {
  25. fmt.Println("host service Stopping")
  26. return nil
  27. }