From c29cead7ec62784d4c80378950f9894b2edfa050 Mon Sep 17 00:00:00 2001 From: Nick Gerakines Date: Wed, 8 Apr 2020 13:38:13 -0400 Subject: [PATCH] Updated json-gold library. --- go.mod | 1 - go.sum | 4 ---- json/command_ld.go | 19 ++++++++++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index f29a8a9..a1229cd 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 80ea597..0130454 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/json/command_ld.go b/json/command_ld.go index c2e3f33..f4c0074 100644 --- a/json/command_ld.go +++ b/json/command_ld.go @@ -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 }