863 Keyspaces: keyspaces,
864 }
865
866 key := strings.Join([]string{rootPath, endpoint.KeyspaceGroupIDPath(groupID)}, "/") 867 value, err := json.Marshal(group)
868 if err != nil {
869 return err
834 ctx context.Context, etcdClient *clientv3.Client,
835 rootPath string, id uint32,
836) error {
837 key := strings.Join([]string{rootPath, endpoint.KeyspaceGroupIDPath(id)}, "/") 838
839 if _, err := etcdClient.Delete(ctx, key); err != nil {
840 return err
816 ctx context.Context, etcdClient *clientv3.Client,
817 rootPath string, group *endpoint.KeyspaceGroup,
818) error {
819 key := strings.Join([]string{rootPath, endpoint.KeyspaceGroupIDPath(group.ID)}, "/") 820 value, err := json.Marshal(group)
821 if err != nil {
822 return err
(\d{5})$
289
290// GetCompiledKeyspaceGroupIDRegexp returns the compiled regular expression for matching keyspace group id.
291func GetCompiledKeyspaceGroupIDRegexp() *regexp.Regexp {
292 pattern := strings.Join([]string{KeyspaceGroupIDPrefix(), `(\d{5})$`}, "/")293 return regexp.MustCompile(pattern)
294}
295
237}
238
239func (s *GrpcServer) loadRangeFromETCD(startKey, endKey string) ([]string, []string, int64, error) {
240 startKey = strings.Join([]string{s.rootPath, startKey}, "/")241 var opOption []clientv3.OpOption
242 if endKey == "\ " {
243 opOption = append(opOption, clientv3.WithPrefix())
Some string concatenation operations such as strings.Join
called with a single
or a two element slice can be simplified using binary operators.
This also improves performance as it doesn't need to allocate a new slice and iterate through it.
func foo(x, y string) string {
return strings.Join([]string{x, y}, "_")
}
func foo(x, y string) string {
return x + "_" + y
}