| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
package main |
| 12 |
|
| 13 |
import ( |
| 14 |
"flag" |
| 15 |
"fmt" |
| 16 |
"log" |
| 17 |
|
| 18 |
"github.com/denisbrodbeck/machineid" |
| 19 |
) |
| 20 |
|
| 21 |
const usageStr = ` |
| 22 |
Usage: machineid [options] |
| 23 |
|
| 24 |
Options: |
| 25 |
--appid <AppID> Protect machine id by hashing it together with an app id. |
| 26 |
|
| 27 |
Try: |
| 28 |
machineid |
| 29 |
machineid --appid MyAppID |
| 30 |
` |
| 31 |
|
| 32 |
func usage() { |
| 33 |
log.Fatalln(usageStr) |
| 34 |
} |
| 35 |
|
| 36 |
func main() { |
| 37 |
var appID string |
| 38 |
flag.StringVar(&appID, "appid", "", "Protect machine id by hashing it together with an app id.") |
| 39 |
|
| 40 |
log.SetFlags(0) |
| 41 |
flag.Usage = usage |
| 42 |
flag.Parse() |
| 43 |
|
| 44 |
var id string |
| 45 |
var err error |
| 46 |
if appID != "" { |
| 47 |
id, err = machineid.ProtectedID(appID) |
| 48 |
} else { |
| 49 |
id, err = machineid.ID() |
| 50 |
} |
| 51 |
if err != nil { |
| 52 |
log.Fatalf("Failed to read machine id with error: %s\n", err) |
| 53 |
} |
| 54 |
fmt.Println(id) |
| 55 |
} |