go读取命令参数

package main

import (
    "flag"
    "fmt"
)

var (
    host *string
    port int
)

func init() {
    host = flag.String("host", "ali", "域名")
    flag.IntVar(&port, "port", 8080, "端口")
}

func main() {
    flag.Parse()
    fmt.Println(*host)
    fmt.Println(port)
}

你可能感兴趣的:(go读取命令参数)