Skip to content

Commit

Permalink
internal/structfilter: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Sep 9, 2019
1 parent 9070859 commit 409e558
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ addons:
postgresql: "9.6"

go:
- 1.11.x
- 1.12.x
- 1.13.x
- tip

matrix:
allow_failures:
- go: 1.13.x
- go: tip

env:
Expand All @@ -21,4 +22,4 @@ go_import_path: github.com/go-pg/pg

before_install:
- psql -U postgres -c "CREATE EXTENSION hstore"
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.1
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ all:
go test ./... -short -race
go test ./... -run=NONE -bench=. -benchmem
env GOOS=linux GOARCH=386 go test ./...
go vet ./...
go get github.com/gordonklaus/ineffassign
ineffassign .
golangci-lint run
15 changes: 6 additions & 9 deletions internal/structfilter/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ func newField(sf reflect.StructField) *Field {
}

filterName := filterName(f.name)
const sep = "_"

if f.IsSlice {
f.Column, f.opCode, f.OpValue = splitSliceColumnOperator(filterName)
f.Column, f.opCode, f.OpValue = splitSliceColumnOperator(filterName, sep)
f.Scan = arrayScanner(sf.Type)
f.Append = types.ArrayAppender(sf.Type)
} else {
f.Column, f.opCode, f.OpValue = splitColumnOperator(filterName)
f.Column, f.opCode, f.OpValue = splitColumnOperator(filterName, sep)
f.Scan = scanner(sf.Type)
f.Append = types.Appender(sf.Type)
}
Expand All @@ -110,9 +112,7 @@ func (f *Field) Omit(value reflect.Value) bool {
return !f.required && f.noWhere || f.isZero(value)
}

func splitColumnOperator(s string) (string, opCode, string) {
const sep = "__"

func splitColumnOperator(s, sep string) (string, opCode, string) {
ind := strings.Index(s, sep)
if ind == -1 {
return s, opCodeEq, opEq
Expand Down Expand Up @@ -143,9 +143,7 @@ func splitColumnOperator(s string) (string, opCode, string) {
}
}

func splitSliceColumnOperator(s string) (string, opCode, string) {
const sep = "__"

func splitSliceColumnOperator(s, sep string) (string, opCode, string) {
ind := strings.Index(s, sep)
if ind == -1 {
return s, opCodeEq, opAny
Expand All @@ -166,6 +164,5 @@ func splitSliceColumnOperator(s string) (string, opCode, string) {

func filterName(s string) string {
s = internal.Underscore(s)
s = strings.ReplaceAll(s, "_", "__")
return s
}
2 changes: 1 addition & 1 deletion internal/structfilter/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewStruct(typ reflect.Type) *Struct {
}

func (s *Struct) Field(name string) *Field {
col, opCode, _ := splitColumnOperator(name)
col, opCode, _ := splitColumnOperator(name, "__")
for _, f := range s.Fields {
if f.Column == col && f.opCode == opCode {
return f
Expand Down

0 comments on commit 409e558

Please sign in to comment.