Skip to content

Commit 68f205f

Browse files
committed
chore(lint): updated linters, relinted code
Signed-off-by: Frédéric BIDON <[email protected]>
1 parent 0bae0fb commit 68f205f

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ linters:
2222
- nestif
2323
- nlreturn
2424
- nonamedreturns
25+
- noinlineerr
2526
- paralleltest
27+
- recvcheck
2628
- testpackage
2729
- thelper
2830
- tparallel
@@ -31,6 +33,7 @@ linters:
3133
- whitespace
3234
- wrapcheck
3335
- wsl
36+
- wsl_v5
3437
settings:
3538
dupl:
3639
threshold: 200

reference.go

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,23 @@ const (
4040

4141
var ErrChildURL = errors.New("child url is nil")
4242

43+
// Ref represents a json reference object
44+
type Ref struct {
45+
referenceURL *url.URL
46+
referencePointer jsonpointer.Pointer
47+
48+
HasFullURL bool
49+
HasURLPathOnly bool
50+
HasFragmentOnly bool
51+
HasFileScheme bool
52+
HasFullFilePath bool
53+
}
54+
4355
// New creates a new reference for the given string
4456
func New(jsonReferenceString string) (Ref, error) {
45-
4657
var r Ref
4758
err := r.parse(jsonReferenceString)
4859
return r, err
49-
5060
}
5161

5262
// MustCreateRef parses the ref string and panics when it's invalid.
@@ -56,19 +66,8 @@ func MustCreateRef(ref string) Ref {
5666
if err != nil {
5767
panic(err)
5868
}
59-
return r
60-
}
61-
62-
// Ref represents a json reference object
63-
type Ref struct {
64-
referenceURL *url.URL
65-
referencePointer jsonpointer.Pointer
6669

67-
HasFullURL bool
68-
HasURLPathOnly bool
69-
HasFragmentOnly bool
70-
HasFileScheme bool
71-
HasFullFilePath bool
70+
return r
7271
}
7372

7473
// GetURL gets the URL for this reference
@@ -83,7 +82,6 @@ func (r *Ref) GetPointer() *jsonpointer.Pointer {
8382

8483
// String returns the best version of the url for this reference
8584
func (r *Ref) String() string {
86-
8785
if r.referenceURL != nil {
8886
return r.referenceURL.String()
8987
}
@@ -108,9 +106,27 @@ func (r *Ref) IsCanonical() bool {
108106
return (r.HasFileScheme && r.HasFullFilePath) || (!r.HasFileScheme && r.HasFullURL)
109107
}
110108

109+
// Inherits creates a new reference from a parent and a child
110+
// If the child cannot inherit from the parent, an error is returned
111+
func (r *Ref) Inherits(child Ref) (*Ref, error) {
112+
childURL := child.GetURL()
113+
parentURL := r.GetURL()
114+
if childURL == nil {
115+
return nil, ErrChildURL
116+
}
117+
if parentURL == nil {
118+
return &child, nil
119+
}
120+
121+
ref, err := New(parentURL.ResolveReference(childURL).String())
122+
if err != nil {
123+
return nil, err
124+
}
125+
return &ref, nil
126+
}
127+
111128
// "Constructor", parses the given string JSON reference
112129
func (r *Ref) parse(jsonReferenceString string) error {
113-
114130
parsed, err := url.Parse(jsonReferenceString)
115131
if err != nil {
116132
return err
@@ -139,22 +155,3 @@ func (r *Ref) parse(jsonReferenceString string) error {
139155

140156
return nil
141157
}
142-
143-
// Inherits creates a new reference from a parent and a child
144-
// If the child cannot inherit from the parent, an error is returned
145-
func (r *Ref) Inherits(child Ref) (*Ref, error) {
146-
childURL := child.GetURL()
147-
parentURL := r.GetURL()
148-
if childURL == nil {
149-
return nil, ErrChildURL
150-
}
151-
if parentURL == nil {
152-
return &child, nil
153-
}
154-
155-
ref, err := New(parentURL.ResolveReference(childURL).String())
156-
if err != nil {
157-
return nil, err
158-
}
159-
return &ref, nil
160-
}

0 commit comments

Comments
 (0)