-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from gfeyer/main
Update to version 2.6
- Loading branch information
Showing
32 changed files
with
6,147 additions
and
5,432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,6 @@ | |
/test/Release | ||
/test/x64 | ||
*.j | ||
*.txt | ||
*.txt | ||
/build | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
go build -o libjq.dll -buildmode=c-shared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
go build -o libjq -buildmode=c-archive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* Code generated by cmd/cgo; DO NOT EDIT. */ | ||
|
||
/* package _/install/platform-tools/kafkadesktopclient/3rdparty/gjq */ | ||
|
||
|
||
#line 1 "cgo-builtin-export-prolog" | ||
|
||
#include <stddef.h> /* for ptrdiff_t below */ | ||
|
||
#ifndef GO_CGO_EXPORT_PROLOGUE_H | ||
#define GO_CGO_EXPORT_PROLOGUE_H | ||
|
||
#ifndef GO_CGO_GOSTRING_TYPEDEF | ||
typedef struct { const char *p; ptrdiff_t n; } _GoString_; | ||
#endif | ||
|
||
#endif | ||
|
||
/* Start of preamble from import "C" comments. */ | ||
|
||
|
||
|
||
|
||
/* End of preamble from import "C" comments. */ | ||
|
||
|
||
/* Start of boilerplate cgo prologue. */ | ||
#line 1 "cgo-gcc-export-header-prolog" | ||
|
||
#ifndef GO_CGO_PROLOGUE_H | ||
#define GO_CGO_PROLOGUE_H | ||
|
||
typedef signed char GoInt8; | ||
typedef unsigned char GoUint8; | ||
typedef short GoInt16; | ||
typedef unsigned short GoUint16; | ||
typedef int GoInt32; | ||
typedef unsigned int GoUint32; | ||
typedef long long GoInt64; | ||
typedef unsigned long long GoUint64; | ||
typedef GoInt64 GoInt; | ||
typedef GoUint64 GoUint; | ||
typedef __SIZE_TYPE__ GoUintptr; | ||
typedef float GoFloat32; | ||
typedef double GoFloat64; | ||
typedef float _Complex GoComplex64; | ||
typedef double _Complex GoComplex128; | ||
|
||
/* | ||
static assertion to make sure the file is being used on architecture | ||
at least with matching size of GoInt. | ||
*/ | ||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; | ||
|
||
#ifndef GO_CGO_GOSTRING_TYPEDEF | ||
typedef _GoString_ GoString; | ||
#endif | ||
typedef void *GoMap; | ||
typedef void *GoChan; | ||
typedef struct { void *t; void *v; } GoInterface; | ||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; | ||
|
||
#endif | ||
|
||
/* End of boilerplate cgo prologue. */ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern long int cgoCurrentMillis(); | ||
extern char* cgoFilter(char* userQuery, char* jsonRequest); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Code generated by cmd/cgo; DO NOT EDIT. */ | ||
|
||
/* package _/install/platform-tools/kafkadesktopclient/src/gjq */ | ||
|
||
|
||
#line 1 "cgo-builtin-export-prolog" | ||
|
||
#include <stddef.h> /* for ptrdiff_t below */ | ||
|
||
#ifndef GO_CGO_EXPORT_PROLOGUE_H | ||
#define GO_CGO_EXPORT_PROLOGUE_H | ||
|
||
#ifndef GO_CGO_GOSTRING_TYPEDEF | ||
typedef struct { const char *p; ptrdiff_t n; } _GoString_; | ||
#endif | ||
|
||
#endif | ||
|
||
/* Start of preamble from import "C" comments. */ | ||
|
||
|
||
|
||
|
||
/* End of preamble from import "C" comments. */ | ||
|
||
|
||
/* Start of boilerplate cgo prologue. */ | ||
#line 1 "cgo-gcc-export-header-prolog" | ||
|
||
#ifndef GO_CGO_PROLOGUE_H | ||
#define GO_CGO_PROLOGUE_H | ||
|
||
typedef signed char GoInt8; | ||
typedef unsigned char GoUint8; | ||
typedef short GoInt16; | ||
typedef unsigned short GoUint16; | ||
typedef int GoInt32; | ||
typedef unsigned int GoUint32; | ||
typedef long long GoInt64; | ||
typedef unsigned long long GoUint64; | ||
typedef GoInt64 GoInt; | ||
typedef GoUint64 GoUint; | ||
#ifndef _WIN32 | ||
typedef __SIZE_TYPE__ GoUintptr; | ||
#endif | ||
typedef float GoFloat32; | ||
typedef double GoFloat64; | ||
#ifndef _WIN32 | ||
typedef float _Complex GoComplex64; | ||
typedef double _Complex GoComplex128; | ||
#endif | ||
/* | ||
static assertion to make sure the file is being used on architecture | ||
at least with matching size of GoInt. | ||
*/ | ||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; | ||
|
||
#ifndef GO_CGO_GOSTRING_TYPEDEF | ||
typedef _GoString_ GoString; | ||
#endif | ||
typedef void *GoMap; | ||
typedef void *GoChan; | ||
typedef struct { void *t; void *v; } GoInterface; | ||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; | ||
|
||
#endif | ||
|
||
/* End of boilerplate cgo prologue. */ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifdef _WIN32 | ||
// windows build | ||
extern __declspec(dllexport) long int cgoCurrentMillis(); | ||
extern __declspec(dllexport) char* cgoFilter(char* userQuery, char* jsonRequest); | ||
#else | ||
// Linux & Macos build | ||
extern long int cgoCurrentMillis(); | ||
extern char* cgoFilter(char* userQuery, char* jsonRequest); | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package main | ||
|
||
import "C" | ||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/itchyny/gojq" | ||
) | ||
|
||
//export cgoCurrentMillis | ||
func cgoCurrentMillis() C.long { | ||
return C.long(time.Now().Unix()) | ||
} | ||
|
||
//export cgoFilter | ||
func cgoFilter(userQuery *C.char, jsonRequest *C.char) *C.char { | ||
q := " fromjson | " + C.GoString(userQuery) | ||
input := C.GoString(jsonRequest) | ||
|
||
query, err := gojq.Parse(q) | ||
|
||
if err != nil { | ||
return C.CString(err.Error()) | ||
} | ||
|
||
iter := query.Run(input) | ||
|
||
// var jsonResult string | ||
var result []byte | ||
|
||
for { | ||
v, ok := iter.Next() | ||
if !ok { | ||
break | ||
} | ||
if err, ok := v.(error); ok { | ||
return C.CString(err.Error()) | ||
} | ||
|
||
j, err := json.Marshal(v) | ||
|
||
if err == nil { | ||
// jsonResult += string(j) | ||
if len(result) == 0 { | ||
result = append(result, j...) | ||
} else { | ||
result = append(result, '\n') | ||
result = append(result, j...) | ||
} | ||
} | ||
} | ||
|
||
// cstr := C.CString(jsonResult) | ||
cstr := C.CString(string(result)) | ||
return cstr | ||
} | ||
|
||
func main() { | ||
query, err := gojq.Parse(" fromjson | .glossary.GlossDiv") | ||
|
||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
// input := map[string]interface{}{"foo": []interface{}{1, 2, 3}} | ||
input := `{ | ||
"glossary": { | ||
"title": "example glossary", | ||
"GlossDiv": { | ||
"title": "S", | ||
"GlossList": { | ||
"GlossEntry": { | ||
"ID": "SGML", | ||
"SortAs": "SGML", | ||
"GlossTerm": "Standard Generalized Markup Language", | ||
"Acronym": "SGML", | ||
"Abbrev": "ISO 8879:1986", | ||
"GlossDef": { | ||
"para": "A meta-markup language, used to create markup languages such as DocBook.", | ||
"GlossSeeAlso": ["GML", "XML"] | ||
}, | ||
"GlossSee": "markup" | ||
} | ||
} | ||
} | ||
} | ||
}` | ||
iter := query.Run(input) // or query.RunWithContext | ||
|
||
v, _ := iter.Next() | ||
b, err := json.Marshal(v) | ||
|
||
fmt.Println(string(b)) | ||
|
||
for { | ||
v, ok := iter.Next() | ||
if !ok { | ||
break | ||
} | ||
if err, ok := v.(error); ok { | ||
log.Fatalln(err) | ||
} | ||
fmt.Printf("%#v\n", v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# With cgo, cannot use .lib directly in visual studio (only works with MinGW compiler). | ||
# So we need to generate the .dll file with go build, then generate the .lib file from the dll by using the function definitions | ||
# | ||
# details 1: https://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll | ||
# details 2: https://web.archive.org/web/20130330132630/http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio | ||
# | ||
# To create the .def file from .dll, open developer command VS2019->Tools->Command Line->Developer command prompt | ||
# dumpbin /exports libjq.dll | ||
# get the function names and add them to the .def file, example: | ||
# EXPORTS | ||
# function1 | ||
# function2 | ||
# | ||
# After .def file is created, run command below to create .lib from .def | ||
|
||
lib /def:libjq.def /out:libjq.lib /machine:x64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
EXPORTS | ||
_cgo_dummy_export | ||
cgoCurrentMillis | ||
cgoFilter |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Code generated by cmd/cgo; DO NOT EDIT. */ | ||
|
||
/* package _/install/platform-tools/kafkadesktopclient/src/gjq */ | ||
|
||
|
||
#line 1 "cgo-builtin-export-prolog" | ||
|
||
#include <stddef.h> /* for ptrdiff_t below */ | ||
|
||
#ifndef GO_CGO_EXPORT_PROLOGUE_H | ||
#define GO_CGO_EXPORT_PROLOGUE_H | ||
|
||
#ifndef GO_CGO_GOSTRING_TYPEDEF | ||
typedef struct { const char *p; ptrdiff_t n; } _GoString_; | ||
#endif | ||
|
||
#endif | ||
|
||
/* Start of preamble from import "C" comments. */ | ||
|
||
|
||
|
||
|
||
/* End of preamble from import "C" comments. */ | ||
|
||
|
||
/* Start of boilerplate cgo prologue. */ | ||
#line 1 "cgo-gcc-export-header-prolog" | ||
|
||
#ifndef GO_CGO_PROLOGUE_H | ||
#define GO_CGO_PROLOGUE_H | ||
|
||
typedef signed char GoInt8; | ||
typedef unsigned char GoUint8; | ||
typedef short GoInt16; | ||
typedef unsigned short GoUint16; | ||
typedef int GoInt32; | ||
typedef unsigned int GoUint32; | ||
typedef long long GoInt64; | ||
typedef unsigned long long GoUint64; | ||
typedef GoInt64 GoInt; | ||
typedef GoUint64 GoUint; | ||
#ifndef _WIN32 | ||
typedef __SIZE_TYPE__ GoUintptr; | ||
#endif | ||
typedef float GoFloat32; | ||
typedef double GoFloat64; | ||
#ifndef _WIN32 | ||
typedef float _Complex GoComplex64; | ||
typedef double _Complex GoComplex128; | ||
#endif | ||
/* | ||
static assertion to make sure the file is being used on architecture | ||
at least with matching size of GoInt. | ||
*/ | ||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; | ||
|
||
#ifndef GO_CGO_GOSTRING_TYPEDEF | ||
typedef _GoString_ GoString; | ||
#endif | ||
typedef void *GoMap; | ||
typedef void *GoChan; | ||
typedef struct { void *t; void *v; } GoInterface; | ||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; | ||
|
||
#endif | ||
|
||
/* End of boilerplate cgo prologue. */ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifdef _WIN32 | ||
// windows build | ||
extern __declspec(dllexport) long int cgoCurrentMillis(); | ||
extern __declspec(dllexport) char* cgoFilter(char* userQuery, char* jsonRequest); | ||
#else | ||
// Linux & Macos build | ||
extern long int cgoCurrentMillis(); | ||
extern char* cgoFilter(char* userQuery, char* jsonRequest); | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.