-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from linkdata/getset-refactor
Getset refactor
- Loading branch information
Showing
75 changed files
with
577 additions
and
1,953 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package jaws | ||
|
||
import "errors" | ||
|
||
var ErrValueNotSettable = errors.New("value not settable") | ||
|
||
type AnyGetter interface { | ||
JawsGetAny(elem *Element) (value any) | ||
} | ||
|
||
type anyGetter struct{ v any } | ||
|
||
func (g anyGetter) JawsGetAny(e *Element) any { | ||
return g.v | ||
} | ||
|
||
func (g anyGetter) JawsSetAny(*Element, any) error { | ||
return ErrValueNotSettable | ||
} | ||
|
||
func (g anyGetter) JawsGetTag(rq *Request) any { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,16 @@ | ||
package jaws | ||
|
||
import ( | ||
"sync/atomic" | ||
) | ||
|
||
type AnySetter interface { | ||
JawsGetAny(e *Element) any | ||
AnyGetter | ||
// JawsSetAny may return ErrValueUnchanged to indicate value was already set. | ||
// It may panic if the type of v cannot be handled. | ||
JawsSetAny(e *Element, v any) (err error) | ||
} | ||
|
||
type anyGetter struct{ v any } | ||
|
||
func (g anyGetter) JawsGetAny(e *Element) any { | ||
return g.v | ||
} | ||
|
||
func (g anyGetter) JawsSetAny(*Element, any) error { | ||
return ErrValueNotSettable | ||
} | ||
|
||
func (g anyGetter) JawsGetTag(rq *Request) any { | ||
return nil | ||
} | ||
|
||
func makeAnySetter(v any) AnySetter { | ||
switch v := v.(type) { | ||
case AnySetter: | ||
return v | ||
case *atomic.Value: | ||
return atomicSetter{v} | ||
} | ||
return anyGetter{v} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.