|
| 1 | +package vo |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "runtime" |
| 6 | + "strings" |
| 7 | + "text/tabwriter" |
| 8 | +) |
| 9 | + |
| 10 | +type AppInfo struct { |
| 11 | + Description string `json:"description" yaml:"description"` |
| 12 | + Version string `json:"version" yaml:"version"` |
| 13 | + Commit string `json:"commit" yaml:"commit"` |
| 14 | + Date string `json:"date" yaml:"date"` |
| 15 | + GoVer string `json:"goVer" yaml:"goVer"` |
| 16 | + Compiler string `json:"compiler" yaml:"compiler"` |
| 17 | + Platform string `json:"platform" yaml:"platform"` |
| 18 | +} |
| 19 | + |
| 20 | +func NewAppInfo() AppInfo { |
| 21 | + return AppInfo{ |
| 22 | + Description: "", |
| 23 | + Version: "devel", |
| 24 | + Commit: "none", |
| 25 | + Date: "none", |
| 26 | + GoVer: runtime.Version(), |
| 27 | + Compiler: runtime.Compiler, |
| 28 | + Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +func (r AppInfo) Array() [][]string { |
| 33 | + return [][]string{ |
| 34 | + {"Version", "Commit", "Date", "GoVer", "Compiler", "Platform"}, |
| 35 | + {r.Version, r.Commit, r.Date, r.GoVer, r.Compiler, r.Platform}, |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func (r AppInfo) String() string { |
| 40 | + b := strings.Builder{} |
| 41 | + w := tabwriter.NewWriter(&b, 0, 0, 2, ' ', 0) |
| 42 | + if r.Description != "" { |
| 43 | + _, _ = fmt.Fprint(w, r.Description) |
| 44 | + _, _ = fmt.Fprint(w, "\n\n") |
| 45 | + } |
| 46 | + _, _ = fmt.Fprintf(w, "Version:\t%s\n", r.Version) |
| 47 | + _, _ = fmt.Fprintf(w, "Commit:\t%s\n", r.Commit) |
| 48 | + _, _ = fmt.Fprintf(w, "Date:\t%s\n", r.Date) |
| 49 | + _, _ = fmt.Fprintf(w, "GoVer:\t%s\n", r.GoVer) |
| 50 | + _, _ = fmt.Fprintf(w, "Compiler:\t%s\n", r.Compiler) |
| 51 | + _, _ = fmt.Fprintf(w, "Platform:\t%s\n", r.Platform) |
| 52 | + |
| 53 | + _ = w.Flush() |
| 54 | + return b.String() |
| 55 | +} |
0 commit comments