// 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 ( "fmt" "os" "time" "github.com/drone/go-license/license" "github.com/drone/go-license/license/licenseutil" ) var year = time.Hour * 24 * 365 type Args struct { In string `json:"in"` // 输入数据 Out string `json:"out"` // 输出数据 Iss string `json:"iss"` // 发布者 Cus string `json:"cus"` // 客户 Sub string `json:"sub"` // 主题 Typ string `json:"typ"` // 类型 Lim int `json:"lim"` // 限制 Dat string `json:"dat"` // 数据 Exp time.Duration `json:"exp"` // 过期时间 } func LicenseCreate(args Args) { if args.Exp == 0 { args.Exp = year } privateKey, err := licenseutil.ReadPrivateKey(args.In) if err != nil { fmt.Println(err) os.Exit(1) } now := time.Now().UTC() license := &license.License{ Iss: args.Iss, Cus: args.Cus, Sub: args.Sub, Typ: args.Typ, Lim: args.Lim, Exp: now.Add(args.Exp), Iat: now, Dat: []byte(args.Dat), } encoded, err := license.Encode(privateKey) if err != nil { fmt.Println(err) os.Exit(1) } err = os.WriteFile(args.Out, encoded, 0644) if err != nil { fmt.Println(err) os.Exit(1) } }