Skip to content

Commit

Permalink
new project for golang. Leveraging go:embed
Browse files Browse the repository at this point in the history
  • Loading branch information
jcockhren committed Jun 17, 2023
1 parent 0af8725 commit 0031852
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
3 changes: 3 additions & 0 deletions projects/golang/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module civichacker/lovelanguage

go 1.18
8 changes: 8 additions & 0 deletions projects/golang/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import (
"embed"
)

//go:embed schemas/*.json
var schemas embed.FS
29 changes: 29 additions & 0 deletions projects/golang/main_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
})
}
}
69 changes: 69 additions & 0 deletions projects/golang/schemas/use-of-force.schema.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
]
}

0 comments on commit 0031852

Please sign in to comment.