github.com/lastbackend/toolkit@v0.0.0-20241020043710-cafa37b95aad/pkg/runtime/controller/service.go (about)

     1  package controller
     2  
     3  import (
     4  	"context"
     5  	"github.com/lastbackend/toolkit"
     6  	"github.com/lastbackend/toolkit/pkg/runtime"
     7  	"github.com/lastbackend/toolkit/pkg/runtime/logger"
     8  	"github.com/lastbackend/toolkit/pkg/runtime/meta"
     9  )
    10  
    11  type service struct {
    12  	toolkit.Service
    13  	runtime runtime.Runtime
    14  	start   func(ctx context.Context, invoke ...interface{}) error
    15  }
    16  
    17  func (s *service) Meta() *meta.Meta {
    18  	return s.runtime.Meta()
    19  }
    20  
    21  func (s *service) Log() logger.Logger {
    22  	return s.runtime.Log()
    23  }
    24  
    25  func (s *service) Client() toolkit.Client {
    26  	return s.runtime.Client()
    27  }
    28  
    29  func (s *service) Server() toolkit.Server {
    30  	return s.runtime.Server()
    31  }
    32  
    33  func (s *service) RegisterConfig(items ...any) error {
    34  	return s.runtime.Config().Provide(items...)
    35  }
    36  
    37  func (s *service) RegisterPackage(items ...any) {
    38  	s.runtime.Package().Provide(items...)
    39  }
    40  
    41  func (s *service) RegisterPlugin(items ...any) {
    42  	s.runtime.Plugin().Provide(items...)
    43  }
    44  
    45  func (s *service) Start(ctx context.Context) error {
    46  	return s.runtime.Start(ctx)
    47  }
    48  
    49  func (s *service) Stop(ctx context.Context, err error) {
    50  	s.runtime.Stop(ctx, err)
    51  }
    52  
    53  func (s *service) RegisterOnStartHook(fn ...func(ctx context.Context) error) {
    54  	s.runtime.RegisterOnStartHook(fn...)
    55  }
    56  
    57  func (s *service) RegisterOnStopHook(fn ...func(ctx context.Context) error) {
    58  	s.runtime.RegisterOnStopHook(fn...)
    59  }
    60  
    61  func (s *service) RegisterOnStartSyncHook(fn ...func(ctx context.Context) error) {
    62  	s.runtime.RegisterOnStartSyncHook(fn...)
    63  }
    64  
    65  func (s *service) RegisterOnStopSyncHook(fn ...func(ctx context.Context) error) {
    66  	s.runtime.RegisterOnStopSyncHook(fn...)
    67  }