github.com/gogf/gf/v2@v2.7.4/net/gsvc/gsvc_registry.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gsvc
     8  
     9  import (
    10  	"context"
    11  
    12  	"github.com/gogf/gf/v2/errors/gcode"
    13  	"github.com/gogf/gf/v2/errors/gerror"
    14  )
    15  
    16  // Register registers `service` to default registry..
    17  func Register(ctx context.Context, service Service) (Service, error) {
    18  	if defaultRegistry == nil {
    19  		return nil, gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`)
    20  	}
    21  	ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
    22  	defer cancel()
    23  
    24  	return defaultRegistry.Register(ctx, service)
    25  }
    26  
    27  // Deregister removes `service` from default registry.
    28  func Deregister(ctx context.Context, service Service) error {
    29  	if defaultRegistry == nil {
    30  		return gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`)
    31  	}
    32  	ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
    33  	defer cancel()
    34  
    35  	return defaultRegistry.Deregister(ctx, service)
    36  }