Skip to content
Merged
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
11 changes: 8 additions & 3 deletions .github/workflows/ci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.23.4
- uses: golangci/golangci-lint-action@v6
with:
version: v1.62.2
- name: install golangci-lint
run:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.60.3
- name: lint
run: |
go version
$GITHUB_WORKSPACE/golangci-lint version
$GITHUB_WORKSPACE/golangci-lint --config .golangci.yml run
37 changes: 19 additions & 18 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
service:
golangci-lint-version: 1.51.x
golangci-lint-version: 1.60.3

run:
timeout: 2m
exclude-dirs:
- vendor

linters-settings:
govet:
shadow: true
revive:
min-confidence: 0.1
rules:
# Add more comments for exported functions and remove this rule
- name: package-comments
disabled: true
maligned:
suggest-new: true
goconst:
Expand All @@ -24,46 +16,55 @@ linters-settings:
locale: US
lll:
line-length: 140
revive:
min-confidence: 0.1
rules:
# Add more comments for exported functions and remove this rule
- name: package-comments
disabled: true

linters:
enable:
- bodyclose
- revive
- govet
- unconvert
- gosec
- gocyclo
- dupl
- misspell
- unparam
- typecheck
- ineffassign
- stylecheck
- gochecknoinits
- gocritic
- copyloopvar
- nakedret
- gosimple
- prealloc
- unused
- goimports
- gofmt
- errcheck
- staticcheck
- exportloopref

## format - fill free to fix
# - errcheck
# - gofmt
fast: false
disable-all: true
disable:
- dupl

issues:
exclude-rules:
# - Fix and remove
# - Fix and remove
- text: "at least one file in a package should have a package comment"
linters:
- stylecheck
# - Fix and remove
- text: "should have a package comment, unless it's in another file for this package"
# - Fix and remove
- text: "package-comments: should have a package comment"
linters:
- revive
- text: "shadow: declaration of \"err\" shadows declaration"
linters:
- govet
- path: _test\.go
linters:
- gosec
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/iden3/go-schema-processor/v2
go 1.18

require (
github.com/iden3/go-iden3-core/v2 v2.3.1
github.com/iden3/go-iden3-core/v2 v2.3.2
github.com/iden3/go-iden3-crypto v0.0.17
github.com/iden3/go-merkletree-sql/v2 v2.0.4
// We require the `json-gold` bugfix which has not yet been included in the
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/blake512 v1.0.0 h1:oDFEQFIqFSeuA34xLtXZ/rWxCXdSjirjzPhey5EUvmA=
github.com/dchest/blake512 v1.0.0/go.mod h1:FV1x7xPPLWukZlpDpWQ88rF/SFwZ5qbskrzhLMB92JI=
github.com/iden3/go-iden3-core/v2 v2.3.1 h1:ytQqiclnVAIWyRKR2LF31hfz4DGRBD6nMjiPILXGSKk=
github.com/iden3/go-iden3-core/v2 v2.3.1/go.mod h1:8vmG6y8k9VS7iNoxuiKukKbRQFsMyabCc+i8er07zOs=
github.com/iden3/go-iden3-core/v2 v2.3.2 h1:kZq/TiSUmBKO/mvPUucfFE45ugTW+hXXlGT+Jf6CQTg=
github.com/iden3/go-iden3-core/v2 v2.3.2/go.mod h1:8vmG6y8k9VS7iNoxuiKukKbRQFsMyabCc+i8er07zOs=
github.com/iden3/go-iden3-crypto v0.0.17 h1:NdkceRLJo/pI4UpcjVah4lN/a3yzxRUGXqxbWcYh9mY=
github.com/iden3/go-iden3-crypto v0.0.17/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E=
github.com/iden3/go-merkletree-sql/v2 v2.0.4 h1:Dp089P3YNX1BE8+T1tKQHWTtnk84Y/Kr7ZAGTqwscoY=
Expand Down
7 changes: 7 additions & 0 deletions loaders/document_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ const (

var rApplicationJSON = regexp.MustCompile(`^application/(\w*\+)?json$`)

// ErrCacheMiss is an error when there is no info in cache
var ErrCacheMiss = errors.New("cache miss")

// CacheEngine is engine interface for cache storages
type CacheEngine interface {
Get(key string) (doc *ld.RemoteDocument, expireTime time.Time, err error)
Set(key string, doc *ld.RemoteDocument, expireTime time.Time) error
}

// IPFSClient interface
type IPFSClient interface {
Cat(url string) (io.ReadCloser, error)
}
Expand All @@ -42,8 +45,10 @@ type documentLoader struct {
httpClient *http.Client
}

// DocumentLoaderOption is an option for document loader
type DocumentLoaderOption func(*documentLoader)

// WithCacheEngine is an option for setting cache
func WithCacheEngine(cacheEngine CacheEngine) DocumentLoaderOption {
return func(loader *documentLoader) {
if cacheEngine == nil {
Expand All @@ -55,6 +60,7 @@ func WithCacheEngine(cacheEngine CacheEngine) DocumentLoaderOption {
}
}

// WithHTTPClient is an option for setting http client
func WithHTTPClient(httpClient *http.Client) DocumentLoaderOption {
return func(loader *documentLoader) {
loader.httpClient = httpClient
Expand Down Expand Up @@ -82,6 +88,7 @@ func NewDocumentLoader(ipfsCli IPFSClient, ipfsGW string,
return loader
}

// LoadDocument loads document from ipfs or http / https source
func (d *documentLoader) LoadDocument(
u string) (doc *ld.RemoteDocument, err error) {

Expand Down
3 changes: 3 additions & 0 deletions loaders/memory_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ func (m *memoryCacheEngine) Set(key string, doc *ld.RemoteDocument,
return nil
}

// MemoryCacheEngineOption is an option to set cache engine
type MemoryCacheEngineOption func(*memoryCacheEngine) error

// WithEmbeddedDocumentBytes sets bytes for given url
func WithEmbeddedDocumentBytes(u string, doc []byte) MemoryCacheEngineOption {
return func(engine *memoryCacheEngine) error {
if engine.embedDocs == nil {
Expand All @@ -81,6 +83,7 @@ func WithEmbeddedDocumentBytes(u string, doc []byte) MemoryCacheEngineOption {
}
}

// NewMemoryCacheEngine creates new memory cache engine
func NewMemoryCacheEngine(
opts ...MemoryCacheEngineOption) (CacheEngine, error) {

Expand Down
3 changes: 3 additions & 0 deletions testing/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ type mockHTTPClientOptions struct {
ignoreUntouchedURLs bool
}

// MockHTTPClientOption is mock for http client for tests
type MockHTTPClientOption func(*mockHTTPClientOptions)

// IgnoreUntouchedURLs is option to ignore unused urls
func IgnoreUntouchedURLs() MockHTTPClientOption {
return func(opts *mockHTTPClientOptions) {
opts.ignoreUntouchedURLs = true
}
}

// MockHTTPClient is mocked http client
func MockHTTPClient(t testing.TB, routes map[string]string,
opts ...MockHTTPClientOption) func() {

Expand Down
2 changes: 1 addition & 1 deletion verifiable/did_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (a *Authentication) UnmarshalJSON(b []byte) error {
if err != nil {
return errors.Errorf("invalid json payload for authentication: %v", err)
}
*a = (Authentication)(tmp)
*a = Authentication(tmp)
case '"':
err := json.Unmarshal(b, &a.did)
if err != nil {
Expand Down