Updated json-gold library.

This commit is contained in:
Nick Gerakines 2020-04-08 13:38:13 -04:00
parent 0dc00b181c
commit c29cead7ec
No known key found for this signature in database
GPG Key ID: 33D43D854F96B2E4
3 changed files with 16 additions and 8 deletions

1
go.mod
View File

@ -24,7 +24,6 @@ require (
github.com/piprate/json-gold v0.3.0
github.com/prometheus/client_golang v1.5.1
github.com/russross/blackfriday/v2 v2.0.1
github.com/sslhound/herr v1.4.1 // indirect
github.com/stretchr/testify v1.4.0
github.com/teacat/noire v1.0.0
github.com/urfave/cli/v2 v2.2.0

4
go.sum
View File

@ -396,8 +396,6 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/sslhound/herr v1.4.1 h1:7EBdK2gDkT7lFve3KXC1PGJUasgeQRVYbZbI3qcpl0c=
github.com/sslhound/herr v1.4.1/go.mod h1:3zw8Zr8bwddppECO/GycmavbbGYyT6oCm0urxmSXfR0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@ -413,8 +411,6 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=

View File

@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/kr/pretty"
@ -60,17 +59,31 @@ func DebugJSONLDAction(cliCtx *cli.Context) error {
}
pretty.Println(result)
triples, err := rdf(result)
if err != nil {
pretty.Println(err)
return err
}
pretty.Println(triples)
return nil
}
func compactJSONLD(document, context map[string]interface{}) (map[string]interface{}, error) {
proc := ld.NewJsonLdProcessor()
options := ld.NewJsonLdOptions("https://www.w3.org/ns/activitystreams")
options := ld.NewJsonLdOptions("")
// options.ProcessingMode = ld.JsonLd_1_1
options.DocumentLoader = DebugDocLoader{ld.NewDefaultDocumentLoader(http.DefaultClient)}
// options.DocumentLoader = DebugDocLoader{ld.NewDefaultDocumentLoader(http.DefaultClient)}
return proc.Compact(document, context, options)
}
func rdf(document map[string]interface{}) (interface{}, error) {
proc := ld.NewJsonLdProcessor()
options := ld.NewJsonLdOptions("")
options.Format = "application/n-quads"
return proc.ToRDF(document, options)
}
type DebugDocLoader struct {
DocumentLoader ld.DocumentLoader
}