Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 22 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,27 @@
on: [push, pull_request]
name: CI
jobs:
build-test-lint:
test:
runs-on: ubuntu-latest
steps:
# Prepare
- name: Install Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Checkout repository
uses: actions/checkout@v2

# TESTS

# Run all tests
- name: Test
run: go test -v -race ./...

# TEST COVERAGE

- name: Calculate coverage
run: |
go test -v -covermode=count -coverprofile=coverage.out
- name: Convert coverage.out to coverage.lcov
uses: jandelgado/gcov2lcov-action@v1.0.6
- name: Coveralls
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov

# LINT

# Install golangci-lint
- name: Install golangci-lint
run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2

# go vet
- name: go vet
continue-on-error: true
run: go vet ./...

# golangci-lint
- name: golangci-lint
continue-on-error: true
run: golangci-lint run ./...
- name: Install Go 1.20
uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true
- name: Checkout repository
uses: actions/checkout@v3
- name: Test
run: go test -v -race ./...
- name: Calculate coverage
run: go test -v -covermode=count -coverprofile=coverage.out
- name: Convert coverage.out to coverage.lcov
uses: jandelgado/gcov2lcov-action@v1.0.9
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
- name: Run go vet
continue-on-error: true
run: go vet ./...
46 changes: 46 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
13 changes: 6 additions & 7 deletions cmd/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,22 @@ func main() {
totalDur := timeEnd.Sub(timeStart)
tb, te := atomic.LoadUint64(&totalBytes), atomic.LoadUint64(&totalErrs)
bytesPerSec := math.Floor(float64(tb) / totalDur.Seconds())
var bps string
if mbps := bytesPerSec / 1024 / 1024 * 8; mbps >= 1000 {
bps = fmt.Sprintf("%.2f gbit/s", bytesPerSec/1024/1024/1024*8)
} else {
bps = fmt.Sprintf("%.2f mbit/s", mbps)
}
bps := fmt.Sprintf("%.2f gbit/s", gbits(float64(tb), totalDur.Seconds()))

fmt.Printf(
"finished (%s)\ntotal processed: %s (%s/s; %s)\ntotal errors: %s\n",
totalDur,
totalDur.String(),
humanize.Bytes(tb),
humanize.Bytes(uint64(bytesPerSec)),
bps,
humanize.Comma(int64(te)),
)
}

func gbits(totalBytes, seconds float64) float64 {
return ((totalBytes * 8) / 1e9) / seconds
}

