Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

[chore] Fmt any and goimports #207

Merged
merged 4 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ linters:
- errcheck
- errorlint
- gocritic
- goimports
- gosec
- govet
- ineffassign
Expand Down
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package config

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestConfig(t *testing.T) {
Expand Down
13 changes: 7 additions & 6 deletions integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ package integration
import (
"bytes"
"embed"
cmpact "github.com/goccy/go-json"
"github.com/goccy/go-json"
"fmt"
"io"
"net/http"
"strings"

manifestsdk "github.com/TBD54566975/ssi-sdk/credential/manifest"
"github.com/TBD54566975/ssi-sdk/crypto"
"github.com/goccy/go-json"
cmpact "github.com/goccy/go-json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't add this but we don't need the alias

"github.com/mr-tron/base58"
"github.com/oliveagle/jsonpath"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
credmodel "github.com/tbd54566975/ssi-service/internal/credential"
"github.com/tbd54566975/ssi-service/internal/keyaccess"
"io"
"net/http"
"strings"
)

const (
Expand Down Expand Up @@ -151,7 +152,7 @@ func compactJSONOutput(json string) string {
}

func getJSONElement(jsonString string, jsonPath string) (string, error) {
jsonMap := make(map[string]interface{})
jsonMap := make(map[string]any)
if err := json.Unmarshal([]byte(jsonString), &jsonMap); err != nil {
return "", errors.Wrap(err, "unmarshalling json string")
}
Expand Down
3 changes: 2 additions & 1 deletion integration/credential_revocation_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package integration

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

var credentialRevocationContext = NewTestContext("CredentialRevocation")
Expand Down
3 changes: 2 additions & 1 deletion integration/didweb_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package integration

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

var didWebContext = NewTestContext("DIDWeb")
Expand Down
3 changes: 2 additions & 1 deletion integration/steelthread_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package integration

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

var steelThreadContext = NewTestContext("SteelThread")
Expand Down
11 changes: 6 additions & 5 deletions integration/testutil.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
package integration

import (
"github.com/pkg/errors"
"sync"

"github.com/pkg/errors"
)

type TestContext struct {
testName string
values map[string]interface{}
values map[string]any
}

var globalMutex sync.RWMutex

func NewTestContext(testName string) *TestContext {
return &TestContext{
testName: testName,
values: make(map[string]interface{}),
values: make(map[string]any),
}
}

// SetValue sets a value in the test context.
func SetValue(ctx *TestContext, key string, value interface{}) {
func SetValue(ctx *TestContext, key string, value any) {
globalMutex.RLock()
defer globalMutex.RUnlock()
ctx.values[key] = value
}

// GetValue retrieves a value from the test context.
func GetValue(ctx *TestContext, key string) (interface{}, error) {
func GetValue(ctx *TestContext, key string) (any, error) {
globalMutex.RLock()
defer globalMutex.RUnlock()
value, ok := ctx.values[key]
Expand Down
10 changes: 5 additions & 5 deletions internal/credential/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewCredentialContainerFromJWT(credentialJWT string) (*Container, error) {

// NewCredentialContainerFromMap attempts to parse a data integrity credential from a piece of JSON,
// which is represented as a map in go, into a Container
func NewCredentialContainerFromMap(credMap map[string]interface{}) (*Container, error) {
func NewCredentialContainerFromMap(credMap map[string]any) (*Container, error) {
var cred credential.VerifiableCredential
credMapBytes, err := json.Marshal(credMap)
if err != nil {
Expand All @@ -76,8 +76,8 @@ func NewCredentialContainerFromMap(credMap map[string]interface{}) (*Container,
return nil, errors.New("credential does not have a data integrity proof")
}

func ContainersToInterface(cs []Container) []interface{} {
var credentials []interface{}
func ContainersToInterface(cs []Container) []any {
var credentials []any
for _, container := range cs {
if container.HasDataIntegrityCredential() {
credentials = append(credentials, *container.Credential)
Expand All @@ -90,7 +90,7 @@ func ContainersToInterface(cs []Container) []interface{} {

// NewCredentialContainerFromArray attempts to parse arrays of credentials of any type (either data integrity or JWT)
// into an array of CredentialContainers. The method will return an error if any of the credentials are invalid.
func NewCredentialContainerFromArray(creds []interface{}) ([]Container, error) {
func NewCredentialContainerFromArray(creds []any) ([]Container, error) {
var containers []Container
for _, c := range creds {
switch v := c.(type) {
Expand All @@ -101,7 +101,7 @@ func NewCredentialContainerFromArray(creds []interface{}) ([]Container, error) {
return nil, errors.Wrap(err, "could not parse credential from JWT")
}
containers = append(containers, *container)
case map[string]interface{}:
case map[string]any:
// JSON
container, err := NewCredentialContainerFromMap(v)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/did/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package did
import (
"crypto"
"fmt"

"github.com/TBD54566975/ssi-sdk/cryptosuite"
didsdk "github.com/TBD54566975/ssi-sdk/did"
"github.com/goccy/go-json"
Expand Down
3 changes: 2 additions & 1 deletion internal/did/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"crypto"
"crypto/ed25519"
"fmt"
"testing"

"github.com/TBD54566975/ssi-sdk/did"
"github.com/stretchr/testify/assert"
"testing"
)

func TestGetVerificationInformation(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions internal/keyaccess/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ func JWTPtr(j string) *JWT {
}

// SignJSON takes an object that is either itself json or json-serializable and signs it.
func (ka JWKKeyAccess) SignJSON(data interface{}) (*JWT, error) {
func (ka JWKKeyAccess) SignJSON(data any) (*JWT, error) {
if ka.JWTSigner == nil {
return nil, errors.New("cannot sign with nil signer")
}
jsonBytes, err := json.Marshal(data)
if err != nil {
return nil, err
}
payload := make(map[string]interface{})
payload := make(map[string]any)
if err = json.Unmarshal(jsonBytes, &payload); err != nil {
return nil, err
}
return ka.Sign(payload)
}

func (ka JWKKeyAccess) Sign(payload map[string]interface{}) (*JWT, error) {
func (ka JWKKeyAccess) Sign(payload map[string]any) (*JWT, error) {
if ka.JWTSigner == nil {
return nil, errors.New("cannot sign with nil signer")
}
Expand Down
10 changes: 5 additions & 5 deletions internal/keyaccess/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestJWKKeyAccessForEachKeyType(t *testing.T) {
testKID := "test-kid"
testData := map[string]interface{}{
testData := map[string]any{
"test": "data",
}

Expand Down Expand Up @@ -99,7 +99,7 @@ func TestJWKKeyAccessSignVerify(t *testing.T) {
assert.NoError(tt, err)
assert.NotEmpty(tt, ka)

data := map[string]interface{}{
data := map[string]any{
"test": "test",
}
token, err := ka.Sign(data)
Expand Down Expand Up @@ -270,9 +270,9 @@ func getTestCredential() credential.VerifiableCredential {
knownType := []string{"VerifiableCredential", "HappyCredential"}
knownIssuer := "https://example.com/issuers/565049"
knownIssuanceDate := "2010-01-01T19:23:24Z"
knownSubject := map[string]interface{}{
knownSubject := map[string]any{
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
"happiness": map[string]interface{}{
"happiness": map[string]any{
"howHappy": "really happy",
},
}
Expand All @@ -296,6 +296,6 @@ func getTestPresentation() credential.VerifiablePresentation {
ID: knownID,
Type: knownType,
Holder: knownHolder,
VerifiableCredential: []interface{}{getTestCredential()},
VerifiableCredential: []any{getTestCredential()},
}
}
4 changes: 2 additions & 2 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func LoggingNewError(msg string) error {
}

// LoggingNewErrorf is a utility to create an error from a formatted message, log it, and return it as an error
func LoggingNewErrorf(msg string, args ...interface{}) error {
func LoggingNewErrorf(msg string, args ...any) error {
return LoggingNewError(fmt.Sprintf(msg, args...))
}

Expand All @@ -42,7 +42,7 @@ func LoggingErrorMsg(err error, msg string) error {
}

// LoggingErrorMsgf is a utility to combine logging an error, and returning and error with a formatted message
func LoggingErrorMsgf(err error, msg string, args ...interface{}) error {
func LoggingErrorMsgf(err error, msg string, args ...any) error {
return LoggingErrorMsg(err, fmt.Sprintf(msg, args...))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/server/framework/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func RouteParams(r *http.Request) map[string]string {
// The body is decoded into the value provided.
//
// The provided value is checked for validation tags if it's a struct.
func Decode(r *http.Request, val interface{}) error {
func Decode(r *http.Request, val any) error {
decoder := json.NewDecoder(r.Body)
decoder.DisallowUnknownFields()

Expand Down Expand Up @@ -97,6 +97,6 @@ func Decode(r *http.Request, val interface{}) error {
return nil
}

func ValidateRequest(request interface{}) error {
func ValidateRequest(request any) error {
return util.IsValidStruct(request)
}
4 changes: 2 additions & 2 deletions pkg/server/framework/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package framework

import (
"context"
"github.com/goccy/go-json"
"net/http"

"github.com/goccy/go-json"
"github.com/pkg/errors"
)

// Respond convert a Go value to JSON and sends it to the client.
func Respond(ctx context.Context, w http.ResponseWriter, data interface{}, statusCode int) error {
func Respond(ctx context.Context, w http.ResponseWriter, data any, statusCode int) error {
// set the status code within the context's request state. Gracefully shutdown if
// the request state doesn't exist in the context
v, ok := ctx.Value(KeyRequestState).(*RequestState)
Expand Down
17 changes: 11 additions & 6 deletions pkg/server/middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ package middleware

import (
"context"
"github.com/sirupsen/logrus"
"github.com/tbd54566975/ssi-service/pkg/server/framework"
"net/http"
"time"

"github.com/sirupsen/logrus"
"github.com/tbd54566975/ssi-service/pkg/server/framework"
)

// Logger logs request info before and after a handler runs.
// logs to to stdout in the following format:
// Before:
// TraceID : (StatusCode) HTTPMethod Path -> IPAddr (latency)
// e.g. 12345 : (200) GET /users/1 -> 192.168.1.0 (4ms)
//
// TraceID : (StatusCode) HTTPMethod Path -> IPAddr (latency)
// e.g. 12345 : (200) GET /users/1 -> 192.168.1.0 (4ms)
//
// After:
// TODO: add after format
// TODO: add after example
//
// TODO: add after format
// TODO: add after example
//
// TODO: make logging output configurable
func Logger() framework.Middleware {
mw := func(handler framework.Handler) framework.Handler {
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/middleware/panics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package middleware

import (
"context"
"github.com/sirupsen/logrus"
"github.com/tbd54566975/ssi-service/pkg/server/framework"
"net/http"
"runtime/debug"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/tbd54566975/ssi-service/pkg/server/framework"
)

// Panics recovers from panics and converts the panic into an error
Expand Down
8 changes: 4 additions & 4 deletions pkg/server/router/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ type CreateCredentialRequest struct {
// A context is optional. If not present, we'll apply default, required context values.
Context string `json:"@context"`
// A schema is optional. If present, we'll attempt to look it up and validate the data against it.
Schema string `json:"schema"`
Data map[string]interface{} `json:"data" validate:"required"`
Expiry string `json:"expiry"`
Revocable bool `json:"revocable"`
Schema string `json:"schema"`
Data map[string]any `json:"data" validate:"required"`
Expiry string `json:"expiry"`
Revocable bool `json:"revocable"`
// TODO(gabe) support more capabilities like signature type, format, status, and more.
}

Expand Down
Loading