trpc.group/trpc-go/trpc-go@v1.0.3/admin/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 admin
    15  
    16  import (
    17  	"time"
    18  )
    19  
    20  // Option Service configuration options.
    21  type Option func(*configuration)
    22  
    23  // WithAddr returns an Option which sets the address bound to admin, default: ":9028".
    24  // Supported formats:
    25  // 1. :80
    26  // 2. 0.0.0.0:80
    27  // 3. localhost:80
    28  // 4. 127.0.0.0:8001
    29  func WithAddr(addr string) Option {
    30  	return func(config *configuration) {
    31  		config.addr = addr
    32  	}
    33  }
    34  
    35  // WithTLS returns an Option which sets whether to use HTTPS.
    36  func WithTLS(isTLS bool) Option {
    37  	return func(config *configuration) {
    38  		config.enableTLS = isTLS
    39  	}
    40  }
    41  
    42  // WithVersion returns an Option which sets the version number.
    43  func WithVersion(version string) Option {
    44  	return func(config *configuration) {
    45  		config.version = version
    46  	}
    47  }
    48  
    49  // WithReadTimeout returns an Option which sets read timeout.
    50  func WithReadTimeout(readTimeout time.Duration) Option {
    51  	return func(config *configuration) {
    52  		if readTimeout > 0 {
    53  			config.readTimeout = readTimeout
    54  		}
    55  	}
    56  }
    57  
    58  // WithWriteTimeout returns an Option which sets write timeout.
    59  func WithWriteTimeout(writeTimeout time.Duration) Option {
    60  	return func(config *configuration) {
    61  		if writeTimeout > 0 {
    62  			config.writeTimeout = writeTimeout
    63  		}
    64  	}
    65  }
    66  
    67  // WithConfigPath returns an Option which sets the framework configuration file path.
    68  func WithConfigPath(configPath string) Option {
    69  	return func(config *configuration) {
    70  		config.configPath = configPath
    71  	}
    72  }
    73  
    74  // WithSkipServe sets whether to skip starting the admin service.
    75  func WithSkipServe(isSkip bool) Option {
    76  	return func(config *configuration) {
    77  		config.skipServe = isSkip
    78  	}
    79  }