mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-24 22:26:54 +02:00
Merge branch 'master' into git-secrets
This commit is contained in:
@ -30,11 +30,13 @@ func (s *svc) Init(opts ...runtime.Option) error {
|
||||
|
||||
// Create registers a service in the runtime
|
||||
func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error {
|
||||
options := runtime.CreateOptions{}
|
||||
// apply requested options
|
||||
var options runtime.CreateOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
if options.Context == nil {
|
||||
options.Context = context.Background()
|
||||
}
|
||||
|
||||
// set the default source from MICRO_RUNTIME_SOURCE
|
||||
if len(svc.Source) == 0 {
|
||||
@ -59,15 +61,23 @@ func (s *svc) Create(svc *runtime.Service, opts ...runtime.CreateOption) error {
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := s.runtime.Create(context.Background(), req); err != nil {
|
||||
if _, err := s.runtime.Create(options.Context, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *svc) Logs(service *runtime.Service, options ...runtime.LogsOption) (runtime.LogStream, error) {
|
||||
ls, err := s.runtime.Logs(context.Background(), &pb.LogsRequest{
|
||||
func (s *svc) Logs(service *runtime.Service, opts ...runtime.LogsOption) (runtime.LogStream, error) {
|
||||
var options runtime.LogsOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
if options.Context == nil {
|
||||
options.Context = context.Background()
|
||||
}
|
||||
|
||||
ls, err := s.runtime.Logs(options.Context, &pb.LogsRequest{
|
||||
Service: service.Name,
|
||||
Stream: true,
|
||||
Count: 10, // @todo pass in actual options
|
||||
@ -123,11 +133,13 @@ func (l *serviceLogStream) Stop() error {
|
||||
|
||||
// Read returns the service with the given name from the runtime
|
||||
func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) {
|
||||
options := runtime.ReadOptions{}
|
||||
// apply requested options
|
||||
var options runtime.ReadOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
if options.Context == nil {
|
||||
options.Context = context.Background()
|
||||
}
|
||||
|
||||
// runtime service create request
|
||||
req := &pb.ReadRequest{
|
||||
@ -138,7 +150,7 @@ func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) {
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := s.runtime.Read(context.Background(), req)
|
||||
resp, err := s.runtime.Read(options.Context, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -158,7 +170,15 @@ func (s *svc) Read(opts ...runtime.ReadOption) ([]*runtime.Service, error) {
|
||||
}
|
||||
|
||||
// Update updates the running service
|
||||
func (s *svc) Update(svc *runtime.Service) error {
|
||||
func (s *svc) Update(svc *runtime.Service, opts ...runtime.UpdateOption) error {
|
||||
var options runtime.UpdateOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
if options.Context == nil {
|
||||
options.Context = context.Background()
|
||||
}
|
||||
|
||||
// runtime service create request
|
||||
req := &pb.UpdateRequest{
|
||||
Service: &pb.Service{
|
||||
@ -169,7 +189,7 @@ func (s *svc) Update(svc *runtime.Service) error {
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := s.runtime.Update(context.Background(), req); err != nil {
|
||||
if _, err := s.runtime.Update(options.Context, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -177,7 +197,15 @@ func (s *svc) Update(svc *runtime.Service) error {
|
||||
}
|
||||
|
||||
// Delete stops and removes the service from the runtime
|
||||
func (s *svc) Delete(svc *runtime.Service) error {
|
||||
func (s *svc) Delete(svc *runtime.Service, opts ...runtime.DeleteOption) error {
|
||||
var options runtime.DeleteOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
if options.Context == nil {
|
||||
options.Context = context.Background()
|
||||
}
|
||||
|
||||
// runtime service create request
|
||||
req := &pb.DeleteRequest{
|
||||
Service: &pb.Service{
|
||||
@ -188,7 +216,7 @@ func (s *svc) Delete(svc *runtime.Service) error {
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := s.runtime.Delete(context.Background(), req); err != nil {
|
||||
if _, err := s.runtime.Delete(options.Context, req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user