diff --git a/projects/golang/go.mod b/projects/golang/go.mod new file mode 100644 index 0000000..31e4794 --- /dev/null +++ b/projects/golang/go.mod @@ -0,0 +1,3 @@ +module civichacker/lovelanguage + +go 1.18 diff --git a/projects/golang/main.go b/projects/golang/main.go new file mode 100644 index 0000000..60957b5 --- /dev/null +++ b/projects/golang/main.go @@ -0,0 +1,8 @@ +package main + +import ( + "embed" +) + +//go:embed schemas/*.json +var schemas embed.FS diff --git a/projects/golang/main_test.go b/projects/golang/main_test.go new file mode 100644 index 0000000..1016355 --- /dev/null +++ b/projects/golang/main_test.go @@ -0,0 +1,29 @@ +package main + +import ( + "testing" + "encoding/json" + "fmt" +) + +func TestSchemaLoading(t *testing.T){ + var tests = []struct { + name string + filename string + }{ + // the table itself + {"use of force", "schemas/use-of-force.schema"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + content, err := schemas.ReadFile(fmt.Sprintf("%s.json", tt.filename)) + result := json.Valid([]byte(content)) + + if err != nil { + t.Errorf("loading schema failed: %s", err) + } else if !result { + t.Errorf("schema is not valid JSON") + } + }) + } +} diff --git a/projects/golang/schemas/use-of-force.schema.json b/projects/golang/schemas/use-of-force.schema.json new file mode 100644 index 0000000..2a8e7d7 --- /dev/null +++ b/projects/golang/schemas/use-of-force.schema.json @@ -0,0 +1,69 @@ +{ + "$id": "https://raw.githubusercontent.com/civichacker/love-language/master/schemas/use-of-force.schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "x-use-of-force", + "description": "Most law enforcement agencies have policies that guide their use of force. These policies describe a escalating series of actions an officer may take to resolve a situation. This continuum generally has many levels, and officers are instructed to respond with a level of force appropriate to the situation at hand, acknowledging that the officer may move from one part of the continuum to another in a matter of seconds. https://nij.ojp.gov/topics/articles/use-force-continuum", + "type": "object", + "allOf": [ + { + "$ref": "https://raw.githubusercontent.com/oasis-open/cti-stix2-json-schemas/stix2.1/schemas/sros/relationship.json" + }, + { + "properties": { + "x_civichacker_deadly_force": { + "type": "string", + "enum": [ + "anticipatory", + "premptive", + "reactive" + ] + }, + "source_ref": { + "type": "string", + "pattern": "^(incident|identity)--" + }, + "target_ref": { + "type": "string", + "pattern": "^identity--" + }, + "x_civichacker_force_applied": { + "type": "string", + "description": "Indicates where on the Use of Force continuum force was used.", + "enum": [ + "presence", + "verbalization", + "empty-hand-control", + "less-lethal-methods", + "lethal-force" + ] + } + } + }, + { + "if": { + "properties": { + "extensions": { + "type": "object", + "required": ["extension-definition--9c59fd79-4215-4ba2-920d-3e4f320e1e62"] + } + } + }, + "then": { + "required": ["x_civichacker_use_of_force"] + } + }, + { + "if": { + "properties": { + "x_civichacker_use_of_force": { + "type": "string", + "pattern": "^lethal-force$" + } + } + }, + "then": { + "required": ["x_civichacker_deadly_force"] + } + } + ] +}