EXE之后的命令行参数

I have my script "file.go" Built with "go build file.go" now I have "file.exe"

In the code I have "steamid := xxxxxxxxxxxxxxxx" Is there anyway when executing file.exe in cmd like "file.exe -steamid=xxxxxxxxxxxxxxxx"

code:

package main

import (
    "crypto/md5"
    "fmt"
)

func main() {
  steamid := xxxxxxxxxxxxxxxx

    h := md5.New()
    h.Write([]byte("BE"))

    for i := 0; i < 8; i++ {
        h.Write([]byte{byte(steamid & 0xFF)})
        steamid >>= 8
    }

    fmt.Printf("Battleye GUID: %x", h.Sum(nil))
}

I've gotten as far as here with new replys;

package main

import (
    "crypto/md5"
    "fmt"
    "bufio"
    "os"
    "flag"
)

var SteamID string

func init() {
    flag.StringVar(&SteamID, "steamid", "XXXXXXXXXXXXXXXXX", "17 Numbers SteamID")
}

func main() {
    steamid := &SteamID

    h := md5.New()
    h.Write([]byte("BE"))

    for i := 0; i < 8; i++ {
        h.Write([]byte{byte(steamid & 0xFF)})
        steamid >>= 8
    }

    fmt.Printf("Battleye GUID: %x", h.Sum(nil))
    fmt.Print("
Press 'Enter' to continue...")
    bufio.NewReader(os.Stdin).ReadBytes('
') 
}

Error:

C:\Go\bin>go build file.go
# command-line-arguments
.\file.go:24: invalid operation: steamid & 255 (mismatched types *string and int)
.\file.go:25: invalid operation: steamid >>= 8 (shift of type *string)

the flag package included in the standard library does just that.

what you need to add in your script:

var SteamID string

func init() {
    flag.StringVar(&SteamID, "steamid", "<insert default value>", "<insert help text>")
}

(in case you need to get it as an integer, use Int64Var instead) then in your main function add:

flag.Parse()

This will initialise the value of SteamID

It's all in the error message. You can't do bitwise operations with strings, pointers to strings or anything that is not an integer, you need to convert or parse them into integers first. Use strconv.ParseInt and its friends from the strconv package to parse strings.

parsedID, e := strconv.ParseInt(*steamID, 16, 64)
if e != nil { log.Fatal("couldn't parse the ID") }
// Use parsedID.