func setField(field reflect.Value, defaultVal string) {
	switch field.Kind() {
	case reflect.String:
		if field.String() == "" {
			field.Set(reflect.ValueOf(defaultVal).Convert(field.Type()))
		}
	case reflect.Bool:
		if val, err := strconv.ParseBool(defaultVal); err == nil {
			field.Set(reflect.ValueOf(val).Convert(field.Type()))
		}
	}
}
setField handles String/Bool types only.
package opts
import (
	"fmt"
	"math/rand"
	"reflect"
	"regexp"
	"strconv"
	"strings"
	"time"
	"github.com/go-echarts/go-echarts/v2/types"
)
func init() {
	rand.Seed(time.Now().UnixNano())
}
type Initialization struct {
	PageTitle string `default:"Awesome go-echarts"`
	Width string `default:"900px"`
	Height string `default:"500px"`
	BackgroundColor string
	ChartID string
	AssetsHost string `default:"https://go-echarts.github.io/go-echarts-assets/assets/"`
	Theme string `default:"white"`
}
func (opt *Initialization) Validate() {
	setDefaultValue(opt)
	if opt.ChartID == "" {
		opt.ChartID = generateUniqueID()
	}
}
func setDefaultValue(ptr interface{}) {
	elem := reflect.ValueOf(ptr).Elem()
	t := elem.Type()
	for i := 0; i < t.NumField(); i++ {
		if defaultVal := t.Field(i).Tag.Get("default"); defaultVal != "" {
			setField(elem.Field(i), defaultVal)
		}
	}
}