func find(root, ext string, fn func(path string)) error {
return filepath.WalkDir(root, func(s string, d fs.DirEntry, e error) error {
if e != nil {
Expand Down
14 changes: 2 additions & 12 deletions cmd/gen/templates/false.gotmpl
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
if i.head+5 < len(i.str) &&
lutEndVal[i.str[i.head+5]] == 1 &&
i.str[i.head+4] == 'e' &&
i.str[i.head+3] == 's' &&
i.str[i.head+2] == 'l' &&
i.str[i.head+1] == 'a' &&
i.str[i.head] == 'f' &&
(i.str[i.head+5] == ' ' ||
i.str[i.head+5] == '\t' ||
i.str[i.head+5] == '\r' ||
i.str[i.head+5] == '\n' ||
i.str[i.head+5] == ',' ||
i.str[i.head+5] == ')' ||
i.str[i.head+5] == '}' ||
i.str[i.head+5] == '{' ||
i.str[i.head+5] == ']' ||
i.str[i.head+5] == '[' ||
i.str[i.head+5] == '#') {
i.str[i.head] == 'f' {
i.tail = -1
i.head += len("false")

Expand Down
126 changes: 92 additions & 34 deletions cmd/gen/templates/gqlscan.gotmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Code generated by github.com/graph-guard/gqlgen/cmd/gen, DO NOT EDIT.

package gqlscan

Expand Down Expand Up @@ -263,39 +262,6 @@ func (i *Iterator) ScanInterpreted(
}
}

// isHeadDigit returns true if the current head is
// a number start character, otherwise returns false.
func (i *Iterator) isHeadDigit() bool {
switch i.str[i.head] {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
return true
}
return false
}

// isHeadDigit returns true if the current head is
// a number start character, otherwise returns false.
func (i *Iterator) isHeadHexDigit() bool {
switch i.str[i.head] {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f',
'A', 'B', 'C', 'D', 'E', 'F':
return true
}
return false
}

// isHeadNumEnd returns true if the current head is a space, line-feed,
// horizontal tab, carriage-return, comma, right parenthesis or
// right curly brace, otherwise returns false.
func (i *Iterator) isHeadNumEnd() bool {
switch i.str[i.head] {
case ' ', '\t', '\r', '\n', ',', ')', '}', ']', '#':
return true
}
return false
}

// isHeadKeywordQuery returns true if the current head equals 'query'.
func (i *Iterator) isHeadKeywordQuery() bool {
return i.head+4 < len(i.str) &&
Expand Down Expand Up @@ -681,3 +647,95 @@ const (
dirFragRef
dirFragInlineOrDef
)

// lutStr maps 0 to all bytes that don't require checking during string traversal.
// 1 is mapped to control, quotation mark (") and reverse solidus ("\").
// All other characters are mapped to 0.
var lutStr = [256]byte{
0x00: 1, 0x01: 1, 0x02: 1, 0x03: 1, 0x04: 1, 0x05: 1, 0x06: 1, 0x07: 1,
0x08: 1, 0x0b: 1, 0x0c: 1, 0x0e: 1, 0x0f: 1, 0x10: 1, 0x11: 1, 0x12: 1,
0x13: 1, 0x14: 1, 0x15: 1, 0x16: 1, 0x17: 1, 0x18: 1, 0x19: 1, 0x1a: 1,
0x1b: 1, 0x1c: 1, 0x1d: 1, 0x1e: 1, 0x1f: 1,

'\\': 1, '"': 1,
}

// lutHex maps valid hex digits to 2. All other characters are mapped to 0.
var lutHex = [256]byte{
'0': 2, '1': 2, '2': 2, '3': 2, '4': 2, '5': 2, '6': 2, '7': 2, '8': 2, '9': 2,
'a': 2, 'b': 2, 'c': 2, 'd': 2, 'e': 2, 'f': 2,
'A': 2, 'B': 2, 'C': 2, 'D': 2, 'E': 2, 'F': 2,
}

// lutIrrel maps irrelevant characters such as comma, whitespace,
// line-break, tab and carriage-return to 1.
// All other characters are mapped to 0.
var lutIrrel = [256]byte{
',': 1, ' ': 1, '\n': 1, '\t': 1, '\r': 1,
}

// lutEndVal maps characters that can appear at the
// end of a value to 1. All other characters are mapped to 0.
var lutEndVal = [256]byte{
' ': 1, '\t': 1, '\r': 1, '\n': 1,
',': 1, ')': 1, '}': 1, '{': 1, ']': 1, '[': 1, '#': 1,
}

// lutEndNum maps characters that can appear at the
// end of a number value to 1. All other characters are mapped to 0.
var lutEndNum = [256]byte{
' ': 1, '\t': 1, '\r': 1, '\n': 1, ',': 1, ')': 1, '}': 1, ']': 1, '#': 1,
}


// lutName maps:
// characters names can start with to 1,
// characters names can contain to <3,
// digit characters to 2.
// characters names can end at to 3,
// illegal control characters to 5,
// all other characters to 4.
var lutName = [256]byte{
'_': 1,

'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1, 'F': 1, 'G': 1,
'H': 1, 'I': 1, 'J': 1, 'K': 1, 'L': 1, 'M': 1, 'N': 1,
'O': 1, 'P': 1, 'Q': 1, 'R': 1, 'S': 1, 'T': 1, 'U': 1,
'V': 1, 'W': 1, 'X': 1, 'Y': 1, 'Z': 1,

'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 1, 'g': 1,
'h': 1, 'i': 1, 'j': 1, 'k': 1, 'l': 1, 'm': 1, 'n': 1,
'o': 1, 'p': 1, 'q': 1, 'r': 1, 's': 1, 't': 1, 'u': 1,
'v': 1, 'w': 1, 'x': 1, 'y': 1, 'z': 1,

'0': 2, '1': 2, '2': 2, '3': 2, '4': 2, '5': 2,
'6': 2, '7': 2, '8': 2, '9': 2,

',': 3, ' ': 3, '\n': 3, '\t': 3, '\r': 3,

0x21: 4, 0x22: 4, 0x23: 4, 0x24: 4, 0x25: 4, 0x26: 4, 0x27: 4, 0x28: 4,
0x29: 4, 0x2a: 4, 0x2b: 4, 0x2d: 4, 0x2e: 4, 0x2f: 4, 0x3a: 4, 0x3b: 4,
0x3c: 4, 0x3d: 4, 0x3e: 4, 0x3f: 4, 0x40: 4, 0x5b: 4, 0x5c: 4, 0x5d: 4,
0x5e: 4, 0x60: 4, 0x7b: 4, 0x7c: 4, 0x7d: 4, 0x7e: 4, 0x7f: 4, 0x80: 4,
0x81: 4, 0x82: 4, 0x83: 4, 0x84: 4, 0x85: 4, 0x86: 4, 0x87: 4, 0x88: 4,
0x89: 4, 0x8a: 4, 0x8b: 4, 0x8c: 4, 0x8d: 4, 0x8e: 4, 0x8f: 4, 0x90: 4,
0x91: 4, 0x92: 4, 0x93: 4, 0x94: 4, 0x95: 4, 0x96: 4, 0x97: 4, 0x98: 4,
0x99: 4, 0x9a: 4, 0x9b: 4, 0x9c: 4, 0x9d: 4, 0x9e: 4, 0x9f: 4, 0xa0: 4,
0xa1: 4, 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