我有這段代碼:// redacted var ( cidr net.IPNet createCmd = &cobra.Command{ Use: "create", Short: "create would create something useful", Long: "create submits a request for something useful creation based on parameters provided ", Run: func(cmd *cobra.Command, args []string) { //region comes from rootCmd log.Infof("cidr: %v, ipmask: %v", cidr, cidr.IP.DefaultMask()) }, } )func init() { createCmd.Flags().IPNetVar(&cidr, "vpc-cidr", cidr, "Vpc cidr range")}// redacted輸出:./somethinguseful create --cidr 192.168.100.0/24INFO[0000] cidr: {192.168.100.0 ffffff00}, ipmask: ffffff00我無法理解命令行參數(shù) 192.168.100.0/24 在哪個(gè)階段被轉(zhuǎn)換為 net.IP 和掩碼。查看IPNet代碼func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue { *p = val return (*ipNetValue)(p) }// allocates default to pointer to net.IPNet if provided沒有任何代碼可以將輸入轉(zhuǎn)換為顯示的輸出。如何根據(jù) cidr 塊的輸入計(jì)算并打印掩碼值。請(qǐng)任何指點(diǎn)。
將 CIDR 塊轉(zhuǎn)換為 net.IP 類型
慕工程0101907
2023-07-31 16:18:26