Skip to content

Commit

Permalink
Updated dependencies and Go version (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex authored Nov 16, 2022
1 parent 6331581 commit c108531
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.16
go-version: ^1.19
id: go

- name: Check out code into the Go module directory
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.16
go-version: ^1.19
- name: Set up env vars
run: |
export FERRET_VERSION=$(sh versions.sh ferret)
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,5 @@ bin
*.log
*.orig
dist
coverage.txt
coverage.txt
.private
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine AS builder
FROM golang:1.19-alpine AS builder

# Install git.
# Git is required for fetching the dependencies.
Expand All @@ -13,7 +13,7 @@ COPY . .
RUN CGO_ENABLED=0 GOOS=linux make compile

# Build the final container. And install
FROM montferret/chromium:99.0.4844.0 as runner
FROM montferret/chromium:106.0.5249.0 as runner

RUN apt-get update && apt-get install -y dumb-init

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM montferret/chromium:99.0.4844.0
FROM montferret/chromium:106.0.5249.0

RUN apt-get update && apt-get install -y dumb-init ca-certificates

Expand Down
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
module github.com/MontFerret/worker

go 1.17
go 1.19

require (
github.com/MontFerret/ferret v0.16.6
github.com/MontFerret/ferret v0.16.7
github.com/go-waitfor/waitfor v1.0.0
github.com/go-waitfor/waitfor-http v1.0.0
github.com/hashicorp/golang-lru v0.5.4
github.com/labstack/echo/v4 v4.6.3
github.com/hashicorp/golang-lru/v2 v2.0.1
github.com/labstack/echo/v4 v4.9.1
github.com/namsral/flag v1.7.4-pre
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.26.1
github.com/ziflex/lecho/v3 v3.1.0
github.com/rs/zerolog v1.28.0
github.com/ziflex/lecho/v3 v3.3.0
)

require (
github.com/PuerkitoBio/goquery v1.8.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/antchfx/htmlquery v1.2.4 // indirect
github.com/antchfx/xpath v1.2.0 // indirect
github.com/antchfx/htmlquery v1.2.5 // indirect
github.com/antchfx/xpath v1.2.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211211185417-43fb4c2dbe28 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/corpix/uarand v0.1.1 // indirect
Expand All @@ -27,18 +27,18 @@ require (
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/labstack/gommon v0.3.1 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/mafredri/cdp v0.32.0 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/sethgrid/pester v1.1.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/wI2L/jettison v0.7.3 // indirect
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e // indirect
github.com/wI2L/jettison v0.7.4 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
)
100 changes: 30 additions & 70 deletions go.sum

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions internal/storage/cache.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package storage

import (
"github.com/hashicorp/golang-lru"
"github.com/MontFerret/ferret/pkg/runtime"
"github.com/hashicorp/golang-lru/v2"

"github.com/MontFerret/worker/pkg/caching"
)

type InMemoryCache struct {
store *lru.Cache
store *lru.Cache[string, *runtime.Program]
}

func NewCache(opts ...caching.Option) (caching.Cache, error) {
func NewCache(opts ...caching.Option) (caching.Cache[*runtime.Program], error) {
options := caching.NewOptions(opts...)

store, err := lru.New(int(options.Size))
store, err := lru.New[string, *runtime.Program](int(options.Size))

if err != nil {
return nil, err
Expand All @@ -22,14 +23,14 @@ func NewCache(opts ...caching.Option) (caching.Cache, error) {
return &InMemoryCache{store}, nil
}

func (cache *InMemoryCache) Set(key, value interface{}) {
func (cache *InMemoryCache) Set(key string, value *runtime.Program) {
cache.store.Add(key, value)
}

func (cache *InMemoryCache) Get(key interface{}) (interface{}, bool) {
func (cache *InMemoryCache) Get(key string) (*runtime.Program, bool) {
return cache.store.Get(key)
}

func (cache *InMemoryCache) Contains(key interface{}) bool {
func (cache *InMemoryCache) Contains(key string) bool {
return cache.store.Contains(key)
}
8 changes: 4 additions & 4 deletions pkg/caching/cache.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package caching

type Cache interface {
Set(key, value interface{})
type Cache[T any] interface {
Set(key string, value T)

Get(key interface{}) (interface{}, bool)
Get(key string) (T, bool)

Contains(key interface{}) bool
Contains(key string) bool
}
5 changes: 3 additions & 2 deletions pkg/worker/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package worker
import (
"fmt"

"github.com/MontFerret/ferret/pkg/runtime"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/worker/pkg/caching"
)
Expand All @@ -17,7 +18,7 @@ type (
functions []core.Functions
noStdlib bool
cdp CDPSettings
cache caching.Cache
cache caching.Cache[*runtime.Program]
}

Option func(opts *Options)
Expand Down Expand Up @@ -59,7 +60,7 @@ func WithCustomCDP(cdp CDPSettings) Option {
}
}

func WithCache(cache caching.Cache) Option {
func WithCache(cache caching.Cache[*runtime.Program]) Option {
return func(opts *Options) {
opts.cache = cache
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
type Worker struct {
comp *compiler.Compiler
drivers []drivers.Driver
cache caching.Cache
cache caching.Cache[*runtime.Program]
}

// New returns Worker without file system access.
Expand Down Expand Up @@ -87,7 +87,7 @@ func (w *Worker) compiledOrCached(text string) (*runtime.Program, error) {
found, isFound := w.cache.Get(text)

if isFound && found != nil {
program = found.(*runtime.Program)
program = found
}
}

Expand Down
36 changes: 24 additions & 12 deletions reference/ferret-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ paths:
description: OK
schema:
$ref: '#/definitions/QueryResult'
'400':
description: Bad Request
schema:
$ref: '#/definitions/Error'
'500':
description: Internal Server Error
schema:
$ref: '#/definitions/Error'
description: Execute a query.
parameters:
- in: body
Expand Down Expand Up @@ -124,15 +132,19 @@ definitions:
- text
QueryResult:
title: Result
anyOf:
- type: object
- type: array
items: {}
- type: string
properties: {}
- type: number
properties: {}
- type: boolean
properties: {}
- properties: {}
x-nullable: true
type:
- object
- string
- number
- integer
- boolean
- array
x-nullable: true
Error:
title: Error
type: object
properties:
error:
type: string
required:
- error

0 comments on commit c108531

Please sign in to comment.