github.com/cloudwego/kitex@v0.9.0/client/streamclient/definition.go (about)

     1  /*
     2   * Copyright 2023 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package streamclient
    18  
    19  import (
    20  	"github.com/cloudwego/kitex/client"
    21  	"github.com/cloudwego/kitex/pkg/utils"
    22  )
    23  
    24  type Option struct {
    25  	F func(*client.Options, *utils.Slice)
    26  }
    27  
    28  // Deprecated: it's not supposed to be called by users directly and may be removed in future versions.
    29  // GetClientOption returns a client.Option
    30  func (o *Option) GetClientOption() client.Option {
    31  	return client.Option{F: o.F}
    32  }
    33  
    34  // Deprecated: it's not supposed to be called by users directly; may be removed in future versions.
    35  // ConvertOptionFrom converts client.Option to streamclient.Option
    36  // It's convenient for creating StreamOption from existing client.Option
    37  // Note: NOT all client.Option(s) converted will work for stream clients;
    38  // Even if it works for now, it's NOT guaranteed that it will always work for future versions.
    39  func ConvertOptionFrom(opt client.Option) Option {
    40  	return Option{F: opt.F}
    41  }
    42  
    43  // GetClientOptions converts given streamclient.Option(s) to client.Option(s)
    44  func GetClientOptions(ops []Option) []client.Option {
    45  	options := make([]client.Option, 0, len(ops))
    46  	for _, opt := range ops {
    47  		options = append(options, opt.GetClientOption())
    48  	}
    49  	return options
    50  }