trpc.group/trpc-go/trpc-cmdline@v1.0.9/util/pb/option.go (about)

     1  // Tencent is pleased to support the open source community by making tRPC available.
     2  //
     3  // Copyright (C) 2023 THL A29 Limited, a Tencent company.
     4  // All rights reserved.
     5  //
     6  // If you have downloaded a copy of the tRPC source code from Tencent,
     7  // please note that tRPC source code is licensed under the  Apache 2.0 License,
     8  // A copy of the Apache 2.0 License is included in this file.
     9  
    10  package pb
    11  
    12  type options struct {
    13  	secvEnabled       bool
    14  	validationEnabled bool
    15  	pb2ImportPath     map[string]string
    16  	pkg2ImportPath    map[string]string
    17  	descriptorSetIn   string
    18  }
    19  
    20  // Option is used to store the content of the relevant options.
    21  type Option func(*options)
    22  
    23  // WithSecvEnabled enables validation and generates stub code using protoc-gen-secv.
    24  // Note: protoc-gen-secv is a modified version of protoc-gen-validate.
    25  // protoc-gen-secv is still not opensourced.
    26  // Please use WithValidationEnabled instead.
    27  func WithSecvEnabled(enabled bool) Option {
    28  	return func(o *options) {
    29  		o.secvEnabled = enabled
    30  	}
    31  }
    32  
    33  // WithValidateEnabled enables validation and generates stub code using protoc-gen-validate.
    34  // https://github.com/bufbuild/protoc-gen-validate/tree/v1.0.2
    35  func WithValidateEnabled(enabled bool) Option {
    36  	return func(o *options) {
    37  		o.validationEnabled = enabled
    38  	}
    39  }
    40  
    41  // WithPb2ImportPath adds mapping between pb file and import path.
    42  func WithPb2ImportPath(m map[string]string) Option {
    43  	return func(o *options) {
    44  		o.pb2ImportPath = m
    45  	}
    46  }
    47  
    48  // WithPkg2ImportPath adds the mapping between package name and import path.
    49  func WithPkg2ImportPath(m map[string]string) Option {
    50  	return func(o *options) {
    51  		o.pkg2ImportPath = m
    52  	}
    53  }
    54  
    55  // WithDescriptorSetIn adds the descriptor_set_in option to the command.
    56  func WithDescriptorSetIn(descriptorSetIn string) Option {
    57  	return func(o *options) {
    58  		o.descriptorSetIn = descriptorSetIn
    59  	}
    60  }