Documentation
¶
Overview ¶
Package netflag implements functions to use network with github.com/urfave/cli/v2.
Index ¶
- func DisableGenCert(c *config)
- func DisableTLS(c *config)
- func EnableGenCert(c *config)
- func EnableTLS(c *config)
- type Client
- func (f *Client) Address() string
- func (f *Client) Before(c *cli.Context) error
- func (f *Client) Dial() (net.Conn, error)
- func (f *Client) DialNetwork(network string) (net.Conn, error)
- func (f *Client) Flags() []cli.Flag
- func (f *Client) Network() string
- func (f *Client) TLSCAs() []string
- func (f *Client) TLSCerts() []string
- func (f *Client) TLSConfig() (*tls.Config, error)
- func (f *Client) TLSKeys() []string
- func (f *Client) TLSMaxVersion() uint16
- func (f *Client) TLSMinVersion() uint16
- func (f *Client) TLSServerName() string
- func (f *Client) TLSSkipVerify() bool
- func (f *Client) UseTLS() bool
- type Option
- type Server
- func (f *Server) Address() string
- func (f *Server) Before(c *cli.Context) error
- func (f *Server) Flags() []cli.Flag
- func (f *Server) Listen() (net.Listener, error)
- func (f *Server) ListenNetwork(network string) (net.Listener, error)
- func (f *Server) Network() string
- func (f *Server) TLSCAs() []string
- func (f *Server) TLSCerts() []string
- func (f *Server) TLSConfig() (*tls.Config, error)
- func (f *Server) TLSGenCert() bool
- func (f *Server) TLSKeys() []string
- func (f *Server) TLSMaxVersion() uint16
- func (f *Server) TLSMinVersion() uint16
- func (f *Server) UseTLS() bool
- type TLSVersion
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableGenCert ¶
func DisableGenCert(c *config)
DisableGenCert is the option not to use FlagTLSGenCert.
func EnableGenCert ¶
func EnableGenCert(c *config)
EnableGenCert is the option to use FlagTLSGenCert.
Types ¶
type Client ¶
type Client struct { // Name is the name of the Client, may be empty string. Name string // PredeterminedFlagNetwork is true if the value of FlagNetwork is predetermined by the option. PredeterminedFlagNetwork bool // DisableTLS is true if TLS is disabled. DisableTLS bool // FlagNetwork is the network to connect. FlagNetwork *cli.StringFlag // FlagAddress is the address to connect. FlagAddress *cli.StringFlag // FlagTLSCerts is the certificate filepath of the client. FlagTLSCerts *cli.StringSliceFlag // FlagTLSKeys is the private key filepath of the certificate. FlagTLSKeys *cli.StringSliceFlag // FlagTLSCAs is the certificate filepath of the RootCAs. FlagTLSCAs *cli.StringSliceFlag // FlagTLSServerName is the value of server name. FlagTLSServerName *cli.StringFlag // FlagTLSSkipVerify is value to InsecureSkipVerify. FlagTLSSkipVerify *cli.BoolFlag // FlagTLSMinVer is the minimum TLS version that is acceptable. FlagTLSMinVer *cli.GenericFlag // FlagTLSMaxVer is the maximum TLS version that is acceptable. FlagTLSMaxVer *cli.GenericFlag // FlagSet is clix.FlagSet. FlagSet clix.FlagSet }
Client represents the flags related to a client to connect a server.
Example ¶
clientFlags := netflag.NewClientName( clix.FlagPrefix("EXAMPLE_"), "echo", netflag.Network("udp", "*"), netflag.Address("127.0.0.1:9000"), ) app := cli.NewApp() app.Name = "example" app.HelpName = "example" app.Flags = clientFlags.Flags() app.Before = clientFlags.Before app.Action = func(c *cli.Context) error { fmt.Println("network[" + clientFlags.Network() + "]") fmt.Println("address[" + clientFlags.Address() + "]") return nil } _ = app.Run([]string{"example", "--help"})
Output: NAME: example - A new cli application USAGE: example [global options] command [command options] [arguments...] COMMANDS: help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --echo-network value, --echo-net value network to connect (default: "udp") [$EXAMPLE_ECHO_NETWORK, $EXAMPLE_ECHO_NET] --echo-address value, --echo-addr value address to connect (default: "127.0.0.1:9000") [$EXAMPLE_ECHO_ADDRESS, $EXAMPLE_ECHO_ADDR] --echo-tls-cert file, --echo-tlscrt file certificate file [$EXAMPLE_ECHO_TLS_CERT, $EXAMPLE_ECHO_TLSCRT] --echo-tls-cert-key file, --echo-tlskey file private key file of certificate [$EXAMPLE_ECHO_TLS_CERT_KEY, $EXAMPLE_ECHO_TLSKEY] --echo-tls-ca file, --echo-tlsca file root CA file of server [$EXAMPLE_ECHO_TLS_CA, $EXAMPLE_ECHO_TLSCA] --echo-tls-server-name value, --echo-tlssrv value server name for verification [$EXAMPLE_ECHO_TLS_SERVER_NAME, $EXAMPLE_ECHO_TLSSRV] --echo-tls-skip-verify, --echo-tlsinsecure TLS insecure skip verify (default: false) [$EXAMPLE_ECHO_TLS_SKIP_VERIFY, $EXAMPLE_ECHO_TLSINSECURE] --echo-tls-min-version value, --echo-tlsmin value TLS minimum version (default: 1.2) [$EXAMPLE_ECHO_TLS_MIN_VERSION, $EXAMPLE_ECHO_TLSMIN] --echo-tls-max-version value, --echo-tlsmax value TLS maximum version (default: 1.3) [$EXAMPLE_ECHO_TLS_MAX_VERSION, $EXAMPLE_ECHO_TLSMAX] --help, -h show help (default: false)
func NewClient ¶
func NewClient(prefix clix.FlagPrefix, opts ...Option) *Client
NewClient returns NewClient(prefix, "", opts...).
func NewClientName ¶
func NewClientName(prefix clix.FlagPrefix, name string, opts ...Option) *Client
NewClientName returns *Client.
func (*Client) Before ¶
Before calls f.FlagSet.Init(c). Before is intended to be used as cli.BeforeFunc.
func (*Client) DialNetwork ¶
DialNetwork returns the result of calling tls.Dial if f.UseTLS() returns true, otherwise returns the result of calling net.Dial. f.Address() and f.TLSConfig() are used.
func (*Client) Flags ¶
func (f *Client) Flags() []cli.Flag
Flags returns []cli.Flag.
It includes the following.
f.FlagNetwork (if not predetermined) f.FlagAddress
It also includes the following if TLS is enabled.
f.FlagTLSCerts f.FlagTLSKeys f.FlagTLSCAs f.FlagTLSServerName f.FlagTLSSkipVerify f.FlagTLSMinVer f.FlagTLSMaxVer
func (*Client) TLSMaxVersion ¶
TLSMaxVersion returns the value of FlagTLSMaxVer.
func (*Client) TLSMinVersion ¶
TLSMinVersion returns the value of FlagTLSMinVer.
func (*Client) TLSServerName ¶
func (*Client) TLSSkipVerify ¶
TLSSkipVerify returns the value of FlagTLSSkipVerify.
type Option ¶
type Option func(*config)
Option represents options for Client and Server.
func Address ¶
Address returns the option setting default address. FlagAddress is set required if the default address is not set.
func Network ¶
Network returns the option shows acceptable networks. FlagNetwork is available in command line options if more than one networks is set. Otherwise FlagNetwork is not shown in the command line options. Default value of network is "tcp".
func SkipVerify ¶
SkipVerify returns the option to set default value of FlagSkipVerify.
func TLSMaxVersion ¶
TLSMaxVersion returns the option to set default value of FlagTLSMaxVer.
func TLSMinVersion ¶
TLSMinVersion returns the option to set default value of FlagTLSMinVer.
type Server ¶
type Server struct { // Name is the name of Server, may be empty string. Name string // PredeterminedFlagNetwork is true if the value of FlagNetwork is predetermined by the option. PredeterminedFlagNetwork bool // DisableTLS is true if TLS is disabled. DisableTLS bool // DisableFlagTLSGenCert is true if FlagTLSGenCert would be included in the result of Flags(). DisableFlagTLSGenCert bool // FlagNetwork is the network to listen. FlagNetwork *cli.StringFlag // FlagAddress is the address to listen. FlagAddress *cli.StringFlag // FlagTLSCerts is the certificate filepath of the server. FlagTLSCerts *cli.StringSliceFlag // FlagTLSKeys is the private key filepath of the certificate. FlagTLSKeys *cli.StringSliceFlag // FlagTLSGenCert specifies whether to generate a self signed certificate. FlagTLSGenCert *cli.BoolFlag // FlagTLSCAs is the certificate filepath of the ClientCAs. FlagTLSCAs *cli.StringSliceFlag // FlagTLSMinVer is the minimum TLS version that is acceptable. FlagTLSMinVer *cli.GenericFlag // FlagTLSMaxVer is the maximum TLS version that is acceptable. FlagTLSMaxVer *cli.GenericFlag // FlagSet is clix.FlagSet. FlagSet clix.FlagSet }
Server represents the flags related to a server to listen and accept clients.
func NewServer ¶
func NewServer(prefix clix.FlagPrefix, opts ...Option) *Server
NewServer returns NewServer(prefix, "", opts...).
func NewServerName ¶
func NewServerName(prefix clix.FlagPrefix, name string, opts ...Option) *Server
NewServerName returns *Server.
func (*Server) Before ¶
Before calls f.FlagSet.Init(c), validates exclusive flags. Before is intended to be used as cli.BeforeFunc.
func (*Server) Flags ¶
func (f *Server) Flags() []cli.Flag
Flags returns []cli.Flag.
It includes the following.
f.FlagNetwork (if not predetermined) f.FlagAddress
It also includes the following if TLS is enabled.
f.FlagTLSCerts f.FlagTLSKeys f.FlagTLSGenCert (if not disabled) f.FlagTLSCAs f.FlagTLSMinVer f.FlagTLSMaxVer
func (*Server) ListenNetwork ¶
ListenNetwork returns the result of calling tls.Listen if f.UseTLS() returns true, otherwise returns the result of calling net.Listen. f.Address() and f.TLSConfig() are used.
func (*Server) TLSGenCert ¶
TLSGenCert returns the value of FlagTLSGenCert.
func (*Server) TLSMaxVersion ¶
TLSMaxVersion returns the value of FlagTLSMaxVer.
func (*Server) TLSMinVersion ¶
TLSMinVersion returns the value of FlagTLSMinVer.
type TLSVersion ¶
type TLSVersion struct {
// contains filtered or unexported fields
}
TLSVersion wraps a uint16 as tls.Version* to satisfy flag.Value.
func NewTLSVersion ¶
func NewTLSVersion(value uint16) *TLSVersion
NewTLSVersion creates a *TLSVersion with a default value.
func (*TLSVersion) Set ¶
func (tv *TLSVersion) Set(value string) error
Set parses value as TLS version string, sets it.
func (*TLSVersion) String ¶
func (tv *TLSVersion) String() string
String returns a readable representation of this value (for usage defaults)
func (*TLSVersion) Value ¶
func (tv *TLSVersion) Value() uint16
Value returns an uint16 as TLS version set by this flag.