Skip to content

Commit

Permalink
Run golint and go vet
Browse files Browse the repository at this point in the history
  • Loading branch information
Madrigal committed Sep 18, 2024
1 parent f0c6adf commit 77eff8e
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion document/cbor/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (d *decoder) Decode(v cbor.Value, to interface{}) error {

rv := reflect.ValueOf(to)
if rv.Kind() != reflect.Ptr || rv.IsNil() || !rv.IsValid() {
return &document.InvalidUnmarshalError{reflect.TypeOf(to)}
return &document.InvalidUnmarshalError{Type: reflect.TypeOf(to)}
}

return d.decode(v, rv, serde.Tag{})
Expand Down
2 changes: 1 addition & 1 deletion document/cbor/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (e *encoder) encodeMap(rv reflect.Value) (cbor.Map, error) {
for _, key := range rv.MapKeys() {
keyName := fmt.Sprint(key.Interface())
if keyName == "" {
return nil, &document.InvalidMarshalError{"map key cannot be empty"}
return nil, &document.InvalidMarshalError{Message: "map key cannot be empty"}
}

cv, err := e.encode(rv.MapIndex(key), serde.Tag{})
Expand Down
4 changes: 2 additions & 2 deletions encoding/cbor/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (v EncodeRaw) encode(p []byte) int {
return len(v)
}

// FixedUint encodes fixed-width Uint values.
// EncodeFixedUint encodes fixed-width Uint values.
//
// This is used by the encoder for the purpose of embedding integrals in
// document shapes. Decode will never return values of this type.
Expand All @@ -203,7 +203,7 @@ func (v EncodeFixedUint) encode(p []byte) int {
return 9
}

// FixedUint encodes fixed-width NegInt values.
// EncodeFixedNegInt encodes fixed-width NegInt values.
//
// This is used by the encoder for the purpose of embedding integrals in
// document shapes. Decode will never return values of this type.
Expand Down
1 change: 0 additions & 1 deletion encoding/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package encoding provides utilities for encoding values for specific
// document encodings.

package encoding
2 changes: 1 addition & 1 deletion encoding/httpbinding/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewEncoder(path, query string, headers http.Header) (*Encoder, error) {
return NewEncoderWithRawPath(path, path, query, headers)
}

// NewHTTPBindingEncoder creates a new encoder from the passed in request. All query and
// NewEncoderWithRawPath creates a new encoder from the passed in request. All query and
// header values will be added on top of the request's existing values. Overwriting
// duplicate values.
func NewEncoderWithRawPath(path, rawPath, query string, headers http.Header) (*Encoder, error) {
Expand Down
1 change: 0 additions & 1 deletion endpoints/private/rulesfn/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package rulesfn provides endpoint rule functions for evaluating endpoint
// resolution rules.

package rulesfn
2 changes: 1 addition & 1 deletion endpoints/private/rulesfn/strings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package rulesfn

// Substring returns the substring of the input provided. If the start or stop
// SubString returns the substring of the input provided. If the start or stop
// indexes are not valid for the input nil will be returned. If errors occur
// they will be added to the provided [ErrorCollector].
func SubString(input string, start, stop int, reverse bool) *string {
Expand Down
4 changes: 2 additions & 2 deletions endpoints/private/rulesfn/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ParseURL(input string) *URL {
Authority: authority,
Path: u.Path,
NormalizedPath: normalizedPath,
IsIp: net.ParseIP(hostnameWithoutZone(u)) != nil,
IsIP: net.ParseIP(hostnameWithoutZone(u)) != nil,
}
}

Expand All @@ -82,7 +82,7 @@ type URL struct {
Authority string // https://www.rfc-editor.org/rfc/rfc3986#section-3.2
Path string // https://www.rfc-editor.org/rfc/rfc3986#section-3.3
NormalizedPath string // https://www.rfc-editor.org/rfc/rfc3986#section-6.2.3
IsIp bool
IsIP bool
}

// URIEncode returns an percent-encoded [RFC3986 section 2.1] version of the
Expand Down
12 changes: 6 additions & 6 deletions endpoints/private/rulesfn/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestParseURL(t *testing.T) {
Authority: "127.0.0.1",
Path: "",
NormalizedPath: "/",
IsIp: true,
IsIP: true,
},
},
"ip4 URL with port": {
Expand All @@ -86,7 +86,7 @@ func TestParseURL(t *testing.T) {
Authority: "127.0.0.1:8443",
Path: "",
NormalizedPath: "/",
IsIp: true,
IsIP: true,
},
},
"ip6 short": {
Expand All @@ -96,7 +96,7 @@ func TestParseURL(t *testing.T) {
Authority: "[fe80::1]",
Path: "",
NormalizedPath: "/",
IsIp: true,
IsIP: true,
},
},
"ip6 short with interface": {
Expand All @@ -106,7 +106,7 @@ func TestParseURL(t *testing.T) {
Authority: "[fe80::1%25en0]",
Path: "",
NormalizedPath: "/",
IsIp: true,
IsIP: true,
},
},
"ip6 short with port": {
Expand All @@ -116,7 +116,7 @@ func TestParseURL(t *testing.T) {
Authority: "[fe80::1]:8443",
Path: "",
NormalizedPath: "/",
IsIp: true,
IsIP: true,
},
},
"ip6 short with port with interface": {
Expand All @@ -126,7 +126,7 @@ func TestParseURL(t *testing.T) {
Authority: "[fe80::1%25en0]:8443",
Path: "",
NormalizedPath: "/",
IsIp: true,
IsIP: true,
},
},
}
Expand Down
1 change: 0 additions & 1 deletion internal/sync/singleflight/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
// and unversioned golang.org/x/sync module.
//
// https://github.com/golang/sync/tree/67f06af15bc961c363a7260195bcd53487529a21/singleflight

package singleflight
8 changes: 4 additions & 4 deletions middleware/stack_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ClearStackValues(ctx context.Context) context.Context {
return context.WithValue(ctx, stackValuesKey{}, nil)
}

// GetStackValues returns the value pointed to by the key within the stack
// GetStackValue returns the value pointed to by the key within the stack
// values, if it is present.
func GetStackValue(ctx context.Context, key interface{}) interface{} {
md, _ := ctx.Value(stackValuesKey{}).(*stackValues)
Expand Down Expand Up @@ -62,13 +62,13 @@ func (m *stackValues) Value(key interface{}) interface{} {
return m.parent.Value(key)
}

func (c *stackValues) String() string {
func (m *stackValues) String() string {
var str strings.Builder

cc := c
cc := m
for cc == nil {
str.WriteString("(" +
reflect.TypeOf(c.key).String() +
reflect.TypeOf(m.key).String() +
": " +
stringify(cc.value) +
")")
Expand Down
6 changes: 4 additions & 2 deletions private/requestcompression/request_compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
"bytes"
"context"
"fmt"
"io"

"github.com/aws/smithy-go/middleware"
"github.com/aws/smithy-go/transport/http"
"io"
)

const MaxRequestMinCompressSizeBytes = 10485760
// MaxRequestMinCompressSizeBytes is the maximum value allowed for the member MinCompressSizeBytes
const MaxRequestMinCompressSizeBytes = 10485760 // 10 MB

// Enumeration values for supported compress Algorithms.
const (
Expand Down
2 changes: 1 addition & 1 deletion testing/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
type compareCompressFunc func([]byte, io.Reader) error

var allowedAlgorithms = map[string]compareCompressFunc{
GZIP: GzipCompareCompressBytes,
GZIP: gzipCompareCompressBytes,
}

// CompareReaderEmpty checks if the reader is nil, or contains no bytes.
Expand Down
2 changes: 1 addition & 1 deletion testing/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
)

func GzipCompareCompressBytes(expect []byte, actual io.Reader) error {
func gzipCompareCompressBytes(expect []byte, actual io.Reader) error {
content, err := gzip.NewReader(actual)
if err != nil {
return fmt.Errorf("error while reading request")
Expand Down
8 changes: 4 additions & 4 deletions testing/xml/doc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// package xml is xml testing package that supports xml comparison utility.
// The package consists of XMLToStruct and StructToXML utils that help sort xml elements
// as per their nesting level. XMLToStruct function converts an xml document into a sorted
// Package xml is xml testing package that supports xml comparison utility.
// The package consists of ToStruct and StructToXML utils that help sort xml elements
// as per their nesting level. ToStruct function converts a xml document into a sorted
// tree node structure, while StructToXML converts the sorted xml nodes into a sorted xml document.
// SortXML function should be used to sort an xml document. It can be configured to ignore indentation
// SortXML function should be used to sort a xml document. It can be configured to ignore indentation
package xml
2 changes: 1 addition & 1 deletion testing/xml/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (x xmlAttrSlice) Swap(i, j int) {
func SortXML(r io.Reader, ignoreIndentation bool) (string, error) {
var buf bytes.Buffer
d := xml.NewDecoder(r)
root, err := XMLToStruct(d, nil, ignoreIndentation)
root, err := ToStruct(d, nil, ignoreIndentation)
if err != nil {
return buf.String(), err
}
Expand Down
62 changes: 31 additions & 31 deletions testing/xml/xmlToStruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ import (
"strings"
)

// A XMLNode contains the values to be encoded or decoded.
type XMLNode struct {
Name xml.Name `json:",omitempty"`
Children map[string][]*XMLNode `json:",omitempty"`
Text string `json:",omitempty"`
Attr []xml.Attr `json:",omitempty"`
// Node contains the values to be encoded or decoded.
type Node struct {
Name xml.Name `json:",omitempty"`
Children map[string][]*Node `json:",omitempty"`
Text string `json:",omitempty"`
Attr []xml.Attr `json:",omitempty"`

namespaces map[string]string
parent *XMLNode
parent *Node
}

// NewXMLElement returns a pointer to a new XMLNode initialized to default values.
func NewXMLElement(name xml.Name) *XMLNode {
return &XMLNode{
func NewXMLElement(name xml.Name) *Node {
return &Node{
Name: name,
Children: map[string][]*XMLNode{},
Children: map[string][]*Node{},
Attr: []xml.Attr{},
}
}

// AddChild adds child to the XMLNode.
func (n *XMLNode) AddChild(child *XMLNode) {
func (n *Node) AddChild(child *Node) {
child.parent = n
if _, ok := n.Children[child.Name.Local]; !ok {
// flattened will have multiple children with same tag name
n.Children[child.Name.Local] = []*XMLNode{}
n.Children[child.Name.Local] = []*Node{}
}
n.Children[child.Name.Local] = append(n.Children[child.Name.Local], child)
}

// XMLToStruct converts a xml.Decoder stream to XMLNode with nested values.
func XMLToStruct(d *xml.Decoder, s *xml.StartElement, ignoreIndentation bool) (*XMLNode, error) {
out := &XMLNode{}
// ToStruct converts a xml.Decoder stream to XMLNode with nested values.
func ToStruct(d *xml.Decoder, s *xml.StartElement, ignoreIndentation bool) (*Node, error) {
out := &Node{}

for {
tok, err := d.Token()
Expand Down Expand Up @@ -69,15 +69,15 @@ func XMLToStruct(d *xml.Decoder, s *xml.StartElement, ignoreIndentation bool) (*
el := typed.Copy()
out.Attr = el.Attr
if out.Children == nil {
out.Children = map[string][]*XMLNode{}
out.Children = map[string][]*Node{}
}

name := typed.Name.Local
slice := out.Children[name]
if slice == nil {
slice = []*XMLNode{}
slice = []*Node{}
}
node, e := XMLToStruct(d, &el, ignoreIndentation)
node, e := ToStruct(d, &el, ignoreIndentation)
out.findNamespaces()
if e != nil {
return out, e
Expand All @@ -99,13 +99,13 @@ func XMLToStruct(d *xml.Decoder, s *xml.StartElement, ignoreIndentation bool) (*
if s != nil && s.Name.Local == typed.Name.Local { // matching end token
return out, nil
}
out = &XMLNode{}
out = &Node{}
}
}
return out, nil
}

func (n *XMLNode) findNamespaces() {
func (n *Node) findNamespaces() {
ns := map[string]string{}
for _, a := range n.Attr {
if a.Name.Space == "xmlns" {
Expand All @@ -116,7 +116,7 @@ func (n *XMLNode) findNamespaces() {
n.namespaces = ns
}

func (n *XMLNode) findElem(name string) (string, bool) {
func (n *Node) findElem(name string) (string, bool) {
for node := n; node != nil; node = node.parent {
for _, a := range node.Attr {
namespace := a.Name.Space
Expand All @@ -132,7 +132,7 @@ func (n *XMLNode) findElem(name string) (string, bool) {
}

// StructToXML writes an XMLNode to a xml.Encoder as tokens.
func StructToXML(e *xml.Encoder, node *XMLNode, sorted bool) error {
func StructToXML(e *xml.Encoder, node *Node, sorted bool) error {
var err error
// Sort Attributes
attrs := node.Attr
Expand Down Expand Up @@ -206,21 +206,21 @@ func StructToXML(e *xml.Encoder, node *XMLNode, sorted bool) error {
// which ever has lower value and then added to the global sorted list.
// If value was initially chosen, but has nested nodes; key will be chosen as comparable
// as it is unique and will always have concrete data ie. string.
func sortFlattenedNodes(nodes []*XMLNode) ([]*XMLNode, error) {
var sortedNodes []*XMLNode
func sortFlattenedNodes(nodes []*Node) ([]*Node, error) {
var sortedNodes []*Node

// concreteNodeMap stores concrete value associated with a list of nodes
// This is possible in case multiple members of a flatList has same values.
concreteNodeMap := make(map[string][]*XMLNode, 0)
concreteNodeMap := make(map[string][]*Node, 0)

// flatListNodeMap stores flat list or wrapped list members associated with a list of nodes
// This will have only flattened list with members that are Nodes and not concrete values.
flatListNodeMap := make(map[string][]*XMLNode, 0)
flatListNodeMap := make(map[string][]*Node, 0)

// flatMapNodeMap stores flat map or map entry members associated with a list of nodes
// This will have only flattened map concrete value members. It is possible to limit this
// to concrete value as map key is expected to be concrete.
flatMapNodeMap := make(map[string][]*XMLNode, 0)
flatMapNodeMap := make(map[string][]*Node, 0)

// nodes with concrete value are prioritized and appended based on sorting order
sortedNodesWithConcreteValue := []string{}
Expand All @@ -238,7 +238,7 @@ func sortFlattenedNodes(nodes []*XMLNode) ([]*XMLNode, error) {
if v, ok := concreteNodeMap[node.Text]; ok {
concreteNodeMap[node.Text] = append(v, node)
} else {
concreteNodeMap[node.Text] = []*XMLNode{node}
concreteNodeMap[node.Text] = []*Node{node}
}
}

Expand All @@ -253,14 +253,14 @@ func sortFlattenedNodes(nodes []*XMLNode) ([]*XMLNode, error) {
if v, ok := flatListNodeMap[nestedNodeName]; ok {
flatListNodeMap[nestedNodeName] = append(v, nestedNodes[0])
} else {
flatListNodeMap[nestedNodeName] = []*XMLNode{nestedNodes[0]}
flatListNodeMap[nestedNodeName] = []*Node{nestedNodes[0]}
}
}
}

// if node has two children, then it is a flattened map node
if len(node.Children) == 2 {
nestedPair := []*XMLNode{}
nestedPair := []*Node{}
for _, k := range node.Children {
nestedPair = append(nestedPair, k[0])
}
Expand All @@ -285,7 +285,7 @@ func sortFlattenedNodes(nodes []*XMLNode) ([]*XMLNode, error) {
if v, ok := flatMapNodeMap[comparableValue]; ok {
flatMapNodeMap[comparableValue] = append(v, node)
} else {
flatMapNodeMap[comparableValue] = []*XMLNode{node}
flatMapNodeMap[comparableValue] = []*Node{node}
}
break
}
Expand Down
Loading

0 comments on commit 77eff8e

Please sign in to comment.