-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
115 lines (107 loc) · 2.59 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package sauce_test
import (
"embed"
"fmt"
"log"
"time"
"github.com/bengarrett/sauce"
)
//go:embed static/*
var static embed.FS
func Example() { //nolint:funlen
// open a file
file, err := static.Open("static/sauce.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
// read the file and create a SAUCE record
sr, err := sauce.Read(file)
if err != nil {
log.Println(err)
return
}
if !sr.Valid() {
fmt.Println("no sauce metadata found")
return
}
// print specific SAUCE fields
fmt.Printf("%q\n", sr.Title)
fmt.Printf("Author,\t%s.\n", sr.Author)
fmt.Printf("Group,\t%s.\n", sr.Group)
fmt.Printf("Date,\t%s.\n", sr.Date.Time.Format(time.ANSIC))
// return the SAUCE data as indented JSON
js, err := sr.JSONIndent(" ")
if err != nil {
log.Println(err)
return
}
fmt.Printf("%s", js)
// Output: "Sauce title"
// Author, Sauce author.
// Group, Sauce group.
// Date, Sat Nov 26 00:00:00 2016.
//{
// "id": "SAUCE",
// "version": "00",
// "title": "Sauce title",
// "author": "Sauce author",
// "group": "Sauce group",
// "date": {
// "value": "20161126",
// "iso": "2016-11-26T00:00:00Z",
// "epoch": 1480118400
// },
// "filesize": {
// "bytes": 3741,
// "decimal": "3.7 kB",
// "binary": "3.7 KiB"
// },
// "dataType": {
// "type": 1,
// "name": "text or character stream"
// },
// "fileType": {
// "type": 0,
// "name": "ASCII text"
// },
// "typeInfo": {
// "1": {
// "value": 977,
// "info": "character width"
// },
// "2": {
// "value": 9,
// "info": "number of lines"
// },
// "3": {
// "value": 0,
// "info": ""
// },
// "flags": {
// "decimal": 19,
// "binary": "10011",
// "nonBlinkMode": {
// "flag": "1",
// "interpretation": "non-blink mode"
// },
// "letterSpacing": {
// "flag": "00",
// "interpretation": "no preference"
// },
// "aspectRatio": {
// "flag": "11",
// "interpretation": "invalid value"
// }
// },
// "fontName": "IBM VGA"
// },
// "comments": {
// "id": "COMNT",
// "count": 1,
// "lines": [
// "Any comments go here. "
// ]
// }
// }
}