diff --git a/fs/fs.go b/fs/fs.go index 1617cf9ee..ad412f1c7 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -2,6 +2,7 @@ package fs import ( + "encoding/json" "fmt" "io" "io/ioutil" @@ -132,6 +133,29 @@ type Option struct { Advanced bool // set if this is an advanced config option } +// BaseOption is an alias for Option used internally +type BaseOption Option + +// MarshalJSON turns an Option into JSON +// +// It adds some generated fields for ease of use +// - DefaultStr - a string rendering of Default +// - ValueStr - a string rendering of Value +// - Type - the type of the option +func (o *Option) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + BaseOption + DefaultStr string + ValueStr string + Type string + }{ + BaseOption: BaseOption(*o), + DefaultStr: fmt.Sprint(o.Default), + ValueStr: o.String(), + Type: o.Type(), + }) +} + // GetValue gets the current current value which is the default if not set func (o *Option) GetValue() interface{} { val := o.Value