this repo has no description
1package main
2
3import (
4 "encoding/json"
5 "fmt"
6 "log"
7 "slices"
8
9 "golang.org/x/text/collate"
10 "golang.org/x/text/language"
11
12 "github.com/edavis/recordcollector/pkg"
13)
14
15type Locale struct {
16 Lang string `json:"lang"`
17 Name string `json:"name"`
18 Description string `json:"description"`
19}
20
21type Definition struct {
22 Blurs string `json:"blurs"`
23 Severity string `json:"severity"`
24 AdultOnly bool `json:"adultOnly"`
25 Identifier string `json:"identifier"`
26 DefaultSetting string `json:"defaultSetting"`
27 Locales []Locale `json:"locales"`
28}
29
30type Document struct {
31 Values []string `json:"labelValues"`
32 Definitions []Definition `json:"labelValueDefinitions"`
33}
34
35func main() {
36 var values []string
37 var defs []Definition
38
39 col := collate.New(language.English)
40 slices.SortFunc(pkg.Applications, func(a, b pkg.Application) int {
41 return col.CompareString(a.Name, b.Name)
42 })
43
44 for _, app := range pkg.Applications {
45 values = append(values, app.Label)
46 defs = append(defs, Definition{
47 Blurs: "none",
48 Severity: "inform",
49 AdultOnly: false,
50 Identifier: app.Label,
51 DefaultSetting: "warn",
52 Locales: []Locale{
53 {
54 Lang: "en",
55 Name: app.Name,
56 Description: fmt.Sprintf("%s (%s.*)", app.Description, app.NSID),
57 },
58 },
59 })
60 }
61
62 doc := Document{
63 Values: values,
64 Definitions: defs,
65 }
66 out, err := json.Marshal(doc)
67 if err != nil {
68 log.Fatalln("error creating JSON")
69 }
70 fmt.Println(string(out))
71}