Skip to content

Commit

Permalink
rename package to validator-go
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed Sep 22, 2024
1 parent d4c6f8d commit 74220cd
Show file tree
Hide file tree
Showing 121 changed files with 816 additions and 690 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Fetch dependencies
run: go mod download -x
- name: Install tools
run: go install -x github.com/kisielk/errcheck golang.org/x/lint/golint github.com/goccmack/gocc github.com/awalterschulze/goderive github.com/gogo/protobuf
- name: Generate
run: make regenerate
- name: Build
run: make build
- name: Test
run: make test
- vet:
run: make vet
- errcheck:
run: make errcheck
- checklicencse:
run: make checklicense
- diff:
run: make diff
9 changes: 5 additions & 4 deletions encode/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//Package json encodes a parser.Interface into json.
//This can be used for transcoding or marshaling.
// Package json encodes a parser.Interface into json.
// This can be used for transcoding or marshaling.
package json

import (
"encoding/base64"
"encoding/json"
"github.com/katydid/katydid/parser"
"io"

"github.com/katydid/validator-go/parser"
)

//Encode encodes a parser.Interface into a byte slice containing valid json.
// Encode encodes a parser.Interface into a byte slice containing valid json.
func Encode(p parser.Interface) ([]byte, error) {
m, err := encode(p)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions encode/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"reflect"
"testing"

jsonparser "github.com/katydid/katydid/parser/json"
reflectparser "github.com/katydid/katydid/parser/reflect"
jsonparser "github.com/katydid/validator-go/parser/json"
reflectparser "github.com/katydid/validator-go/parser/reflect"
)

func testTranscode(t *testing.T, input interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions encode/proto/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"testing"

"github.com/gogo/protobuf/proto"
. "github.com/katydid/katydid/encode/proto/prototests"
reflectparser "github.com/katydid/katydid/parser/reflect"
. "github.com/katydid/validator-go/encode/proto/prototests"
reflectparser "github.com/katydid/validator-go/parser/reflect"
)

