104 lines
2.8 KiB
Go
104 lines
2.8 KiB
Go
package loader
|
|
|
|
import (
|
|
"bytes"
|
|
_ "embed"
|
|
"encoding/json"
|
|
"io"
|
|
"log"
|
|
)
|
|
|
|
//go:embed conf/default.json
|
|
var defaultConf []byte
|
|
|
|
// DefaultConf loads the defaultConf of the package. The base
|
|
// is the default.json inside the package definition.
|
|
func DefaultConf() *Conf {
|
|
buf := bytes.NewBuffer(defaultConf)
|
|
conf := &Conf{}
|
|
err := conf.DecodeJSON(buf)
|
|
if err != nil {
|
|
log.Println("cannot decode default conf: ", err)
|
|
}
|
|
return conf
|
|
}
|
|
|
|
// Conf configures the mapping from the excel version
|
|
// to the eCalc structure
|
|
type Conf struct {
|
|
Title string `json:"title"`
|
|
Version string `json:"version"`
|
|
Values []Value `json:"values"`
|
|
Areas []Area `json:"areas"`
|
|
Rating Rating `json:"rating"`
|
|
}
|
|
|
|
// EncodeJSON writes the JSON of the conf into the Writer
|
|
func (c Conf) EncodeJSON(w io.Writer) error {
|
|
enc := json.NewEncoder(w)
|
|
enc.SetIndent("", " ")
|
|
return enc.Encode(c)
|
|
}
|
|
|
|
// DecodeJSON writes the configuration from the reader into
|
|
// the pointer of the conf
|
|
func (c *Conf) DecodeJSON(r io.Reader) error {
|
|
dec := json.NewDecoder(r)
|
|
return dec.Decode(c)
|
|
}
|
|
|
|
// Value defines a single value inside the excel workbook
|
|
type Value struct {
|
|
Sheet int `json:"sheet"`
|
|
Cell string `json:"cell"`
|
|
Type string `json:"type"`
|
|
Struct string `json:"struct"`
|
|
Field string `json:"field"`
|
|
Default string `json:"default"`
|
|
}
|
|
|
|
// Area defines rows and cols, which are maped to
|
|
// a slice of a type. For example IndustrySector
|
|
type Area struct {
|
|
Sheet int `json:"sheet"`
|
|
StartRow int `json:"start_row"`
|
|
EndRow int `json:"end_row"`
|
|
Struct string `json:"struct"`
|
|
Cols []AreaCol `json:"cols"`
|
|
}
|
|
|
|
// AreaCol defines each col of an area. As Col-Definition
|
|
// the letter from the Excel should be used.
|
|
// For example "A" for the first col, "B" for the second ...
|
|
type AreaCol struct {
|
|
Col string `json:"col"`
|
|
Field string `json:"field"`
|
|
Type string `json:"type"`
|
|
Default string `json:"default"`
|
|
}
|
|
|
|
// Rating defines the area of the ratingarea
|
|
// The cols must be defined by the letter of the col
|
|
// for example "A" for the first col
|
|
type Rating struct {
|
|
Sheet int `json:"sheet"`
|
|
StartRow int `json:"start_row"`
|
|
EndRow int `json:"end_row"`
|
|
Cols []RatingCol `json:"cols"`
|
|
PointsCol string `json:"points_col"`
|
|
MaxPointsCol string `json:"max_points_col"`
|
|
IDCol string `json:"id_col"`
|
|
ShortNameCol string `json:"short_name_col"`
|
|
NameCol string `json:"name_col"`
|
|
EstimationsCol string `json:"estimations_col"`
|
|
WeightCol string `json:"weight_col"`
|
|
SelectedByUserCol string `json:"selected_by_user_col"`
|
|
}
|
|
|
|
type RatingCol struct {
|
|
Col string `json:"col"`
|
|
Field string `json:"field"`
|
|
Type string `json:"type"`
|
|
Default string `json:"default"`
|
|
}
|