string.go 551 B

12345678910111213141516171819202122232425262728
  1. package muesli
  2. // StringValue are Muesli strings
  3. type StringValue string
  4. const StringType = TypeValue("String")
  5. func (val StringValue) String() string {
  6. return string(val)
  7. }
  8. func (from StringValue) Convert(to interface{}) error {
  9. switch toPtr := to.(type) {
  10. case *string:
  11. (*toPtr) = from.String()
  12. case *StringValue:
  13. (*toPtr) = from
  14. case *Value:
  15. (*toPtr) = from
  16. default:
  17. return NewErrorValuef("Cannot convert StringValue %v to %v", from, to)
  18. }
  19. return nil
  20. }
  21. func (v StringValue) Type() TypeValue { return StringType }