func BenchmarkMarshalSimple(b *testing.B) {
Expand Down
21 changes: 11 additions & 10 deletions encode/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,32 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//Package proto encodes a parser.Interface into marshaled protocol buffer.
//This can be used for transcoding or dynamic marshaling.
//Dynamic marshaling is when the protocol buffer has not been compiled into the source and only the descriptor struct is available.
// Package proto encodes a parser.Interface into marshaled protocol buffer.
// This can be used for transcoding or dynamic marshaling.
// Dynamic marshaling is when the protocol buffer has not been compiled into the source and only the descriptor struct is available.
//
//TODO: more tests
// TODO: more tests
//
//TODO: support for packed, proto3, maps, etc.
// TODO: support for packed, proto3, maps, etc.
package proto

import (
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
"github.com/katydid/katydid/parser"
protoparser "github.com/katydid/katydid/parser/proto"
"io"
"math"

"github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
"github.com/katydid/validator-go/parser"
protoparser "github.com/katydid/validator-go/parser/proto"
)

const maxVarintSize = 10

//Encoder encodes a parser.Interface into a byte slice containing marshaled protocol buffer.
// Encoder encodes a parser.Interface into a byte slice containing marshaled protocol buffer.
type Encoder interface {
Encode([]byte, parser.Interface) ([]byte, error)
}

//NewEncoder returns an Encoder that can marshal a parser.Interface into the specified protocol buffer message.
// NewEncoder returns an Encoder that can marshal a parser.Interface into the specified protocol buffer message.
func NewEncoder(desc *descriptor.FileDescriptorSet, pkgName, msgName string) (Encoder, error) {
descMap, err := protoparser.NewDescriptorMap(pkgName, msgName, desc)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions encode/proto/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"time"

"github.com/gogo/protobuf/proto"
"github.com/katydid/katydid/encode/proto/prototests"
reflectparser "github.com/katydid/katydid/parser/reflect"
"github.com/katydid/validator-go/encode/proto/prototests"
reflectparser "github.com/katydid/validator-go/parser/reflect"
)

func makeEmptyNil(v reflect.Value) {
Expand Down
9 changes: 5 additions & 4 deletions encode/reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//Package reflect encodes a parser.Interface into a reflected go structure.
//This can be used to unmarshal or copy.
// Package reflect encodes a parser.Interface into a reflected go structure.
// This can be used to unmarshal or copy.
package reflect

import (
"fmt"
"github.com/katydid/katydid/parser"
"io"
"reflect"

"github.com/katydid/validator-go/parser"
)

//Encode encodes a parser.Interface into a go structure value.
// Encode encodes a parser.Interface into a go structure value.
func Encode(p parser.Interface, v interface{}) error {
r := reflect.ValueOf(v)
return encodeStruct(p, r)
Expand Down
3 changes: 2 additions & 1 deletion encode/reflect/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package reflect

import (
reflectparser "github.com/katydid/katydid/parser/reflect"
"reflect"
"testing"

reflectparser "github.com/katydid/validator-go/parser/reflect"
)

func testCopy(t *testing.T, input interface{}) {
Expand Down
11 changes: 6 additions & 5 deletions encode/xml/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//Package xml encodes a parser.Interface into xml.
//This can be used for transcoding.
// Package xml encodes a parser.Interface into xml.
// This can be used for transcoding.
//
//TODO: currently only handles very naive cases, more tests would help.
// TODO: currently only handles very naive cases, more tests would help.
package xml

import (
"bytes"
"encoding/base64"
"encoding/xml"
"github.com/katydid/katydid/parser"
"io"
"strconv"

"github.com/katydid/validator-go/parser"
)

//Encode encodes a parser.Interface into a byte slice containing valid xml.
// Encode encodes a parser.Interface into a byte slice containing valid xml.
func Encode(p parser.Interface) ([]byte, error) {
buf := bytes.NewBuffer(nil)
e := xml.NewEncoder(buf)
Expand Down
3 changes: 2 additions & 1 deletion encode/xml/xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ package xml

import (
"encoding/xml"
xmlparser "github.com/katydid/katydid/parser/xml"
"reflect"
"testing"

xmlparser "github.com/katydid/validator-go/parser/xml"
)

func testTranscode(t *testing.T, input interface{}) {
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/katydid/validator-go

go 1.19

require github.com/gogo/protobuf v1.3.2
31 changes: 31 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10 changes: 0 additions & 10 deletions install-godeps.sh

This file was deleted.

9 changes: 0 additions & 9 deletions install-protobuf.sh

This file was deleted.

2 changes: 1 addition & 1 deletion parser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

regenerate:
go install github.com/katydid/katydid/parser/parser-gen
go install github.com/katydid/validator-go/parser/parser-gen
parser-gen ./
cd debug && make regenerate
cd proto && make regenerate
Expand Down
2 changes: 1 addition & 1 deletion parser/debug/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

regenerate:
go install github.com/katydid/katydid/parser/debug/debug-gen
go install github.com/katydid/validator-go/parser/debug/debug-gen
debug-gen ./
(protoc --gogo_out=. -I=.:../../../../../:../../../../../github.com/gogo/protobuf/protobuf debug.proto)

Expand Down
6 changes: 3 additions & 3 deletions parser/debug/debug-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//Command debug-gen generates some of the code in the debug package.
// Command debug-gen generates some of the code in the debug package.
package main

import (
"strings"

"github.com/katydid/katydid/gen"
"github.com/katydid/validator-go/gen"
)

type valuer struct {
Expand Down Expand Up @@ -60,5 +60,5 @@ func main() {
&valuer{"Bool", "bool", "false"},
&valuer{"String", "string", `""`},
&valuer{"Bytes", "[]byte", "nil"},
}, `"github.com/katydid/katydid/parser"`)
}, `"github.com/katydid/validator-go/parser"`)
}
13 changes: 7 additions & 6 deletions parser/debug/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
package debug

import (
"github.com/katydid/katydid/parser"
"log"
"os"
"path/filepath"
"runtime"
"strconv"
"time"

"github.com/katydid/validator-go/parser"
)

//Logger is an interface for a type that is made to log debug info.
// Logger is an interface for a type that is made to log debug info.
type Logger interface {
Printf(format string, v ...interface{})
}

//NewLineLogger returns a logger that logs the line at which the Printf method was called to stderr.
// NewLineLogger returns a logger that logs the line at which the Printf method was called to stderr.
func NewLineLogger() Logger {
return &line{log.New(os.Stderr, "", 0)}
}
Expand Down Expand Up @@ -61,8 +62,8 @@ func (l *line) Printf(format string, v ...interface{}) {
}
}

//NewDelayLogger returns a logger that sleeps after every log.
//This is useful for debugging infinite loops.
// NewDelayLogger returns a logger that sleeps after every log.
// This is useful for debugging infinite loops.
func NewDelayLogger(delay time.Duration) Logger {
return &d{
delay: delay,
Expand All @@ -87,7 +88,7 @@ type l struct {
copies int
}

//NewLogger returns a parser that when called returns and logs the value returned by the argument parser to the argument logger.
// NewLogger returns a parser that when called returns and logs the value returned by the argument parser to the argument logger.
func NewLogger(s parser.Interface, logger Logger) parser.Interface {
return &l{"parser", s, logger, 0}
}
Expand Down
2 changes: 1 addition & 1 deletion parser/debug/value.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 74220cd

Please sign in to comment.