trpc.group/trpc-go/trpc-go@v1.0.3/internal/writev/options.go (about)

     1  //
     2  //
     3  // Tencent is pleased to support the open source community by making tRPC available.
     4  //
     5  // Copyright (C) 2023 THL A29 Limited, a Tencent company.
     6  // All rights reserved.
     7  //
     8  // If you have downloaded a copy of the tRPC source code from Tencent,
     9  // please note that tRPC source code is licensed under the  Apache 2.0 License,
    10  // A copy of the Apache 2.0 License is included in this file.
    11  //
    12  //
    13  
    14  package writev
    15  
    16  // Options is the Buffer configuration.
    17  type Options struct {
    18  	handler    QuitHandler // Set the goroutine to exit the cleanup function.
    19  	bufferSize int         // Set the length of each connection request queue.
    20  	dropFull   bool        // Whether the queue is full or not.
    21  }
    22  
    23  // Option optional parameter.
    24  type Option func(*Options)
    25  
    26  // WithQuitHandler returns an Option which sets the Buffer goroutine exit handler.
    27  func WithQuitHandler(handler QuitHandler) Option {
    28  	return func(o *Options) {
    29  		o.handler = handler
    30  	}
    31  }
    32  
    33  // WithBufferSize returns an Option which sets the length of each connection request queue.
    34  func WithBufferSize(size int) Option {
    35  	return func(opts *Options) {
    36  		opts.bufferSize = size
    37  	}
    38  }
    39  
    40  // WithDropFull returns an Option which sets whether to drop the request when the queue is full.
    41  func WithDropFull(drop bool) Option {
    42  	return func(opts *Options) {
    43  		opts.dropFull = drop
    44  	}
    45  }