-
Notifications
You must be signed in to change notification settings - Fork 1
/
floatsetter.go
42 lines (35 loc) · 862 Bytes
/
floatsetter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package jaws
import (
"fmt"
"sync/atomic"
)
type FloatSetter interface {
JawsGetFloat(e *Element) float64
// JawsSetFloat may return ErrValueUnchanged to indicate value was already set.
JawsSetFloat(e *Element, v float64) (err error)
}
type floatGetter struct{ v float64 }
func (g floatGetter) JawsGetFloat(e *Element) float64 {
return g.v
}
func (g floatGetter) JawsSetFloat(*Element, float64) error {
return ErrValueNotSettable
}
func (g floatGetter) JawsGetTag(rq *Request) any {
return nil
}
func makeFloatSetter(v any) FloatSetter {
switch v := v.(type) {
case FloatSetter:
return v
case float64:
return floatGetter{v}
case float32:
return floatGetter{float64(v)}
case int:
return floatGetter{float64(v)}
case *atomic.Value:
return atomicSetter{v}
}
panic(fmt.Errorf("expected jaws.FloatSetter, float or int, not %T", v))
}