github.com/cloudwego/kitex@v0.9.0/client/callopt/streamcall/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 streamcall
    18  
    19  import (
    20  	"strings"
    21  
    22  	"github.com/cloudwego/kitex/client/callopt"
    23  )
    24  
    25  // Option is the option type used in StreamClient's Call method
    26  type Option struct {
    27  	f func(o *callopt.CallOptions, di *strings.Builder)
    28  }
    29  
    30  // Deprecated: it's not supposed to be called by users directly and may be removed in future versions.
    31  // GetCallOption returns a callopt.Option
    32  func (o Option) GetCallOption() callopt.Option {
    33  	return callopt.NewOption(o.f)
    34  }
    35  
    36  // Deprecated: it's not supposed to be called by users directly; may be removed in future versions.
    37  // ConvertOptionFrom converts a callopt.Option to StreamOption
    38  // It's convenient for creating StreamOption from existing callopt.Option
    39  // Note: NOT all callopt.Option(s) converted will work for stream clients;
    40  // Even if it works for now, it's NOT guaranteed that it will always work for future versions.
    41  func ConvertOptionFrom(option callopt.Option) Option {
    42  	return Option{f: option.F()}
    43  }
    44  
    45  // GetCallOptions converts given streamcall.Option(s) to callopt.Option
    46  func GetCallOptions(ops []Option) []callopt.Option {
    47  	options := make([]callopt.Option, 0, len(ops))
    48  	for _, opt := range ops {
    49  		options = append(options, opt.GetCallOption())
    50  	}
    51  	return options
    52  }