github.com/kolbycrouch/elvish@v0.14.1-0.20210614162631-215b9ac1c423/pkg/eval/vars/read_only.go (about) 1 package vars 2 3 import ( 4 "src.elv.sh/pkg/eval/errs" 5 ) 6 7 type readOnly struct { 8 value interface{} 9 } 10 11 // NewReadOnly creates a variable that is read-only and always returns an error 12 // on Set. 13 func NewReadOnly(v interface{}) Var { 14 return readOnly{v} 15 } 16 17 func (rv readOnly) Set(val interface{}) error { 18 return errs.SetReadOnlyVar{} 19 } 20 21 func (rv readOnly) Get() interface{} { 22 return rv.value 23 }