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