// Copyright 2018 Drone.IO Inc. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package cmd import ( "encoding/json" "flag" "fmt" "os" "time" "github.com/drone/go-license/license" "github.com/drone/go-license/license/licenseutil" ) /*var ( pub = flag.String("pub", "id_ed25519.pub", "") file = flag.String("file", "license.txt", "") )*/ type Args struct { Pub string File string } func LicenseVerify(args Args) { flag.Parse() publicKey, err := licenseutil.ReadPublicKey(args.Pub) if err != nil { fmt.Println(err) os.Exit(1) } l, err := license.DecodeFile(args.File, publicKey) if err != nil { fmt.Println(err) os.Exit(1) } enc := json.NewEncoder(os.Stdout) enc.SetIndent("", " ") enc.Encode(l) } func LicenseHealth(args Args) { flag.Parse() publicKey, err := licenseutil.ReadPublicKey(args.Pub) if err != nil { fmt.Println(err) os.Exit(1) } l, err := license.DecodeFile(args.File, publicKey) if err == nil { if l.Exp.After(time.Now()) { os.Exit(0) // 正常退出 } os.Exit(1) } if err != nil { fmt.Println(err) os.Exit(2) } }