-
Notifications
You must be signed in to change notification settings - Fork 6
/
topic.go
38 lines (32 loc) · 994 Bytes
/
topic.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
37
38
package topic
import (
"context"
"github.com/golang/protobuf/ptypes/empty"
"github.com/kakao/varlog/internal/varlogctl"
"github.com/kakao/varlog/pkg/types"
"github.com/kakao/varlog/pkg/varlog"
)
// Add returns a function to add a new topic.
func Add() varlogctl.ExecuteFunc {
return func(ctx context.Context, adm varlog.Admin) (any, error) {
return adm.AddTopic(ctx)
}
}
// Remove returns a function to remove the topic identified with id.
func Remove(id types.TopicID) varlogctl.ExecuteFunc {
return func(ctx context.Context, adm varlog.Admin) (any, error) {
if err := adm.UnregisterTopic(ctx, id); err != nil {
return nil, err
}
return empty.Empty{}, nil
}
}
// Describe returns a function to list of topics or to get the topic identified with id.
func Describe(id ...types.TopicID) varlogctl.ExecuteFunc {
return func(ctx context.Context, adm varlog.Admin) (any, error) {
if len(id) > 0 {
return adm.GetTopic(ctx, id[0])
}
return adm.ListTopics(ctx)
}
}